]> git.mxchange.org Git - city.git/commitdiff
Added more methods:
authorRoland Haeder <roland@mxchange.org>
Wed, 29 Jul 2015 21:07:07 +0000 (23:07 +0200)
committerRoland Haeder <roland@mxchange.org>
Wed, 29 Jul 2015 21:09:50 +0000 (23:09 +0200)
- 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 <roland@mxchange.org>
application/city/interfaces/database/frontend/city/class_CityInformationWrapper.php
application/city/interfaces/database/frontend/city_sections/class_CitySectionsWrapper.php
application/city/interfaces/manager/city_sections/class_ManageableCitySections.php
application/city/main/city_daemon/class_BaseCityDaemon.php
application/city/main/database/frontend/city/class_CityInformationDatabaseWrapper.php
application/city/main/database/frontend/city_sections/class_CitySectionsDatabaseWrapper.php
application/city/main/manager/city_sections/class_CitySectionsManager.php
application/city/main/tasks/daemon/map_expander/class_CityDaemonMapExpanderTask.php
core

index 7c45cf01a2c17c054cb554cff90cd2ef95f6a791..b2fe7cdce3b690bb2145bc0767bb5290bf0c1a89 100644 (file)
@@ -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]
index 3d832128add21f983d0757ec862ceb9b6b810d88..6075615cbb49061fd8d1f6fcc3e65aea36406ab7 100644 (file)
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 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]
index 7251669741e37bc3c383420ca209bd623119fdbe..e38f337fc6ec00a1d914873881ff0bc1e1b8b167 100644 (file)
@@ -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]
index f477a1ab4e14609aa615d6e699bf04be80f65375..89b3a51ff63f73d624add13ee8c994de53c339ed 100644 (file)
@@ -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]
index 6bebe8f2dc23f91550a5a8c3ea8088fafeb0ac50..6624b56100f39db126518f70953e9099e8bd38ad 100644 (file)
@@ -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]
index eef07bc53026ba94d7f8cc98d7819f0d05de6784..bb9effefa5aa1adfb6277c1d3a0cd344e1a72217 100644 (file)
@@ -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]
index fd1106d7012678494fd01a6f724adc2ddec0e290..b05ab91cca4cc92ab0eed271a1ba88d5708042af 100644 (file)
@@ -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
        }
 }
 
index 4152e922f5ca2fa5c8d21e21fb2d9883097de6de..a3ba21d89bbfafbb1ffb2eba4a49426dd8b9a45f 100644 (file)
@@ -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 867042ee4793d38bd778717192f4f6cd727b8e19..d939a8df01d12151255dc67950f1336fa215e2ab 160000 (submodule)
--- a/core
+++ b/core
@@ -1 +1 @@
-Subproject commit 867042ee4793d38bd778717192f4f6cd727b8e19
+Subproject commit d939a8df01d12151255dc67950f1336fa215e2ab