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