]> git.mxchange.org Git - city.git/commitdiff
Added more console and database frontend classes.
authorRoland Haeder <roland@mxchange.org>
Tue, 24 Mar 2015 17:20:27 +0000 (18:20 +0100)
committerRoland Haeder <roland@mxchange.org>
Tue, 24 Mar 2015 17:20:27 +0000 (18:20 +0100)
Signed-off-by: Roland Haeder <roland@mxchange.org>
19 files changed:
application/city/config.php
application/city/interfaces/database/.htaccess [new file with mode: 0644]
application/city/interfaces/database/frontend/.htaccess [new file with mode: 0644]
application/city/interfaces/database/frontend/class_CityInformationWrapper.php [new file with mode: 0644]
application/city/main/city/class_
application/city/main/class_
application/city/main/database/.htaccess [new file with mode: 0644]
application/city/main/database/frontend/.htaccess [new file with mode: 0644]
application/city/main/database/frontend/city/.htaccess [new file with mode: 0644]
application/city/main/database/frontend/city/class_CityInformationDatabaseWrapper.php [new file with mode: 0644]
application/city/main/factories/states/.htaccess [new file with mode: 0644]
application/city/main/factories/states/city/.htaccess [new file with mode: 0644]
application/city/main/factories/states/city/class_CityStateFactory.php [new file with mode: 0644]
application/city/main/states/.htaccess [new file with mode: 0644]
application/city/main/states/city/.htaccess [new file with mode: 0644]
application/city/main/states/city/class_ [new file with mode: 0644]
application/city/main/states/city/class_BaseCityState.php [new file with mode: 0644]
application/city/main/states/city/init/class_CityInitState.php [new file with mode: 0644]
core

index 293d0442b01c08899ddd43694d8ee53525a56847..0a5c1b63bee2ba7c55992bb65ba5c15ceadad9e2 100644 (file)
@@ -43,6 +43,9 @@ $cfg->setConfigEntry('news_reader_class', 'ConsoleNewsReader');
 // CFG: CITY-INFO-DB-WRAPPER-CLASS
 $cfg->setConfigEntry('city_info_db_wrapper_class', 'CityInformationDatabaseWrapper');
 
+// CFG: CITY-INIT-STATE-CLASS
+$cfg->setConfigEntry('city_init_state_class', 'CityInitState');
+
 /******************************************************************************
  *                                HTML client                                 *
  ******************************************************************************/
