From: Roland Haeder <roland@mxchange.org>
Date: Sat, 18 Apr 2015 00:41:12 +0000 (+0200)
Subject: Added region database handling and creation (partly finished).
X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=ebdc6397026a6d03c424281266376cd48d081db8;p=city.git

Added region database handling and creation (partly finished).

Signed-off-by: Roland Haeder <roland@mxchange.org>
---

diff --git a/application/city/config.php b/application/city/config.php
index 46d0815..8c46d53 100644
--- a/application/city/config.php
+++ b/application/city/config.php
@@ -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: REGION-INFO-DB-WRAPPER-CLASS
+$cfg->setConfigEntry('region_info_db_wrapper_class', 'RegionInformationDatabaseWrapper');
+
 // CFG: CITY-INIT-STATE-CLASS
 $cfg->setConfigEntry('city_init_state_class', 'CityInitState');
 
@@ -458,6 +461,9 @@ $cfg->setConfigEntry('login_type', 'username');
 // CFG: CITY-MANAGER-CLASS
 $cfg->setConfigEntry('city_manager_class', 'CityManager');
 
+// CFG: REGION-MANAGER-CLASS
+$cfg->setConfigEntry('region_manager_class', 'RegionManager');
+
 /******************************************************************************
  *                              Console client                                *
  ******************************************************************************/
diff --git a/application/city/exceptions.php b/application/city/exceptions.php
index d3b9d64..1646b64 100644
--- a/application/city/exceptions.php
+++ b/application/city/exceptions.php
@@ -22,7 +22,7 @@
  */
 
 // The node's own exception handler
