3 namespace Org\Mxchange\City\Database\Frontend\Region;
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Database\Frontend\BaseDatabaseFrontend;
7 use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory;
8 use Org\Mxchange\CoreFramework\Registry\GenericRegistry;
9 use Org\Mxchange\CoreFramework\Registry\Registerable;
12 * A database frontend for region maps
14 * @author Roland Haeder <webmaster@shipsimu.org>
16 * @copyright Copyright (c) 2015, 2016 City Developer Team
17 * @license GNU GPL 3.0 or any newer version
18 * @link http://www.shipsimu.org
20 * This program is free software: you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License as published by
22 * the Free Software Foundation, either version 3 of the License, or
23 * (at your option) any later version.
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
30 * You should have received a copy of the GNU General Public License
31 * along with this program. If not, see <http://www.gnu.org/licenses/>.
33 class RegionMapDatabaseFrontend extends BaseDatabaseFrontend implements RegionMapFrontend, Registerable {
34 // Constants for database table names
35 const DB_TABLE_REGION_MAP = 'region_map';
37 // Constants for database column names
38 const DB_COLUMN_REGION_ID = 'region_id';
41 * Protected constructor
45 protected function __construct () {
46 // Call parent constructor
47 parent::__construct(__CLASS__);
51 * Creates an instance of this database frontend by a provided user class
53 * @return $frontendInstance An instance of the created frontend class
55 public static final function createRegionMapDatabaseFrontend () {
57 $frontendInstance = new RegionMapDatabaseFrontend();
59 // Set (primary!) table name
60 $frontendInstance->setTableName(self::DB_TABLE_REGION_MAP);
62 // Return the instance
63 return $frontendInstance;
67 * Removes non-public data from given array.
69 * @param $data An array with possible non-public data that needs to be removed.
70 * @return $data A cleaned up array with only public data.
72 public function removeNonPublicDataFromArray(array $data) {
73 // Currently call only inner method
74 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('REGION-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: Calling parent::removeNonPublicDataFromArray(data) ...');
75 $data = parent::removeNonPublicDataFromArray($data);
77 // Return cleaned data
82 * Creates a region by given name
86 public function createRegionByName () {
88 die(__METHOD__ . ': Unfinshed!');
89 assert(!$this->ifRegionExists($regionName));
92 $userInstance = GenericRegistry::getRegistry()->getInstance('user');
94 // Get a dataset instance
95 $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_REGION_MAP));
97 // Set the primary key
98 $dataSetInstance->setUniqueKey(self::DB_COLUMN_REGION_ID);
100 // Add region name and assign user id
101 $dataSetInstance->addCriteria(self::DB_COLUMN_REGION_ID , ($this->countTotalRows() + 1));
103 // "Insert" this dataset instance completely into the database
104 $this->queryInsertDataSet($dataSetInstance);
107 assert($this->ifRegionExists($regionName));