]> git.mxchange.org Git - city.git/blob - application/city/classes/database/frontend/region_map/class_RegionMapDatabaseFrontend.php
Continued:
[city.git] / application / city / classes / database / frontend / region_map / class_RegionMapDatabaseFrontend.php
1 <?php
2 // Own namespace
3 namespace Org\Mxchange\City\Database\Frontend\Region;
4
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;
10
11 /**
12  * A database frontend for region maps
13  *
14  * @author              Roland Haeder <webmaster@shipsimu.org>
15  * @version             0.0.0
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
19  *
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.
24  *
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.
29  *
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/>.
32  */
33 class RegionMapDatabaseFrontend extends BaseDatabaseFrontend implements RegionMapFrontend, Registerable {
34         // Constants for database table names
35         const DB_TABLE_REGION_MAP = 'region_map';
36
37         // Constants for database column names
38         const DB_COLUMN_REGION_ID = 'region_id';
39
40         /**
41          * Protected constructor
42          *
43          * @return      void
44          */
45         protected function __construct () {
46                 // Call parent constructor
47                 parent::__construct(__CLASS__);
48         }
49
50         /**
51          * Creates an instance of this database frontend by a provided user class
52          *
53          * @return      $frontendInstance       An instance of the created frontend class
54          */
55         public static final function createRegionMapDatabaseFrontend () {
56                 // Get a new instance
57                 $frontendInstance = new RegionMapDatabaseFrontend();
58
59                 // Set (primary!) table name
60                 $frontendInstance->setTableName(self::DB_TABLE_REGION_MAP);
61
62                 // Return the instance
63                 return $frontendInstance;
64         }
65
66         /**
67          * Removes non-public data from given array.
68          *
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.
71          */
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);
76
77                 // Return cleaned data
78                 return $data;
79         }
80
81         /**
82          * Creates a region by given name
83          *
84          * @return      void
85          */
86         public function createRegionByName () {
87                 // Pre-check
88                 die(__METHOD__ . ': Unfinshed!');
89                 assert(!$this->ifRegionExists($regionName));
90
91                 // Get user instance
92                 $userInstance = GenericRegistry::getRegistry()->getInstance('user');
93
94                 // Get a dataset instance
95                 $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_REGION_MAP));
96
97                 // Set the primary key
98                 $dataSetInstance->setUniqueKey(self::DB_COLUMN_REGION_ID);
99
100                 // Add region name and assign user id
101                 $dataSetInstance->addCriteria(self::DB_COLUMN_REGION_ID     , ($this->countTotalRows() + 1));
102
103                 // "Insert" this dataset instance completely into the database
104                 $this->queryInsertDataSet($dataSetInstance);
105
106                 // Post-check name
107                 assert($this->ifRegionExists($regionName));
108         }
109 }