From 3935e544363c8cad755c75df4d20c46e6bf8d1e6 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Sat, 1 Aug 2015 15:11:24 +0200 Subject: [PATCH] Introduced "entities" to bundle lots and sections + added some (not-used) classes for handling city lots. 'core' updated to latest commit. Signed-off-by: Roland Haeder --- .../.htaccess | 0 .../frontend/city_entities/lots}/.htaccess | 0 .../lots/class_CityLotsWrapper.php | 35 ++++++ .../city_entities/sections}/.htaccess | 0 .../sections}/class_CitySectionsWrapper.php | 2 +- .../manager/city/class_ManageableCity.php | 2 +- .../manager/city_entities}/.htaccess | 0 .../class_ManageableCityEntities.php | 41 +++++++ .../manager/city_entities/lots/.htaccess | 1 + .../lots/class_ManageableCityLots.php | 28 +++++ .../manager/city_entities/sections/.htaccess | 1 + .../class_ManageableCitySections.php | 2 +- .../interfaces/manager/class_Manageable.php | 28 +++++ .../manager/region/class_ManageableRegion.php | 2 +- .../region/class_ManageableRegionMap.php | 2 +- .../database/frontend/city_entities/.htaccess | 1 + .../frontend/city_entities/lots/.htaccess | 1 + .../lots/class_CityLotsDatabaseWrapper.php | 89 +++++++++++++++ .../frontend/city_entities/sections/.htaccess | 1 + .../class_CitySectionsDatabaseWrapper.php | 4 +- .../city/main/manager/city_entities/.htaccess | 1 + .../main/manager/city_entities/lots/.htaccess | 1 + .../lots/class_CityLotsManager.php | 101 ++++++++++++++++++ .../manager/city_entities/sections/.htaccess | 1 + .../sections}/class_CitySectionsManager.php | 2 +- .../city/main/manager/class_BaseManager.php | 2 +- core | 2 +- db/city_lots/.htaccess | 1 + 28 files changed, 341 insertions(+), 10 deletions(-) rename application/city/interfaces/database/frontend/{city_sections => city_entities}/.htaccess (100%) rename application/city/interfaces/{manager/city_sections => database/frontend/city_entities/lots}/.htaccess (100%) create mode 100644 application/city/interfaces/database/frontend/city_entities/lots/class_CityLotsWrapper.php rename application/city/{main/database/frontend/city_sections => interfaces/database/frontend/city_entities/sections}/.htaccess (100%) rename application/city/interfaces/database/frontend/{city_sections => city_entities/sections}/class_CitySectionsWrapper.php (96%) rename application/city/{main/manager/city_sections => interfaces/manager/city_entities}/.htaccess (100%) create mode 100644 application/city/interfaces/manager/city_entities/class_ManageableCityEntities.php create mode 100644 application/city/interfaces/manager/city_entities/lots/.htaccess create mode 100644 application/city/interfaces/manager/city_entities/lots/class_ManageableCityLots.php create mode 100644 application/city/interfaces/manager/city_entities/sections/.htaccess rename application/city/interfaces/manager/{city_sections => city_entities/sections}/class_ManageableCitySections.php (94%) create mode 100644 application/city/interfaces/manager/class_Manageable.php create mode 100644 application/city/main/database/frontend/city_entities/.htaccess create mode 100644 application/city/main/database/frontend/city_entities/lots/.htaccess create mode 100644 application/city/main/database/frontend/city_entities/lots/class_CityLotsDatabaseWrapper.php create mode 100644 application/city/main/database/frontend/city_entities/sections/.htaccess rename application/city/main/database/frontend/{city_sections => city_entities/sections}/class_CitySectionsDatabaseWrapper.php (97%) create mode 100644 application/city/main/manager/city_entities/.htaccess create mode 100644 application/city/main/manager/city_entities/lots/.htaccess create mode 100644 application/city/main/manager/city_entities/lots/class_CityLotsManager.php create mode 100644 application/city/main/manager/city_entities/sections/.htaccess rename application/city/main/manager/{city_sections => city_entities/sections}/class_CitySectionsManager.php (97%) create mode 100644 db/city_lots/.htaccess diff --git a/application/city/interfaces/database/frontend/city_sections/.htaccess b/application/city/interfaces/database/frontend/city_entities/.htaccess similarity index 100% rename from application/city/interfaces/database/frontend/city_sections/.htaccess rename to application/city/interfaces/database/frontend/city_entities/.htaccess diff --git a/application/city/interfaces/manager/city_sections/.htaccess b/application/city/interfaces/database/frontend/city_entities/lots/.htaccess similarity index 100% rename from application/city/interfaces/manager/city_sections/.htaccess rename to application/city/interfaces/database/frontend/city_entities/lots/.htaccess diff --git a/application/city/interfaces/database/frontend/city_entities/lots/class_CityLotsWrapper.php b/application/city/interfaces/database/frontend/city_entities/lots/class_CityLotsWrapper.php new file mode 100644 index 0000000..7455c38 --- /dev/null +++ b/application/city/interfaces/database/frontend/city_entities/lots/class_CityLotsWrapper.php @@ -0,0 +1,35 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2015 City Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.shipsimu.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 . + */ +interface CityLotsWrapper extends DatabaseWrapper { + /** + * Checks if the given city id is found in lots table + * + * @param $cityId City id to check + * @return $isFound Whether the city id is found + */ + function ifCityHasLots ($cityId); +} + +// [EOF] +?> diff --git a/application/city/main/database/frontend/city_sections/.htaccess b/application/city/interfaces/database/frontend/city_entities/sections/.htaccess similarity index 100% rename from application/city/main/database/frontend/city_sections/.htaccess rename to application/city/interfaces/database/frontend/city_entities/sections/.htaccess diff --git a/application/city/interfaces/database/frontend/city_sections/class_CitySectionsWrapper.php b/application/city/interfaces/database/frontend/city_entities/sections/class_CitySectionsWrapper.php similarity index 96% rename from application/city/interfaces/database/frontend/city_sections/class_CitySectionsWrapper.php rename to application/city/interfaces/database/frontend/city_entities/sections/class_CitySectionsWrapper.php index 6075615..e96eacc 100644 --- a/application/city/interfaces/database/frontend/city_sections/class_CitySectionsWrapper.php +++ b/application/city/interfaces/database/frontend/city_entities/sections/class_CitySectionsWrapper.php @@ -34,7 +34,7 @@ interface CitySectionsWrapper extends DatabaseWrapper { * Expands the sections table with initial data for given city id * * @param $cityId City id to check - * @return void + * @return $ids Sections ids from initial expansion */ function doInitialCityExpansion ($cityId); } diff --git a/application/city/interfaces/manager/city/class_ManageableCity.php b/application/city/interfaces/manager/city/class_ManageableCity.php index 206e4d4..66d9155 100644 --- a/application/city/interfaces/manager/city/class_ManageableCity.php +++ b/application/city/interfaces/manager/city/class_ManageableCity.php @@ -21,7 +21,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -interface ManageableCity extends FrameworkInterface { +interface ManageableCity extends Manageable { /** * Checks whether the current user has already founded a city * diff --git a/application/city/main/manager/city_sections/.htaccess b/application/city/interfaces/manager/city_entities/.htaccess similarity index 100% rename from application/city/main/manager/city_sections/.htaccess rename to application/city/interfaces/manager/city_entities/.htaccess diff --git a/application/city/interfaces/manager/city_entities/class_ManageableCityEntities.php b/application/city/interfaces/manager/city_entities/class_ManageableCityEntities.php new file mode 100644 index 0000000..127201a --- /dev/null +++ b/application/city/interfaces/manager/city_entities/class_ManageableCityEntities.php @@ -0,0 +1,41 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2015 City Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.shipsimu.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 . + */ +interface ManageableCityEntities extends Manageable { + /** + * Checks whether at least one map requires expansion + * + * @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/interfaces/manager/city_entities/lots/.htaccess b/application/city/interfaces/manager/city_entities/lots/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/application/city/interfaces/manager/city_entities/lots/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/city/interfaces/manager/city_entities/lots/class_ManageableCityLots.php b/application/city/interfaces/manager/city_entities/lots/class_ManageableCityLots.php new file mode 100644 index 0000000..696727e --- /dev/null +++ b/application/city/interfaces/manager/city_entities/lots/class_ManageableCityLots.php @@ -0,0 +1,28 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2015 City Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.shipsimu.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 . + */ +interface ManageableCityLots extends ManageableCityEntities { +} + +// [EOF] +?> diff --git a/application/city/interfaces/manager/city_entities/sections/.htaccess b/application/city/interfaces/manager/city_entities/sections/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/application/city/interfaces/manager/city_entities/sections/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/city/interfaces/manager/city_sections/class_ManageableCitySections.php b/application/city/interfaces/manager/city_entities/sections/class_ManageableCitySections.php similarity index 94% rename from application/city/interfaces/manager/city_sections/class_ManageableCitySections.php rename to application/city/interfaces/manager/city_entities/sections/class_ManageableCitySections.php index e38f337..ec8c661 100644 --- a/application/city/interfaces/manager/city_sections/class_ManageableCitySections.php +++ b/application/city/interfaces/manager/city_entities/sections/class_ManageableCitySections.php @@ -21,7 +21,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -interface ManageableCitySections extends FrameworkInterface { +interface ManageableCitySections extends ManageableCityEntities { /** * Checks whether at least one map requires expansion * diff --git a/application/city/interfaces/manager/class_Manageable.php b/application/city/interfaces/manager/class_Manageable.php new file mode 100644 index 0000000..5daf798 --- /dev/null +++ b/application/city/interfaces/manager/class_Manageable.php @@ -0,0 +1,28 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2015 City Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.shipsimu.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 . + */ +interface Manageable extends FrameworkInterface { +} + +// [EOF] +?> diff --git a/application/city/interfaces/manager/region/class_ManageableRegion.php b/application/city/interfaces/manager/region/class_ManageableRegion.php index 1e5b7a9..9452bb6 100644 --- a/application/city/interfaces/manager/region/class_ManageableRegion.php +++ b/application/city/interfaces/manager/region/class_ManageableRegion.php @@ -21,7 +21,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -interface ManageableRegion extends FrameworkInterface { +interface ManageableRegion extends Manageable { /** * Checks whether the current user has already founded a region * diff --git a/application/city/interfaces/manager/region/class_ManageableRegionMap.php b/application/city/interfaces/manager/region/class_ManageableRegionMap.php index 41dca2c..e8f596a 100644 --- a/application/city/interfaces/manager/region/class_ManageableRegionMap.php +++ b/application/city/interfaces/manager/region/class_ManageableRegionMap.php @@ -21,7 +21,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -interface ManageableRegionMap extends FrameworkInterface { +interface ManageableRegionMap extends Manageable { /** * Creates a map, if not found yet, for given result which should contain * data about the region in question diff --git a/application/city/main/database/frontend/city_entities/.htaccess b/application/city/main/database/frontend/city_entities/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/application/city/main/database/frontend/city_entities/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/city/main/database/frontend/city_entities/lots/.htaccess b/application/city/main/database/frontend/city_entities/lots/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/application/city/main/database/frontend/city_entities/lots/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/city/main/database/frontend/city_entities/lots/class_CityLotsDatabaseWrapper.php b/application/city/main/database/frontend/city_entities/lots/class_CityLotsDatabaseWrapper.php new file mode 100644 index 0000000..cafd007 --- /dev/null +++ b/application/city/main/database/frontend/city_entities/lots/class_CityLotsDatabaseWrapper.php @@ -0,0 +1,89 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2015 City Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.shipsimu.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 CityLotsDatabaseWrapper extends BaseDatabaseWrapper implements CityLotsWrapper, Registerable { + // Constants for database table names + const DB_TABLE_CITY_LOTS = 'city_lots'; + + // Section id, an referenced city id and lot id + const DB_COLUMN_CITY_ID = 'city_id'; + const DB_COLUMN_LOT_ID = 'lot_id'; + + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this database wrapper by a provided user class + * + * @return $wrapperInstance An instance of the created wrapper class + */ + public static final function createCityLotsDatabaseWrapper () { + // Get a new instance + $wrapperInstance = new CityLotsDatabaseWrapper(); + + // Set (primary!) table name + $wrapperInstance->setTableName(self::DB_TABLE_CITY_LOTS); + + // Return the instance + return $wrapperInstance; + } + + /** + * Checks if the given city id is found in lots table + * + * @param $cityId City id to check + * @return $isFound Whether the city id is found + */ + public function ifCityHasLots ($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; + } +} + +// [EOF] +?> diff --git a/application/city/main/database/frontend/city_entities/sections/.htaccess b/application/city/main/database/frontend/city_entities/sections/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/application/city/main/database/frontend/city_entities/sections/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/city/main/database/frontend/city_sections/class_CitySectionsDatabaseWrapper.php b/application/city/main/database/frontend/city_entities/sections/class_CitySectionsDatabaseWrapper.php similarity index 97% rename from application/city/main/database/frontend/city_sections/class_CitySectionsDatabaseWrapper.php rename to application/city/main/database/frontend/city_entities/sections/class_CitySectionsDatabaseWrapper.php index bb9effe..007129d 100644 --- a/application/city/main/database/frontend/city_sections/class_CitySectionsDatabaseWrapper.php +++ b/application/city/main/database/frontend/city_entities/sections/class_CitySectionsDatabaseWrapper.php @@ -1,6 +1,6 @@ * @version 0.0.0 @@ -110,7 +110,7 @@ class CitySectionsDatabaseWrapper extends BaseDatabaseWrapper implements CitySec * Expands the sections table with initial data for given city id * * @param $cityId City id to check - * @return void + * @return $ids Sections ids from initial expansion */ public function doInitialCityExpansion ($cityId) { // Make sure this city has no sections diff --git a/application/city/main/manager/city_entities/.htaccess b/application/city/main/manager/city_entities/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/application/city/main/manager/city_entities/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/city/main/manager/city_entities/lots/.htaccess b/application/city/main/manager/city_entities/lots/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/application/city/main/manager/city_entities/lots/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/city/main/manager/city_entities/lots/class_CityLotsManager.php b/application/city/main/manager/city_entities/lots/class_CityLotsManager.php new file mode 100644 index 0000000..5e25cc4 --- /dev/null +++ b/application/city/main/manager/city_entities/lots/class_CityLotsManager.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 CityLotsManager extends BaseFrameworkSystem implements ManageableCityLots, 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 ManageableCityLots class + */ + public final static function createCityLotsManager () { + // Get new instance + $managerInstance = new CityLotsManager(); + + // Get database wrapper + $wrapperInstance = DatabaseWrapperFactory::createWrapperByConfiguredName('city_lots_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 lots 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 lots + if (!$this->getWrapperInstance()->ifCityHasLots($cityId)) { + // Nothing found, so it is a brand-new city that needs first initialization + $sections = $this->getWrapperInstance()->doInitialCityExpansion($cityId); + } else { + // @TODO Maybe some expansion is needed + } + } // END - foreach + } +} + +// [EOF] +?> diff --git a/application/city/main/manager/city_entities/sections/.htaccess b/application/city/main/manager/city_entities/sections/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/application/city/main/manager/city_entities/sections/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/city/main/manager/city_sections/class_CitySectionsManager.php b/application/city/main/manager/city_entities/sections/class_CitySectionsManager.php similarity index 97% rename from application/city/main/manager/city_sections/class_CitySectionsManager.php rename to application/city/main/manager/city_entities/sections/class_CitySectionsManager.php index b05ab91..fda32de 100644 --- a/application/city/main/manager/city_sections/class_CitySectionsManager.php +++ b/application/city/main/manager/city_entities/sections/class_CitySectionsManager.php @@ -89,7 +89,7 @@ class CitySectionsManager extends BaseFrameworkSystem implements ManageableCityS // 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); + $sections = $this->getWrapperInstance()->doInitialCityExpansion($cityId); } else { // @TODO Maybe some expansion is needed } diff --git a/application/city/main/manager/class_BaseManager.php b/application/city/main/manager/class_BaseManager.php index 69de06b..ec3e690 100644 --- a/application/city/main/manager/class_BaseManager.php +++ b/application/city/main/manager/class_BaseManager.php @@ -21,7 +21,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class BaseManager extends BaseCitySystem implements Registerable { +class BaseManager extends BaseCitySystem implements Manageable, Registerable { /** * Protected constructor * diff --git a/core b/core index d939a8d..23aa45d 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit d939a8df01d12151255dc67950f1336fa215e2ab +Subproject commit 23aa45d4a6205e26184190ca446316d06a9b4648 diff --git a/db/city_lots/.htaccess b/db/city_lots/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/db/city_lots/.htaccess @@ -0,0 +1 @@ +Deny from all -- 2.39.2