* @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]
* 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]
* @return $requiresExpansion Whether a map requires expansion
*/
function isMapPendingExpansion ();
+
+ /**
+ * Expands any map that requires expansion
+ *
+ * @return void
+ */
+ function expandMaps ();
}
// [EOF]
// 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]
// 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]
// 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]
* @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
}
}
* Executes the task
*
* @return void
- * @todo 0% done
+ * @todo ~ 10% done
*/
public function executeTask () {
// Get daemon instance
-Subproject commit 867042ee4793d38bd778717192f4f6cd727b8e19
+Subproject commit d939a8df01d12151255dc67950f1336fa215e2ab