diff --git a/application/city/interfaces/database/.htaccess b/application/city/interfaces/database/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/application/city/interfaces/database/frontend/.htaccess b/application/city/interfaces/database/frontend/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/application/city/interfaces/database/frontend/class_CityInformationWrapper.php b/application/city/interfaces/database/frontend/class_CityInformationWrapper.php
new file mode 100644 (file)
index 0000000..5f2edbc
--- /dev/null
@@ -0,0 +1,37 @@
+<?php
+/**
+ * An interface for city-information (database) wrapper
+ *
+ * @author             Roland Haeder <webmaster@shipsimu.org>
+ * @version            0.0.0
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 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 CityInformationWrapper extends DatabaseWrapper {
+       /**
+        * 'Registers' a new city id along with data provided in the city instance.
+        * This may sound confusing but avoids double code very nicely...
+        *
+        * @param       $cityInstance           A city instance
+        * @param       $requestInstance        An instance of a Requestable class
+        * @return      void
+        */
+       function registerCityId (BaseCity $cityInstance, Requestable $requestInstance);
+}
+
+// [EOF]
+?>
index 915a3e85db019a2cfa938dbb6ce45410022f456b..19410eca031c385fc35450d5110e61421c8a2eb7 100644 (file)
@@ -21,7 +21,7 @@
  * 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 Hub???Node extends BaseHubNode implements NodeHelper, Registerable {
+class Simulation???City extends BaseCity implements CityHelper, Registerable {
        /**
         * Protected constructor
         *
@@ -38,9 +38,9 @@ class Hub???Node extends BaseHubNode implements NodeHelper, Registerable {
         * @param       $requestInstance        An instance of a Requestable class
         * @return      $nodeInstance           An instance of this hub-node class
         */
-       public final static function createHub???Node (Requestable $requestInstance) {
+       public final static function createCity???City (Requestable $requestInstance) {
                // Get a new instance
-               $nodeInstance = new Hub???Node();
+               $nodeInstance = new City???City();
 
                // Set the request instance
                $nodeInstance->setRequestInstance($requestInstance);
@@ -78,7 +78,7 @@ class Hub???Node extends BaseHubNode implements NodeHelper, Registerable {
         *
         * @return      void
         */
-       public function addExtraHubFilters () {
+       public function addExtraCityFilters () {
                // Add some filters here
        }
 
index 2dea4bd3893a2fde75698cbb4a2c29d14acaffef..2ebd8759474ac7673624169efeeae9ee5b0820fb 100644 (file)
@@ -4,7 +4,7 @@
  *
  * @author             Roland Haeder <webmaster@ship-simu.org>
  * @version            0.0.0
- * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @copyright  Copyright (c) 2015 City Developer Team
  * @license            GNU GPL 3.0 or any newer version
  * @link               http://www.ship-simu.org
  *
diff --git a/application/city/main/database/.htaccess b/application/city/main/database/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/application/city/main/database/frontend/.htaccess b/application/city/main/database/frontend/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/application/city/main/database/frontend/city/.htaccess b/application/city/main/database/frontend/city/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/application/city/main/database/frontend/city/class_CityInformationDatabaseWrapper.php b/application/city/main/database/frontend/city/class_CityInformationDatabaseWrapper.php
new file mode 100644 (file)
index 0000000..641e763
--- /dev/null
@@ -0,0 +1,129 @@
+<?php
+/**
+ * A database wrapper for city informations
+ *
+ * @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 CityInformationDatabaseWrapper extends BaseDatabaseWrapper implements CityInformationWrapper, Registerable {
+       // Constants for database table names
+       const DB_TABLE_CITY_INFORMATION = 'city_data';
+
+       // Constants for database column names
+       const DB_COLUMN_CITY_NR          = 'city_nr';
+       const DB_COLUMN_CITY_ID          = 'city_id';
+       const DB_COLUMN_CITY_MODE        = 'city_mode';
+
+       /**
+        * 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 createCityInformationDatabaseWrapper () {
+               // Get a new instance
+               $wrapperInstance = new CityInformationDatabaseWrapper();
+
+               // Set (primary!) table name
+               $wrapperInstance->setTableName(self::DB_TABLE_CITY_INFORMATION);
+
+               // Return the instance
+               return $wrapperInstance;
+       }
+
+       /**
+        * Checks whether there is an entry for given city instance
+        *
+        * @param       $cityInstance   An instance of a CityHelper class
+        * @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');
+
+                       // Search for the city number one which is hard-coded the default
+                       $searchInstance->addCriteria(CityInformationDatabaseWrapper::DB_COLUMN_CITY_NR  , 1);
+                       $searchInstance->addCriteria(CityInformationDatabaseWrapper::DB_COLUMN_CITY_MODE, $cityInstance->getRequestInstance()->getRequestElement('mode'));
+                       $searchInstance->setLimit(1);
+
+                       // Get a result back
+                       $resultInstance = $this->doSelectByCriteria($searchInstance);
+
+                       // Set result instance in city instance
+                       $cityInstance->setResultInstance($resultInstance);
+
+                       // Is it valid?
+                       $GLOBALS[__METHOD__] = $resultInstance->next();
+               } // END - if
+
+               // Return it
+               return $GLOBALS[__METHOD__];
+       }
+
+       /**
+        * 'Registers' a new city id along with data provided in the city instance.
+        * This may sound confusing but avoids double code very nicely...
+        *
+        * @param       $cityInstance           A city instance
+        * @param       $requestInstance        An instance of a Requestable class
+        * @return      void
+        */
+       public function registerCityId (BaseCity $cityInstance, Requestable $requestInstance) {
+               // Get a dataset instance
+               $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_CITY_INFORMATION));
+
+               // Set the primary key
+               $dataSetInstance->setUniqueKey(self::DB_COLUMN_CITY_ID);
+
+               // Add registration elements to the dataset
+               $cityInstance->addElementsToDataSet($dataSetInstance, $requestInstance);
+
+               // "Insert" this dataset instance completely into the database
+               $this->queryInsertDataSet($dataSetInstance);
+       }
+
+       /**
+        * 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('CITY-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: Calling parent::removeNonPublicDataFromArray(data) ...');
+               $data = parent::removeNonPublicDataFromArray($data);
+
+               // Return cleaned data
+               return $data;
+       }
+}
+
+// [EOF]
+?>
diff --git a/application/city/main/factories/states/.htaccess b/application/city/main/factories/states/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/application/city/main/factories/states/city/.htaccess b/application/city/main/factories/states/city/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/application/city/main/factories/states/city/class_CityStateFactory.php b/application/city/main/factories/states/city/class_CityStateFactory.php
new file mode 100644 (file)
index 0000000..8c8fffe
--- /dev/null
@@ -0,0 +1,65 @@
+<?php
+/**
+ * A factory class for city states
+ *
+ * @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 CityStateFactory extends ObjectFactory {
+       /**
+        * Protected constructor
+        *
+        * @return      void
+        */
+       protected function __construct () {
+               // Call parent constructor
+               parent::__construct(__CLASS__);
+       }
+
+       /**
+        * Creates an instance of a configurable city state and sets it in the
+        * given city instance.
+        *
+        * @param       $stateName              Name of the state
+        * @param       $cityInstance   A CityHelper class instance
+        * @return      $stateInstance  A Stateable class instance
+        */
+       public static final function createCityStateInstanceByName ($stateName, CityHelper $cityInstance) {
+               // Then construct the class' configuraton entry
+               $className = 'city_' . $stateName . '_state_class';
+
+               // Get a class from that configuration entry
+               $stateInstance = self::createObjectByConfiguredName($className, array($cityInstance));
+
+               // Debug message
+               self::createDebugInstance(__CLASS__)->debugOutput('CITY-STATE-FACTORY[' . __METHOD__ . ':' . __LINE__ . ']: City state has changed from ' . $cityInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.');
+
+               // Once we have that state, set it in the city instance
+               $cityInstance->setStateInstance($stateInstance);
+
+               // Update city data
+               $cityInstance->updateCityData();
+
+               // For any purposes, return the state instance
+               return $stateInstance;
+       }
+}
+
+// [EOF]
+?>
diff --git a/application/city/main/states/.htaccess b/application/city/main/states/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/application/city/main/states/city/.htaccess b/application/city/main/states/city/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/application/city/main/states/city/class_ b/application/city/main/states/city/class_
new file mode 100644 (file)
index 0000000..5df9aa5
--- /dev/null
@@ -0,0 +1,60 @@
+<?php
+/**
+ * A ??? city state class
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+class City???State extends BaseCityState implements Stateable {
+       /**
+        * Protected constructor
+        *
+        * @return      void
+        */
+       protected function __construct () {
+               // Call parent constructor
+               parent::__construct(__CLASS__);
+
+               // Set state name
+               $this->setStateName('!!!');
+       }
+
+       /**
+        * Creates an instance of this class
+        *
+        * @param       $cityInstance   An instance of a CityHelper class
+        * @return      $stateInstance  An instance of a Stateable class
+        */
+       public final static function createCity???State (CityHelper $cityInstance) {
+               // Get new instance
+               $stateInstance = new City???State();
+
+               // Debug message
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CITY-STATE: Has changed from ' . $cityInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.');
+
+               // Set the city instance
+               $stateInstance->setCityInstance($cityInstance);
+
+               // Return the prepared instance
+               return $stateInstance;
+       }
+}
+
+// [EOF]
+?>
diff --git a/application/city/main/states/city/class_BaseCityState.php b/application/city/main/states/city/class_BaseCityState.php
new file mode 100644 (file)
index 0000000..fb05751
--- /dev/null
@@ -0,0 +1,53 @@
+<?php
+/**
+ * A general city state class
+ *
+ * @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 BaseCityState extends BaseState {
+       /**
+        * Protected constructor
+        *
+        * @param       $className      Name of the class
+        * @return      void
+        */
+       protected function __construct ($className) {
+               // Call parent constructor
+               parent::__construct($className);
+       }
+
+       /**
+        * Validates whether the state is 'active' or throws an exception if
+        * it is every other state.
+        *
+        * @return      void
+        * @throws      InvalidStateException   If the state is not 'active'
+        */
+       public function validateCityStateIsActive () {
+               // Just compare it...
+               if (!$this instanceof CityActiveState) {
+                       // Throw the exception
+                       throw new InvalidStateException($this, self::EXCEPTION_INVALID_STATE);
+               } // END - if
+       }
+}
+
+// [EOF]
+?>
diff --git a/application/city/main/states/city/init/class_CityInitState.php b/application/city/main/states/city/init/class_CityInitState.php
new file mode 100644 (file)
index 0000000..28584cd
--- /dev/null
@@ -0,0 +1,57 @@
+<?php
+/**
+ * A init city state class
+ *
+ * @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 CityInitState extends BaseCityState implements Stateable {
+       /**
+        * Protected constructor
+        *
+        * @return      void
+        */
+       protected function __construct () {
+               // Call parent constructo
+               parent::__construct(__CLASS__);
+
+               // Set state name
+               $this->setStateName('init');
+       }
+
+       /**
+        * Creates an instance of this class
+        *
+        * @param       $cityInstance   An instance of a CityHelper class
+        * @return      $stateInstance  An instance of a Stateable class
+        */
+       public static final function createCityInitState (CityHelper $cityInstance) {
+               // Get new instance
+               $stateInstance = new CityInitState();
+
+               // Set the city instance
+               $stateInstance->setCityInstance($cityInstance);
+
+               // Return the prepared instance
+               return $stateInstance;
+       }
+}
+
+// [EOF]
+?>
diff --git a/core b/core
index 87b2be57b63b6e923aab40e0fbba2ff86db88a86..c0922d6cccd0fb0f1b5221585748e92d02ad1cee 160000 (submodule)
--- a/core
+++ b/core
@@ -1 +1 @@
-Subproject commit 87b2be57b63b6e923aab40e0fbba2ff86db88a86
+Subproject commit c0922d6cccd0fb0f1b5221585748e92d02ad1cee