]> git.mxchange.org Git - city.git/blobdiff - application/city/main/database/frontend/city_entities/sections/class_CitySectionsDatabaseWrapper.php
Introduced "entities" to bundle lots and sections + added some (not-used) classes
[city.git] / application / city / main / database / frontend / city_entities / sections / class_CitySectionsDatabaseWrapper.php
diff --git a/application/city/main/database/frontend/city_entities/sections/class_CitySectionsDatabaseWrapper.php b/application/city/main/database/frontend/city_entities/sections/class_CitySectionsDatabaseWrapper.php
new file mode 100644 (file)
index 0000000..007129d
--- /dev/null
@@ -0,0 +1,125 @@
+<?php
+/**
+ * A database wrapper for city sections
+ *
+ * @author             Roland Haeder <webmaster@shipsimu.org>
+ * @version            0.0.0
+ * @copyright  Copyright (c) 2015 City Developer Team
+ * @license            GNU GPL 3.0 or any newer version
+ * @link               http://www.shipsimu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+class CitySectionsDatabaseWrapper extends BaseDatabaseWrapper implements CitySectionsWrapper, Registerable {
+       // Constants for database table names
+       const DB_TABLE_CITY_SECTIONS = 'city_sections';
+
+       // Section id, an referenced city id and lot id
+       const DB_COLUMN_SECTION_ID             = 'city_section_id';
+       const DB_COLUMN_CITY_ID                = 'city_id';
+       const DB_COLUMN_LOT_ID                 = 'lot_id';
+
+       // Section and sub type (e.g. residential, hut)
+       const DB_COLUMN_SECTION_TYPE           = 'section_type';
+       const DB_COLUMN_SECTION_SUB_TYPE       = 'section_sub_type';
+
+       // X-Y-Z position
+       const DB_COLUMN_SECTION_POSITION_X     = 'section_position_x';
+       const DB_COLUMN_SECTION_POSITION_Y     = 'section_position_y';
+       const DB_COLUMN_SECTION_POSITION_Z     = 'section_position_z';
+
+       // Connected neigbouring sections
+       const DB_COLUMN_SECTION_NEIGHBOUR_WEST_ID  = 'section_neighbour_west_id';
+       const DB_COLUMN_SECTION_NEIGHBOUR_EAST_ID  = 'section_neighbour_east_id';
+       const DB_COLUMN_SECTION_NEIGHBOUR_NORTH_ID = 'section_neighbour_north_id';
+       const DB_COLUMN_SECTION_NEIGHBOUR_SOUTH_ID = 'section_neighbour_south_id';
+       const DB_COLUMN_SECTION_NEIGHBOUR_UP_ID    = 'section_neighbour_up_id';
+       const DB_COLUMN_SECTION_NEIGHBOUR_DOWN_ID  = 'section_neighbour_down_id';
+
+       // Other settings:
+       // Reserved section (see documentation)
+       const DB_COLUMN_SECTION_RESERVED       = 'section_reserved';
+
+       /**
+        * Protected constructor
+        *
+        * @return      void
+        */
+       protected function __construct () {
+               // Call parent constructor
+               parent::__construct(__CLASS__);
+       }
+
+       /**
+        * Creates an instance of this database wrapper by a provided user class
+        *
+        * @return      $wrapperInstance        An instance of the created wrapper class
+        */
+       public static final function createCitySectionsDatabaseWrapper () {
+               // Get a new instance
+               $wrapperInstance = new CitySectionsDatabaseWrapper();
+
+               // Set (primary!) table name
+               $wrapperInstance->setTableName(self::DB_TABLE_CITY_SECTIONS);
+
+               // Return the instance
+               return $wrapperInstance;
+       }
+
+       /**
+        * Checks if the given city id is found in sections table
+        *
+        * @param       $cityId         City id to check
+        * @return      $isFound        Whether the city id is found
+        */
+       public function ifCityHasSections ($cityId) {
+               // Get search instance
+               $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
+
+               // Search for 'city_id'
+               $searchInstance->addCriteria(self::DB_COLUMN_CITY_ID, $cityId);
+
+               /*
+                * Only one entry is enough to find, else this query could run very\
+                * long on large maps.
+                */
+               $searchInstance->setLimit(1);
+
+               // Execute it on database instance
+               $resultInstance = $this->doSelectByCriteria($searchInstance);
+
+               // Check if there is one entry
+               $isFound = ($resultInstance->next() == 1);
+
+               // Return result
+               return $isFound;
+       }
+
+       /**
+        * Expands the sections table with initial data for given city id
+        *
+        * @param       $cityId         City id to check
+        * @return      $ids            Sections ids from initial expansion
+        */
+       public function doInitialCityExpansion ($cityId) {
+               // Make sure this city has no sections
+               assert(!$this->ifCityHasSections($cityId));
+
+               // @TODO Unfinished
+               $this->partialStub('cityId=' . $cityId . ' - UNFINISHED!');
+       }
+}
+
+// [EOF]
+?>