X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=application%2Fcity%2Fmain%2Fmanager%2Fcity_entities%2Fdistricts%2Fclass_CityDistrictsManager.php;fp=application%2Fcity%2Fmain%2Fmanager%2Fcity_entities%2Fdistricts%2Fclass_CityDistrictsManager.php;h=e1f1907ef07dcf482cd499809b3a4ac1160869e3;hb=cc05cc124c273dd7fa727c4872d147287a09951b;hp=0000000000000000000000000000000000000000;hpb=3935e544363c8cad755c75df4d20c46e6bf8d1e6;p=city.git diff --git a/application/city/main/manager/city_entities/districts/class_CityDistrictsManager.php b/application/city/main/manager/city_entities/districts/class_CityDistrictsManager.php new file mode 100644 index 0000000..e1f1907 --- /dev/null +++ b/application/city/main/manager/city_entities/districts/class_CityDistrictsManager.php @@ -0,0 +1,101 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2015 City Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.ship-simu.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 . + */ +class CityDistrictsManager extends BaseFrameworkSystem implements ManageableCityDistricts, Registerable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this class + * + * @return $managerInstance An instance of a ManageableCityDistricts class + */ + public final static function createCityDistrictsManager () { + // Get new instance + $managerInstance = new CityDistrictsManager(); + + // Get database wrapper + $wrapperInstance = DatabaseWrapperFactory::createWrapperByConfiguredName('city_districts_db_wrapper_class'); + + // And set it here + $managerInstance->setWrapperInstance($wrapperInstance); + + // Return the prepared instance + return $managerInstance; + } + + /** + * Checks whether at least one map requires expansion + * + * @return $requiresExpansion Whether a map requires expansion + * @todo 0% done + */ + public function isMapPendingExpansion () { + // Default is no expansion is needed + $requireExpansion = FALSE; + + // First, a simple check if the districts 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 districts + if (!$this->getWrapperInstance()->ifCityHasDistricts($cityId)) { + // Nothing found, so it is a brand-new city that needs first initialization + $districts = $this->getWrapperInstance()->doInitialCityExpansion($cityId); + } else { + // @TODO Maybe some expansion is needed + } + } // END - foreach + } +} + +// [EOF] +?>