]> git.mxchange.org Git - city.git/blob
007129db6f2bc8c2a1c9e8083199a996a26d599c
[city.git] /
1 <?php
2 /**
3  * A database wrapper for city sections
4  *
5  * @author              Roland Haeder <webmaster@shipsimu.org>
6  * @version             0.0.0
7  * @copyright   Copyright (c) 2015 City Developer Team
8  * @license             GNU GPL 3.0 or any newer version
9  * @link                http://www.shipsimu.org
10  *
11  * This program is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation, either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program. If not, see <http://www.gnu.org/licenses/>.
23  */
24 class CitySectionsDatabaseWrapper extends BaseDatabaseWrapper implements CitySectionsWrapper, Registerable {
25         // Constants for database table names
26         const DB_TABLE_CITY_SECTIONS = 'city_sections';
27
28         // Section id, an referenced city id and lot id
29         const DB_COLUMN_SECTION_ID             = 'city_section_id';
30         const DB_COLUMN_CITY_ID                = 'city_id';
31         const DB_COLUMN_LOT_ID                 = 'lot_id';
32
33         // Section and sub type (e.g. residential, hut)
34         const DB_COLUMN_SECTION_TYPE           = 'section_type';
35         const DB_COLUMN_SECTION_SUB_TYPE       = 'section_sub_type';
36
37         // X-Y-Z position
38         const DB_COLUMN_SECTION_POSITION_X     = 'section_position_x';
39         const DB_COLUMN_SECTION_POSITION_Y     = 'section_position_y';
40         const DB_COLUMN_SECTION_POSITION_Z     = 'section_position_z';
41
42         // Connected neigbouring sections
43         const DB_COLUMN_SECTION_NEIGHBOUR_WEST_ID  = 'section_neighbour_west_id';
44         const DB_COLUMN_SECTION_NEIGHBOUR_EAST_ID  = 'section_neighbour_east_id';
45         const DB_COLUMN_SECTION_NEIGHBOUR_NORTH_ID = 'section_neighbour_north_id';
46         const DB_COLUMN_SECTION_NEIGHBOUR_SOUTH_ID = 'section_neighbour_south_id';
47         const DB_COLUMN_SECTION_NEIGHBOUR_UP_ID    = 'section_neighbour_up_id';
48         const DB_COLUMN_SECTION_NEIGHBOUR_DOWN_ID  = 'section_neighbour_down_id';
49
50         // Other settings:
51         // Reserved section (see documentation)
52         const DB_COLUMN_SECTION_RESERVED       = 'section_reserved';
53
54         /**
55          * Protected constructor
56          *
57          * @return      void
58          */
59         protected function __construct () {
60                 // Call parent constructor
61                 parent::__construct(__CLASS__);
62         }
63
64         /**
65          * Creates an instance of this database wrapper by a provided user class
66          *
67          * @return      $wrapperInstance        An instance of the created wrapper class
68          */
69         public static final function createCitySectionsDatabaseWrapper () {
70                 // Get a new instance
71                 $wrapperInstance = new CitySectionsDatabaseWrapper();
72
73                 // Set (primary!) table name
74                 $wrapperInstance->setTableName(self::DB_TABLE_CITY_SECTIONS);
75
76                 // Return the instance
77                 return $wrapperInstance;
78         }
79
80         /**
81          * Checks if the given city id is found in sections table
82          *
83          * @param       $cityId         City id to check
84          * @return      $isFound        Whether the city id is found
85          */
86         public function ifCityHasSections ($cityId) {
87                 // Get search instance
88                 $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
89
90                 // Search for 'city_id'
91                 $searchInstance->addCriteria(self::DB_COLUMN_CITY_ID, $cityId);
92
93                 /*
94                  * Only one entry is enough to find, else this query could run very\
95                  * long on large maps.
96                  */
97                 $searchInstance->setLimit(1);
98
99                 // Execute it on database instance
100                 $resultInstance = $this->doSelectByCriteria($searchInstance);
101
102                 // Check if there is one entry
103                 $isFound = ($resultInstance->next() == 1);
104
105                 // Return result
106                 return $isFound;
107         }
108
109         /**
110          * Expands the sections table with initial data for given city id
111          *
112          * @param       $cityId         City id to check
113          * @return      $ids            Sections ids from initial expansion
114          */
115         public function doInitialCityExpansion ($cityId) {
116                 // Make sure this city has no sections
117                 assert(!$this->ifCityHasSections($cityId));
118
119                 // @TODO Unfinished
120                 $this->partialStub('cityId=' . $cityId . ' - UNFINISHED!');
121         }
122 }
123
124 // [EOF]
125 ?>