* @version 0.0.0 * @copyright Copyright (c) 2015 City Developer Team * @license GNU GPL 3.0 or any newer version * @link http://www.shipsimu.org * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ class RegionMapDatabaseWrapper extends BaseDatabaseWrapper implements RegionMapWrapper, Registerable { // Constants for database table names const DB_TABLE_REGION_MAP = 'region_map'; // Constants for database column names const DB_COLUMN_REGION_ID = 'region_id'; /** * Protected constructor * * @return void */ protected function __construct () { // Call parent constructor parent::__construct(__CLASS__); } /** * Creates an instance of this database wrapper by a provided user class * * @return $wrapperInstance An instance of the created wrapper class */ public static final function createRegionMapDatabaseWrapper () { // Get a new instance $wrapperInstance = new RegionMapDatabaseWrapper(); // Set (primary!) table name $wrapperInstance->setTableName(self::DB_TABLE_REGION_MAP); // Return the instance return $wrapperInstance; } /** * Removes non-public data from given array. * * @param $data An array with possible non-public data that needs to be removed. * @return $data A cleaned up array with only public data. */ public function removeNonPublicDataFromArray(array $data) { // Currently call only inner method /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('REGION-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: Calling parent::removeNonPublicDataFromArray(data) ...'); $data = parent::removeNonPublicDataFromArray($data); // Return cleaned data return $data; } /** * Creates a region by given name * * @return void */ public function createRegionByName () { // Pre-check die(__METHOD__ . ': Unfinshed!'); assert(!$this->ifRegionExists($regionName)); // Get user instance $userInstance = Registry::getRegistry()->getInstance('user'); // Get a dataset instance $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_REGION_MAP)); // Set the primary key $dataSetInstance->setUniqueKey(self::DB_COLUMN_REGION_ID); // Add region name and assign user id $dataSetInstance->addCriteria(self::DB_COLUMN_REGION_ID , ($this->countTotalRows() + 1)); // "Insert" this dataset instance completely into the database $this->queryInsertDataSet($dataSetInstance); // Post-check name assert($this->ifRegionExists($regionName)); } } // [EOF] ?>