-function tests_exception_handler ($exceptionInstance) {
+function city_exception_handler ($exceptionInstance) {
 	// Is it an object and a valid instance?
 	if ((is_object($exceptionInstance)) && ($exceptionInstance instanceof FrameworkException)) {
 		// Init variable
@@ -120,6 +120,7 @@ function __assertHandler ($file, $line, $code) {
 	);
 
 	// Log assert
+	die('message='.$message);
 	syslog(LOG_WARNING, $message);
 
 	// Throw an exception here
@@ -130,7 +131,7 @@ function __assertHandler ($file, $line, $code) {
 //set_error_handler('__errorHandler');
 
 // Set the new handler
-set_exception_handler('tests_exception_handler');
+set_exception_handler('city_exception_handler');
 
 // Init assert handling
 assert_options(ASSERT_ACTIVE    , TRUE);
diff --git a/application/city/interfaces/database/frontend/class_CityInformationWrapper.php b/application/city/interfaces/database/frontend/class_CityInformationWrapper.php
index 571308c..9484065 100644
--- a/application/city/interfaces/database/frontend/class_CityInformationWrapper.php
+++ b/application/city/interfaces/database/frontend/class_CityInformationWrapper.php
@@ -31,6 +31,45 @@ interface CityInformationWrapper extends DatabaseWrapper {
 	 * @return	void
 	 */
 	function registerCityId (BaseCity $cityInstance, Requestable $requestInstance);
+
+	/**
+	 * 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
+	 */
+	function ifCityDataIsFound (CityHelper $cityInstance);
+
+	/**
+	 * Removes non-data from given array.
+	 *
+	 * @param	$data	An array with possible non-data that needs to be removed.
+	 * @return	$data	A cleaned up array with only data.
+	 */
+	function removeNonPublicDataFromArray(array $data);
+
+	/**
+	 * Checks whether the user has already founded a city
+	 *
+	 * @return	$hasFounded		Whether the user has already founded a city
+	 */
+	function ifUserHasFoundedCity ();
+
+	/**
+	 * Checks whether the given city name is taken
+	 *
+	 * @para	$cityName	Name of city
+	 * @return	$isTaken	Whether the given city name is taken
+	 */
+	function ifCityExists ($cityName);
+
+	/**
+	 * Creates a city from given request
+	 *
+	 * @para	$requestInstance	An instance of a Requestable class
+	 * @return	void
+	 */
+	function createCityByRequest (Requestable $requestInstance);
 }
 
 // [EOF]
diff --git a/application/city/interfaces/database/frontend/class_RegionInformationWrapper.php b/application/city/interfaces/database/frontend/class_RegionInformationWrapper.php
new file mode 100644
index 0000000..45d9f9f
--- /dev/null
+++ b/application/city/interfaces/database/frontend/class_RegionInformationWrapper.php
@@ -0,0 +1,50 @@
+<?php
+/**
+ * An interface for region-information (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 RegionInformationWrapper extends DatabaseWrapper {
+	/**
+	 * Removes non-data from given array.
+	 *
+	 * @param	$data	An array with possible non-data that needs to be removed.
+	 * @return	$data	A cleaned up array with only data.
+	 */
+	function removeNonPublicDataFromArray(array $data);
+
+	/**
+	 * Checks whether the user has already founded a region
+	 *
+	 * @return	$hasFounded		Whether the user has already founded a region
+	 */
+	function ifUserHasCreatedRegion ();
+
+	/**
+	 * Checks whether the given region name is taken
+	 *
+	 * @param	$regionName		Name of region
+	 * @return	$isTaken		Whether the given region name is taken
+	 */
+	function ifRegionExists ($regionName);
+}
+
+// [EOF]
+?>
diff --git a/application/city/interfaces/manager/city/class_ManageableCity.php b/application/city/interfaces/manager/city/class_ManageableCity.php
index 454b248..206e4d4 100644
--- a/application/city/interfaces/manager/city/class_ManageableCity.php
+++ b/application/city/interfaces/manager/city/class_ManageableCity.php
@@ -36,6 +36,13 @@ interface ManageableCity extends FrameworkInterface {
 	 * @return	$isTaken	Whether the given city name is already taken
 	 */
 	function ifCityNameExists ($cityName);
+
+	/**
+	 * Founds the first city. A dummy region will also be created
+	 *
+	 * @return	void
+	 */
+	function foundFirstCity ();
 }
 
 // [EOF]
diff --git a/application/city/interfaces/manager/region/.htaccess b/application/city/interfaces/manager/region/.htaccess
new file mode 100644
index 0000000..3a42882
--- /dev/null
+++ b/application/city/interfaces/manager/region/.htaccess
@@ -0,0 +1 @@
+Deny from all
diff --git a/application/city/interfaces/manager/region/class_ManageableRegion.php b/application/city/interfaces/manager/region/class_ManageableRegion.php
new file mode 100644
index 0000000..1e5b7a9
--- /dev/null
+++ b/application/city/interfaces/manager/region/class_ManageableRegion.php
@@ -0,0 +1,49 @@
+<?php
+/**
+ * An interface region 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 ManageableRegion extends FrameworkInterface {
+	/**
+	 * Checks whether the current user has already founded a region
+	 *
+	 * @return	$isFounded	Whether the current user has already founded a region
+	 */
+	function ifUserHasCreatedRegion ();
+
+	/**
+	 * Checks whether the given region name is already taken
+	 *
+	 * @para	$regionName		Name of region
+	 * @return	$isTaken		Whether the given region name is already taken
+	 */
+	function ifRegionNameExists ($regionName);
+
+	/**
+	 * Creates first region
+	 *
+	 * @return	$resultInstance		Found result after creating it
+	 */
+	function createFirstRegion ();
+}
+
+// [EOF]
+?>
diff --git a/application/city/main/city/class_BaseCity.php b/application/city/main/city/class_BaseCity.php
index c079cf8..aa3d1ee 100644
--- a/application/city/main/city/class_BaseCity.php
+++ b/application/city/main/city/class_BaseCity.php
@@ -101,7 +101,7 @@ class BaseCity extends BaseCitySystem implements Updateable, AddableCriteria {
 		assert($requestInstance instanceof Requestable);
 
 		// Add City number and type
-		$criteriaInstance->addCriteria(CityInformationDatabaseWrapper::DB_COLUMN_CITY_NR  , 1);
+		$criteriaInstance->addCriteria(CityInformationDatabaseWrapper::DB_COLUMN_CITY_ID  , 1);
 		$criteriaInstance->addCriteria(CityInformationDatabaseWrapper::DB_COLUMN_CITY_MODE, $requestInstance->getRequestElement('mode'));
 
 		// Add the City id
diff --git a/application/city/main/database/frontend/city/class_CityInformationDatabaseWrapper.php b/application/city/main/database/frontend/city/class_CityInformationDatabaseWrapper.php
index 0e78683..2884e1e 100644
--- a/application/city/main/database/frontend/city/class_CityInformationDatabaseWrapper.php
+++ b/application/city/main/database/frontend/city/class_CityInformationDatabaseWrapper.php
@@ -26,11 +26,11 @@ class CityInformationDatabaseWrapper extends BaseDatabaseWrapper implements City
 	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';
 	const DB_COLUMN_CITY_NAME        = 'city_name';
 	const DB_COLUMN_CITY_USER_ID     = 'city_user_id';
+	const DB_COLUMN_CITY_REGION_ID   = 'city_region_id';
 
 	/**
 	 * Protected constructor
@@ -71,7 +71,7 @@ class CityInformationDatabaseWrapper extends BaseDatabaseWrapper implements City
 			$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_ID  , 1);
 			$searchInstance->addCriteria(CityInformationDatabaseWrapper::DB_COLUMN_CITY_MODE, $cityInstance->getRequestInstance()->getRequestElement('mode'));
 			$searchInstance->setLimit(1);
 
@@ -160,6 +160,7 @@ class CityInformationDatabaseWrapper extends BaseDatabaseWrapper implements City
 	/**
 	 * Checks whether the given city name is taken
 	 *
+	 * @para	$cityName	Name of city
 	 * @return	$isTaken	Whether the given city name is taken
 	 */
 	public function ifCityExists ($cityName) {
@@ -176,8 +177,52 @@ class CityInformationDatabaseWrapper extends BaseDatabaseWrapper implements City
 		// Check it
 		$isTaken = $resultInstance->valid();
 
+		// Get manger instance
+		$managerInstance = ManagerFactory::createManagerByType('city');
+
+		// Set result instance
+		$managerInstance->setResultInstance($resultInstance);
+
 		// Return result
 		return $isTaken;
+
+	/**
+	 * Creates a city from given request
+	 *
+	 * @para	$requestInstance	An instance of a Requestable class
+	 * @return	void
+	 */
+	public function createCityByRequest (Requestable $requestInstance) {
+		// Make sure all required fields are there
+		assert($requestInstance->isRequestElementSet(self::DB_COLUMN_CITY_NAME));
+		assert($requestInstance->isRequestElementSet(self::DB_COLUMN_CITY_REGION_ID));
+
+		// Get city name (to save some calls)
+		$cityName = $requestInstance->getRequestElement(self::DB_COLUMN_CITY_NAME);
+
+		// Make sure the city name is not taken yet
+		assert(!$this->ifCityExists($cityName));
+
+		// Get user instance
+		$userInstance = Registry::getRegistry()->getInstance('user');
+
+		// 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 city name and assign user id
+		$dataSetInstance->addCriteria(self::DB_COLUMN_CITY_ID       , ($this->countTotalRows() + 1));
+		$dataSetInstance->addCriteria(self::DB_COLUMN_CITY_NAME     , $cityName);
+		$dataSetInstance->addCriteria(self::DB_COLUMN_CITY_USER_ID  , $userInstance->getUserId());
+		$dataSetInstance->addCriteria(self::DB_COLUMN_CITY_REGION_ID, $requestInstance->getRequestElement(self::DB_COLUMN_CITY_REGION_ID));
+
+		// "Insert" this dataset instance completely into the database
+		$this->queryInsertDataSet($dataSetInstance);
+
+		// Post-check name
+		assert($this->ifCityExists($cityName));
 	}
 }
 
diff --git a/application/city/main/database/frontend/region/.htaccess b/application/city/main/database/frontend/region/.htaccess
new file mode 100644
index 0000000..3a42882
--- /dev/null
+++ b/application/city/main/database/frontend/region/.htaccess
@@ -0,0 +1 @@
+Deny from all
diff --git a/application/city/main/database/frontend/region/class_RegionInformationDatabaseWrapper.php b/application/city/main/database/frontend/region/class_RegionInformationDatabaseWrapper.php
new file mode 100644
index 0000000..5dd0765
--- /dev/null
+++ b/application/city/main/database/frontend/region/class_RegionInformationDatabaseWrapper.php
@@ -0,0 +1,169 @@
+<?php
+/**
+ * A database wrapper for region 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 RegionInformationDatabaseWrapper extends BaseDatabaseWrapper implements RegionInformationWrapper, Registerable {
+	// Constants for database table names
+	const DB_TABLE_REGION_INFORMATION = 'region_data';
+
+	// Constants for database column names
+	const DB_COLUMN_REGION_ID          = 'region_id';
+	const DB_COLUMN_REGION_NAME        = 'region_name';
+	const DB_COLUMN_REGION_USER_ID     = 'region_user_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 createRegionInformationDatabaseWrapper () {
+		// Get a new instance
+		$wrapperInstance = new RegionInformationDatabaseWrapper();
+
+		// Set (primary!) table name
+		$wrapperInstance->setTableName(self::DB_TABLE_REGION_INFORMATION);
+
+		// 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;
+	}
+
+	/**
+	 * Checks whether the user has already founded a region
+	 *
+	 * @return	$hasFounded		Whether the user has already founded a region
+	 */
+	public function ifUserHasCreatedRegion () {
+		// Get user instance
+		$userInstance = Registry::getRegistry()->getInstance('user');
+
+		// Now get a search criteria instance
+		$searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
+
+		// Search for user's cities
+		$searchInstance->addCriteria(RegionInformationDatabaseWrapper::DB_COLUMN_REGION_USER_ID, $userInstance->getUserId());
+
+		// Get a result back
+		$resultInstance = $this->doSelectByCriteria($searchInstance);
+
+		// Get region manager instance
+		$managerInstance = ManagerFactory::createManagerByType('region');
+
+		// Set result instance
+		$managerInstance->setResultInstance($resultInstance);
+
+		// Has it been founded?
+		$hasFounded = $resultInstance->valid();
+
+		// Return result
+		return $hasFounded;
+	}
+
+	/**
+	 * Checks whether the given region name is taken
+	 *
+	 * @param	$regionName		Name of region
+	 * @return	$isTaken		Whether the given region name is taken
+	 */
+	public function ifRegionExists ($regionName) {
+		// Now get a search criteria instance
+		$searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
+
+		// Search for the region number one which is hard-coded the default
+		$searchInstance->addCriteria(RegionInformationDatabaseWrapper::DB_COLUMN_REGION_NAME, $regionName);
+		$searchInstance->setLimit(1);
+
+		// Get a result back
+		$resultInstance = $this->doSelectByCriteria($searchInstance);
+
+		// Check it
+		$isTaken = $resultInstance->next();
+		//* NOISY-DEBUG: */ $this->debugOutput('[' . __METHOD__ . ':' . __LINE__ . '] isTaken[' . gettype($isTaken) . ']=' . intval($isTaken));
+
+		// Get manger instance
+		$managerInstance = ManagerFactory::createManagerByType('region');
+
+		// Set result instance
+		$managerInstance->setResultInstance($resultInstance);
+
+		// Return result
+		return $isTaken;
+	}
+
+	/**
+	 * Creates a region by given name
+	 *
+	 * @param	$regionName		Name of region
+	 * @return	void
+	 */
+	public function createRegionByName ($regionName) {
+		// Pre-check name
+		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_INFORMATION));
+
+		// 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));
+		$dataSetInstance->addCriteria(self::DB_COLUMN_REGION_NAME   , $regionName);
+		$dataSetInstance->addCriteria(self::DB_COLUMN_REGION_USER_ID, $userInstance->getUserId());
+
+		// "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/filter/verifier/class_CityNameVerifierFilter.php b/application/city/main/filter/verifier/class_CityNameVerifierFilter.php
index e7ca6d8..a914258 100644
--- a/application/city/main/filter/verifier/class_CityNameVerifierFilter.php
+++ b/application/city/main/filter/verifier/class_CityNameVerifierFilter.php
@@ -57,7 +57,7 @@ class CityNameVerifierFilter extends BaseFilter implements Filterable {
 	 */
 	public function execute (Requestable $requestInstance, Responseable $responseInstance) {
 		// Get city name from request
-		$cityName = $requestInstance->getRequestElement('city_name');
+		$cityName = $requestInstance->getRequestElement(CityInformationDatabaseWrapper::DB_COLUMN_CITY_NAME);
 
 		// Is the city name set?
 		if (is_null($cityName)) {
diff --git a/application/city/main/manager/city/class_CityManager.php b/application/city/main/manager/city/class_CityManager.php
index 97abac7..11d1245 100644
--- a/application/city/main/manager/city/class_CityManager.php
+++ b/application/city/main/manager/city/class_CityManager.php
@@ -77,6 +77,42 @@ class CityManager extends BaseManager implements ManageableCity {
 		// Return result
 		return $isTaken;
 	}
+
+	/**
+	 * Founds the first city. A dummy region will also be created
+	 *
+	 * @return	void
+	 */
+	public function foundFirstCity () {
+		// Check on request instance and 'city_name' element
+		assert($this->getRequestInstance() instanceof Requestable);
+		assert($this->getRequestInstance()->isRequestElementSet(CityInformationDatabaseWrapper::DB_COLUMN_CITY_NAME));
+
+		// Get city name
+		$cityName = $this->getRequestInstance()->getRequestElement(CityInformationDatabaseWrapper::DB_COLUMN_CITY_NAME);
+
+		// Some pre-checks
+		assert(!$this->isCityAlreadyFounded());
+		assert(!$this->ifCityNameExists($cityName));
+
+		// Get region manager
+		$managerInstance = ManagerFactory::createManagerByType('region');
+
+		// There should be no region created
+		assert(!$managerInstance->ifUserHasCreatedRegion());
+
+		// Create first region and get back whole result
+		$regionResultInstance = $managerInstance->createFirstRegion();
+
+		// Get current entry
+		$regionData = $regionResultInstance->current();
+
+		// Add region id from it
+		$this->getRequestInstance()->setRequestElement(CityInformationDatabaseWrapper::DB_COLUMN_CITY_REGION_ID, $regionData[RegionInformationDatabaseWrapper::DB_COLUMN_REGION_ID]);
+
+		// Then create the first city
+		$this->getWrapperInstance()->createCityByRequest($this->getRequestInstance());
+	}
 }
 
 // [EOF]
diff --git a/application/city/main/manager/region/.htaccess b/application/city/main/manager/region/.htaccess
new file mode 100644
index 0000000..3a42882
--- /dev/null
+++ b/application/city/main/manager/region/.htaccess
@@ -0,0 +1 @@
+Deny from all
diff --git a/application/city/main/manager/region/class_RegionManager.php b/application/city/main/manager/region/class_RegionManager.php
new file mode 100644
index 0000000..c31b965
--- /dev/null
+++ b/application/city/main/manager/region/class_RegionManager.php
@@ -0,0 +1,110 @@
+<?php
+/**
+ * A Region 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 RegionManager extends BaseManager implements ManageableRegion {
+	/**
+	 * 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 createRegionManager () {
+		// Get new instance
+		$managerInstance = new RegionManager();
+
+		// Get database wrapper
+		$wrapperInstance = ObjectFactory::createObjectByConfiguredName('region_info_db_wrapper_class');
+
+		// And set it here
+		$managerInstance->setWrapperInstance($wrapperInstance);
+
+		// Return the prepared instance
+		return $managerInstance;
+	}
+
+	/**
+	 * Checks whether the current user has already founded a region
+	 *
+	 * @return	$isFounded	Whether the current user has already founded a region
+	 */
+	public function ifUserHasCreatedRegion () {
+		// Check if the currently set user has already founded a region
+		$isFounded = $this->getWrapperInstance()->ifUserHasCreatedRegion();
+
+		// Return result
+		return $isFounded;
+	}
+
+	/**
+	 * Checks whether the given region name is already taken
+	 *
+	 * @para	$regionName		Name of region
+	 * @return	$isTaken		Whether the given region name is already taken
+	 */
+	public function ifRegionNameExists ($regionName) {
+		// Check if the given region name is taken
+		$isTaken = $this->getWrapperInstance()->ifRegionExists($regionName);
+
+		// Return result
+		return $isTaken;
+	}
+
+	/**
+	 * Founds the first region. A dummy region will also be created
+	 *
+	 * @return	$resultInstance		Found result after creating it
+	 */
+	public function createFirstRegion () {
+		// Dummy name
+		// @TODO Move to language system
+		$regionName = 'Region 1';
+
+		// Some pre-checks
+		assert(!$this->ifUserHasCreatedRegion());
+		assert(!$this->ifRegionNameExists($regionName));
+
+		// First region can now be created
+		$this->getWrapperInstance()->createRegionByName($regionName);
+
+		// Then try to find it
+		assert($this->ifRegionNameExists($regionName));
+
+		// Get result instance
+		$resultInstance = $this->getResultInstance();
+
+		// And return it
+		return $resultInstance;
+	}
+}
+
+// [EOF]
+?>
diff --git a/core b/core
index 50591de..b9437a2 160000
--- a/core
+++ b/core
@@ -1 +1 @@
-Subproject commit 50591deeef32ed14e5f6c297c3633e378686ff2c
+Subproject commit b9437a2a7c4a83e8c03d3a7508dfb0ccf270a94b
diff --git a/db/region_data/.htaccess b/db/region_data/.htaccess
new file mode 100644
index 0000000..3a42882
--- /dev/null
+++ b/db/region_data/.htaccess
@@ -0,0 +1 @@
+Deny from all