3 namespace Org\Mxchange\City\Database\Frontend\Region;
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
7 use Org\Mxchange\CoreFramework\Registry\Registry;
10 * A database wrapper for region maps
12 * @author Roland Haeder <webmaster@shipsimu.org>
14 * @copyright Copyright (c) 2015, 2016 City Developer Team
15 * @license GNU GPL 3.0 or any newer version
16 * @link http://www.shipsimu.org
18 * This program is free software: you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation, either version 3 of the License, or
21 * (at your option) any later version.
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
28 * You should have received a copy of the GNU General Public License
29 * along with this program. If not, see <http://www.gnu.org/licenses/>.
31 class RegionMapDatabaseWrapper extends BaseDatabaseWrapper implements RegionMapWrapper, Registerable {
32 // Constants for database table names
33 const DB_TABLE_REGION_MAP = 'region_map';
35 // Constants for database column names
36 const DB_COLUMN_REGION_ID = 'region_id';
39 * Protected constructor
43 protected function __construct () {
44 // Call parent constructor
45 parent::__construct(__CLASS__);
49 * Creates an instance of this database wrapper by a provided user class
51 * @return $wrapperInstance An instance of the created wrapper class
53 public static final function createRegionMapDatabaseWrapper () {
55 $wrapperInstance = new RegionMapDatabaseWrapper();
57 // Set (primary!) table name
58 $wrapperInstance->setTableName(self::DB_TABLE_REGION_MAP);
60 // Return the instance
61 return $wrapperInstance;
65 * Removes non-public data from given array.
67 * @param $data An array with possible non-public data that needs to be removed.
68 * @return $data A cleaned up array with only public data.
70 public function removeNonPublicDataFromArray(array $data) {
71 // Currently call only inner method
72 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('REGION-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: Calling parent::removeNonPublicDataFromArray(data) ...');
73 $data = parent::removeNonPublicDataFromArray($data);
75 // Return cleaned data
80 * Creates a region by given name
84 public function createRegionByName () {
86 die(__METHOD__ . ': Unfinshed!');
87 assert(!$this->ifRegionExists($regionName));
90 $userInstance = Registry::getRegistry()->getInstance('user');
92 // Get a dataset instance
93 $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_REGION_MAP));
95 // Set the primary key
96 $dataSetInstance->setUniqueKey(self::DB_COLUMN_REGION_ID);
98 // Add region name and assign user id
99 $dataSetInstance->addCriteria(self::DB_COLUMN_REGION_ID , ($this->countTotalRows() + 1));
101 // "Insert" this dataset instance completely into the database
102 $this->queryInsertDataSet($dataSetInstance);
105 assert($this->ifRegionExists($regionName));