From 1df144f7ede0b303c6a63266ad42dc49a72b0b81 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Wed, 29 Jul 2015 23:07:07 +0200 Subject: [PATCH] Added more methods: - getCityIds() - Getter for an array of all available city ids - ifCityHasSections() - Checks whether the given city id has entries in sections table - doInitialCityExpansion() - Initial expansion of table sections for given city id Signed-off-by: Roland Haeder --- .../city/class_CityInformationWrapper.php | 7 +++ .../class_CitySectionsWrapper.php | 15 +++++++ .../class_ManageableCitySections.php | 7 +++ .../main/city_daemon/class_BaseCityDaemon.php | 13 ++++++ .../class_CityInformationDatabaseWrapper.php | 37 ++++++++++++++++ .../class_CitySectionsDatabaseWrapper.php | 43 +++++++++++++++++++ .../class_CitySectionsManager.php | 37 +++++++++++++++- .../class_CityDaemonMapExpanderTask.php | 2 +- core | 2 +- 9 files changed, 160 insertions(+), 3 deletions(-) diff --git a/application/city/interfaces/database/frontend/city/class_CityInformationWrapper.php b/application/city/interfaces/database/frontend/city/class_CityInformationWrapper.php index 7c45cf0..b2fe7cd 100644 --- a/application/city/interfaces/database/frontend/city/class_CityInformationWrapper.php +++ b/application/city/interfaces/database/frontend/city/class_CityInformationWrapper.php @@ -70,6 +70,13 @@ interface CityInformationWrapper extends DatabaseWrapper { * @return void */ function createCityByRequest (Requestable $requestInstance); + + /** + * Getter for all city ids as an array + * + * @return $cityIds All city ids as an array + */ + function getAllCityIds (); } // [EOF] diff --git a/application/city/interfaces/database/frontend/city_sections/class_CitySectionsWrapper.php b/application/city/interfaces/database/frontend/city_sections/class_CitySectionsWrapper.php index 3d83212..6075615 100644 --- a/application/city/interfaces/database/frontend/city_sections/class_CitySectionsWrapper.php +++ b/application/city/interfaces/database/frontend/city_sections/class_CitySectionsWrapper.php @@ -22,6 +22,21 @@ * along with this program. If not, see . */ interface CitySectionsWrapper extends DatabaseWrapper { + /** + * 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 + */ + function ifCityHasSections ($cityId); + + /** + * Expands the sections table with initial data for given city id + * + * @param $cityId City id to check + * @return void + */ + function doInitialCityExpansion ($cityId); } // [EOF] diff --git a/application/city/interfaces/manager/city_sections/class_ManageableCitySections.php b/application/city/interfaces/manager/city_sections/class_ManageableCitySections.php index 7251669..e38f337 100644 --- a/application/city/interfaces/manager/city_sections/class_ManageableCitySections.php +++ b/application/city/interfaces/manager/city_sections/class_ManageableCitySections.php @@ -28,6 +28,13 @@ interface ManageableCitySections extends FrameworkInterface { * @return $requiresExpansion Whether a map requires expansion */ function isMapPendingExpansion (); + + /** + * Expands any map that requires expansion + * + * @return void + */ + function expandMaps (); } // [EOF] diff --git a/application/city/main/city_daemon/class_BaseCityDaemon.php b/application/city/main/city_daemon/class_BaseCityDaemon.php index f477a1a..89b3a51 100644 --- a/application/city/main/city_daemon/class_BaseCityDaemon.php +++ b/application/city/main/city_daemon/class_BaseCityDaemon.php @@ -262,6 +262,19 @@ class BaseCityDaemon extends BaseCitySystem implements Updateable, AddableCriter // Call it's method and return value return $mapInstance->isMapPendingExpansion(); } + + /** + * Expands any found map that requires expansion + * + * @return void + */ + public function expandMaps () { + // Get sections manager + $mapInstance = ManagerFactory::createManagerByType('city_sections'); + + // Call it's method and return value + $mapInstance->expandMaps(); + } } // [EOF] diff --git a/application/city/main/database/frontend/city/class_CityInformationDatabaseWrapper.php b/application/city/main/database/frontend/city/class_CityInformationDatabaseWrapper.php index 6bebe8f..6624b56 100644 --- a/application/city/main/database/frontend/city/class_CityInformationDatabaseWrapper.php +++ b/application/city/main/database/frontend/city/class_CityInformationDatabaseWrapper.php @@ -222,6 +222,43 @@ class CityInformationDatabaseWrapper extends BaseDatabaseWrapper implements City // Post-check name assert($this->ifCityExists($cityName)); } + + /** + * Getter for all city ids as an array + * + * @return $cityIds All city ids as an array + */ + public function getAllCityIds () { + // Init empty search instance + $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class'); + + // And run it on the database + $resultInstance = $this->doSelectByCriteria($searchInstance); + + // Init array + $cityIds = array(); + + // Anything found? + if ($resultInstance->count() == 0) { + // Nothing found + return $cityIds; + } // END - if + + // Now get all 'city_id' columns + while ($resultInstance->next()) { + // Get current entry + $current = $resultInstance->current(); + + // 'city_id' should be there + assert(isset($current[self::DB_COLUMN_CITY_ID])); + + // Add it to the array + array_push($cityIds, $current[self::DB_COLUMN_CITY_ID]); + } // END - while + + // Return result + return $cityIds; + } } // [EOF] 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 eef07bc..bb9effe 100644 --- a/application/city/main/database/frontend/city_sections/class_CitySectionsDatabaseWrapper.php +++ b/application/city/main/database/frontend/city_sections/class_CitySectionsDatabaseWrapper.php @@ -76,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] diff --git a/application/city/main/manager/city_sections/class_CitySectionsManager.php b/application/city/main/manager/city_sections/class_CitySectionsManager.php index fd1106d..b05ab91 100644 --- a/application/city/main/manager/city_sections/class_CitySectionsManager.php +++ b/application/city/main/manager/city_sections/class_CitySectionsManager.php @@ -58,7 +58,42 @@ class CitySectionsManager extends BaseFrameworkSystem implements ManageableCityS * @todo 0% done */ public function isMapPendingExpansion () { - $this->partialStub('Please implement this method.'); + // Default is no expansion is needed + $requireExpansion = FALSE; + + // First, a simple check if the sections table contains any entries at all + if ($this->getWrapperInstance()->countTotalRows() == 0) { + // This definedly requires expansion + $requireExpansion = TRUE; + } // END - if + + // Return status + return $requireExpansion; + } + + /** + * Expands any map that requires expansion + * + * @return void + * @todo 0% done + */ + public function expandMaps () { + // Get a city info wrapper instance + $cityWrapperInstance = DatabaseWrapperFactory::createWrapperByConfiguredName('city_info_db_wrapper_class'); + + // Get all city ids from it + $cityIds = $cityWrapperInstance->getAllCityIds(); + + // Now check all ids + foreach ($cityIds as $cityId) { + // Does this id have any sections + if (!$this->getWrapperInstance()->ifCityHasSections($cityId)) { + // Nothing found, so it is a brand-new city that needs first initialization + $this->getWrapperInstance()->doInitialCityExpansion($cityId); + } else { + // @TODO Maybe some expansion is needed + } + } // END - foreach } } diff --git a/application/city/main/tasks/daemon/map_expander/class_CityDaemonMapExpanderTask.php b/application/city/main/tasks/daemon/map_expander/class_CityDaemonMapExpanderTask.php index 4152e92..a3ba21d 100644 --- a/application/city/main/tasks/daemon/map_expander/class_CityDaemonMapExpanderTask.php +++ b/application/city/main/tasks/daemon/map_expander/class_CityDaemonMapExpanderTask.php @@ -67,7 +67,7 @@ class CityDaemonMapExpanderTask extends BaseCityTask implements Taskable, Visita * Executes the task * * @return void - * @todo 0% done + * @todo ~ 10% done */ public function executeTask () { // Get daemon instance diff --git a/core b/core index 867042e..d939a8d 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit 867042ee4793d38bd778717192f4f6cd727b8e19 +Subproject commit d939a8df01d12151255dc67950f1336fa215e2ab -- 2.39.5