X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=application%2Fcity%2Fmain%2Fdatabase%2Ffrontend%2Fcity_sections%2Fclass_CitySectionsDatabaseWrapper.php;h=bb9effefa5aa1adfb6277c1d3a0cd344e1a72217;hb=1df144f7ede0b303c6a63266ad42dc49a72b0b81;hp=0ba967d790de9ab901e78e52d8c9eaaaa93d5386;hpb=0629a5a64c3ad497fa9f25617ee83064612444f4;p=city.git diff --git a/application/city/main/database/frontend/city_sections/class_CitySectionsDatabaseWrapper.php b/application/city/main/database/frontend/city_sections/class_CitySectionsDatabaseWrapper.php index 0ba967d..bb9effe 100644 --- a/application/city/main/database/frontend/city_sections/class_CitySectionsDatabaseWrapper.php +++ b/application/city/main/database/frontend/city_sections/class_CitySectionsDatabaseWrapper.php @@ -25,9 +25,31 @@ class CitySectionsDatabaseWrapper extends BaseDatabaseWrapper implements CitySec // Constants for database table names const DB_TABLE_CITY_SECTIONS = 'city_sections'; - // Constants for database column names - const DB_COLUMN_SECTION_ID = 'city_section_id'; - const DB_COLUMN_CITY_ID = 'city_id'; + // 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 @@ -54,6 +76,49 @@ class CitySectionsDatabaseWrapper extends BaseDatabaseWrapper implements CitySec // 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 void + */ + public function doInitialCityExpansion ($cityId) { + // Make sure this city has no sections + assert(!$this->ifCityHasSections($cityId)); + + // @TODO Unfinished + $this->partialStub('cityId=' . $cityId . ' - UNFINISHED!'); + } } // [EOF]