From 317507fed8361be25688ae78bd0daa632feec04f Mon Sep 17 00:00:00 2001 From: Roland Haeder <roland@mxchange.org> Date: Fri, 29 May 2015 08:09:26 +0200 Subject: [PATCH] Added a lot new stuff for region maps (and prepared city maps). These maps can become really large and should not be created or expanded by the HTML client. Better is to let the daemon do the work. Signed-off-by: Roland Haeder <roland@mxchange.org> --- application/city/config.php | 9 ++ .../database/frontend/city/.htaccess | 1 + .../class_CityInformationWrapper.php | 0 .../database/frontend/region/.htaccess | 1 + .../class_RegionInformationWrapper.php | 8 ++ .../region/class_RegionMapWrapper.php | 28 +++++ .../region/class_ManageableRegionMap.php | 36 ++++++ .../class_CityInformationDatabaseWrapper.php | 29 +++-- .../region/class_RegionMapDatabaseWrapper.php | 103 ++++++++++++++++++ .../manager/region/class_RegionMapManager.php | 67 ++++++++++++ db/region_map/.htaccess | 1 + 11 files changed, 267 insertions(+), 16 deletions(-) create mode 100644 application/city/interfaces/database/frontend/city/.htaccess rename application/city/interfaces/database/frontend/{ => city}/class_CityInformationWrapper.php (100%) create mode 100644 application/city/interfaces/database/frontend/region/.htaccess rename application/city/interfaces/database/frontend/{ => region}/class_RegionInformationWrapper.php (91%) create mode 100644 application/city/interfaces/database/frontend/region/class_RegionMapWrapper.php create mode 100644 application/city/interfaces/manager/region/class_ManageableRegionMap.php create mode 100644 application/city/main/database/frontend/region/class_RegionMapDatabaseWrapper.php create mode 100644 application/city/main/manager/region/class_RegionMapManager.php create mode 100644 db/region_map/.htaccess diff --git a/application/city/config.php b/application/city/config.php index fba3046..6487ec0 100644 --- a/application/city/config.php +++ b/application/city/config.php @@ -46,6 +46,9 @@ $cfg->setConfigEntry('city_info_db_wrapper_class', 'CityInformationDatabaseWrapp // CFG: REGION-INFO-DB-WRAPPER-CLASS $cfg->setConfigEntry('region_info_db_wrapper_class', 'RegionInformationDatabaseWrapper'); +// CFG: REGION-MAP-DB-WRAPPER-CLASS +$cfg->setConfigEntry('region_map_db_wrapper_class', 'RegionMapDatabaseWrapper'); + // CFG: CITY-INIT-STATE-CLASS $cfg->setConfigEntry('city_init_state_class', 'CityInitState'); @@ -470,9 +473,15 @@ $cfg->setConfigEntry('login_type', 'username'); // CFG: CITY-MANAGER-CLASS $cfg->setConfigEntry('city_manager_class', 'CityManager'); +// CFG: CITY-MAP-MANAGER-CLASS +$cfg->setConfigEntry('city_map_manager_class', 'CityMapManager'); + // CFG: REGION-MANAGER-CLASS $cfg->setConfigEntry('region_manager_class', 'RegionManager'); +// CFG: REGION-MAP-MANAGER-CLASS +$cfg->setConfigEntry('region_map_manager_class', 'RegionMapManager'); + /****************************************************************************** * Console client * ******************************************************************************/ diff --git a/application/city/interfaces/database/frontend/city/.htaccess b/application/city/interfaces/database/frontend/city/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/application/city/interfaces/database/frontend/city/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/city/interfaces/database/frontend/class_CityInformationWrapper.php b/application/city/interfaces/database/frontend/city/class_CityInformationWrapper.php similarity index 100% rename from application/city/interfaces/database/frontend/class_CityInformationWrapper.php rename to application/city/interfaces/database/frontend/city/class_CityInformationWrapper.php diff --git a/application/city/interfaces/database/frontend/region/.htaccess b/application/city/interfaces/database/frontend/region/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/application/city/interfaces/database/frontend/region/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/city/interfaces/database/frontend/class_RegionInformationWrapper.php b/application/city/interfaces/database/frontend/region/class_RegionInformationWrapper.php similarity index 91% rename from application/city/interfaces/database/frontend/class_RegionInformationWrapper.php rename to application/city/interfaces/database/frontend/region/class_RegionInformationWrapper.php index 45d9f9f..2aa07c5 100644 --- a/application/city/interfaces/database/frontend/class_RegionInformationWrapper.php +++ b/application/city/interfaces/database/frontend/region/class_RegionInformationWrapper.php @@ -44,6 +44,14 @@ interface RegionInformationWrapper extends DatabaseWrapper { * @return $isTaken Whether the given region name is taken */ function ifRegionExists ($regionName); + + /** + * Creates a region by given name + * + * @param $regionName Name of region + * @return void + */ + function createRegionByName ($regionName); } // [EOF] diff --git a/application/city/interfaces/database/frontend/region/class_RegionMapWrapper.php b/application/city/interfaces/database/frontend/region/class_RegionMapWrapper.php new file mode 100644 index 0000000..b83e897 --- /dev/null +++ b/application/city/interfaces/database/frontend/region/class_RegionMapWrapper.php @@ -0,0 +1,28 @@ +<?php +/** + * An interface for region-map (database) wrapper + * + * @author Roland Haeder <webmaster@shipsimu.org> + * @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 <http://www.gnu.org/licenses/>. + */ +interface RegionMapWrapper extends DatabaseWrapper { +} + +// [EOF] +?> diff --git a/application/city/interfaces/manager/region/class_ManageableRegionMap.php b/application/city/interfaces/manager/region/class_ManageableRegionMap.php new file mode 100644 index 0000000..41dca2c --- /dev/null +++ b/application/city/interfaces/manager/region/class_ManageableRegionMap.php @@ -0,0 +1,36 @@ +<?php +/** + * An interface region map manager + * + * @author Roland Haeder <webmaster@shipsimu.org> + * @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 <http://www.gnu.org/licenses/>. + */ +interface ManageableRegionMap extends FrameworkInterface { + /** + * Creates a map, if not found yet, for given result which should contain + * data about the region in question + * + * @param $resultInstance Region result instance + * @return void + */ + function createRegionMapByResult (SearchableResult $resultInstance); +} + +// [EOF] +?> diff --git a/application/city/main/database/frontend/city/class_CityInformationDatabaseWrapper.php b/application/city/main/database/frontend/city/class_CityInformationDatabaseWrapper.php index e5cc911..9322280 100644 --- a/application/city/main/database/frontend/city/class_CityInformationDatabaseWrapper.php +++ b/application/city/main/database/frontend/city/class_CityInformationDatabaseWrapper.php @@ -65,28 +65,25 @@ class CityInformationDatabaseWrapper extends BaseDatabaseWrapper implements City * @return $isFound Whether a city id has been found for this city */ public function ifCityDataIsFound (CityHelper $cityInstance) { - // Is there cache? - if (!isset($GLOBALS[__METHOD__])) { - // Now get a search criteria instance - $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class'); + // Now get a search criteria instance + $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class'); - // Search for the city number one which is hard-coded the default - $searchInstance->addCriteria(CityInformationDatabaseWrapper::DB_COLUMN_CITY_ID , 1); - $searchInstance->addCriteria(CityInformationDatabaseWrapper::DB_COLUMN_CITY_MODE, $cityInstance->getRequestInstance()->getRequestElement('mode')); - $searchInstance->setLimit(1); + // Search for the city number one which is hard-coded the default + $searchInstance->addCriteria(CityInformationDatabaseWrapper::DB_COLUMN_CITY_ID , 1); + $searchInstance->addCriteria(CityInformationDatabaseWrapper::DB_COLUMN_CITY_MODE, $cityInstance->getRequestInstance()->getRequestElement('mode')); + $searchInstance->setLimit(1); - // Get a result back - $resultInstance = $this->doSelectByCriteria($searchInstance); + // Get a result back + $resultInstance = $this->doSelectByCriteria($searchInstance); - // Set result instance in city instance - $cityInstance->setResultInstance($resultInstance); + // Set result instance in city instance + $cityInstance->setResultInstance($resultInstance); - // Is it valid? - $GLOBALS[__METHOD__] = $resultInstance->next(); - } // END - if + // Is it valid? + $isFound = $resultInstance->next(); // Return it - return $GLOBALS[__METHOD__]; + return $isFound; } /** diff --git a/application/city/main/database/frontend/region/class_RegionMapDatabaseWrapper.php b/application/city/main/database/frontend/region/class_RegionMapDatabaseWrapper.php new file mode 100644 index 0000000..a2d215b --- /dev/null +++ b/application/city/main/database/frontend/region/class_RegionMapDatabaseWrapper.php @@ -0,0 +1,103 @@ +<?php +/** + * A database wrapper for region maps + * + * @author Roland Haeder <webmaster@shipsimu.org> + * @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 <http://www.gnu.org/licenses/>. + */ +class RegionMapDatabaseWrapper extends BaseDatabaseWrapper implements RegionMapWrapper, Registerable { + // Constants for database table names + const DB_TABLE_REGION_MAP = 'region_map'; + + // Constants for database column names + const DB_COLUMN_REGION_ID = 'region_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 createRegionMapDatabaseWrapper () { + // Get a new instance + $wrapperInstance = new RegionMapDatabaseWrapper(); + + // Set (primary!) table name + $wrapperInstance->setTableName(self::DB_TABLE_REGION_MAP); + + // Return the instance + return $wrapperInstance; + } + + /** + * Removes non-public data from given array. + * + * @param $data An array with possible non-public data that needs to be removed. + * @return $data A cleaned up array with only public data. + */ + public function removeNonPublicDataFromArray(array $data) { + // Currently call only inner method + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('REGION-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: Calling parent::removeNonPublicDataFromArray(data) ...'); + $data = parent::removeNonPublicDataFromArray($data); + + // Return cleaned data + return $data; + } + + /** + * Creates a region by given name + * + * @return void + */ + public function createRegionByName () { + // Pre-check + die(__METHOD__ . ': Unfinshed!'); + assert(!$this->ifRegionExists($regionName)); + + // Get user instance + $userInstance = Registry::getRegistry()->getInstance('user'); + + // Get a dataset instance + $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_REGION_MAP)); + + // Set the primary key + $dataSetInstance->setUniqueKey(self::DB_COLUMN_REGION_ID); + + // Add region name and assign user id + $dataSetInstance->addCriteria(self::DB_COLUMN_REGION_ID , ($this->countTotalRows() + 1)); + + // "Insert" this dataset instance completely into the database + $this->queryInsertDataSet($dataSetInstance); + + // Post-check name + assert($this->ifRegionExists($regionName)); + } +} + +// [EOF] +?> diff --git a/application/city/main/manager/region/class_RegionMapManager.php b/application/city/main/manager/region/class_RegionMapManager.php new file mode 100644 index 0000000..516b1ba --- /dev/null +++ b/application/city/main/manager/region/class_RegionMapManager.php @@ -0,0 +1,67 @@ +<?php +/** + * A region map manager + * + * @author Roland Haeder <webmaster@ship-simu.org> + * @version 0.0.0 + * @copyright Copyright (c) 2015 Region 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 <http://www.gnu.org/licenses/>. + */ +class RegionMapManager extends BaseManager implements ManageableRegionMap { + /** + * 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 ManageableRegion class + */ + public final static function createRegionMapManager () { + // Get new instance + $managerInstance = new RegionMapManager(); + + // Get database wrapper + $wrapperInstance = ObjectFactory::createObjectByConfiguredName('region_map_db_wrapper_class'); + + // And set it here + $managerInstance->setWrapperInstance($wrapperInstance); + + // Return the prepared instance + return $managerInstance; + } + + /** + * Creates a map, if not found yet, for given result which should contain + * data about the region in question + * + * @param $resultInstance Region result instance + * @return void + */ + public function createRegionMapByResult (SearchableResult $resultInstance) { + die('!ok'); + } +} + +// [EOF] +?> diff --git a/db/region_map/.htaccess b/db/region_map/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/db/region_map/.htaccess @@ -0,0 +1 @@ +Deny from all -- 2.39.5