3 namespace Org\Mxchange\City\Manager\City;
5 // Import application-specific stuff
6 use Org\Mxchange\City\Database\Frontend\Information\CityInformationDatabaseWrapper;
8 // Import framework stuff
9 use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
10 use Org\Mxchange\CoreFramework\Factory\Database\Wrapper\DatabaseWrapperFactory;
11 use Org\Mxchange\CoreFramework\Request\Requestable;
12 use Org\Mxchange\CoreFramework\Response\Responseable;
17 * @author Roland Haeder <webmaster@ship-simu.org>
19 * @copyright Copyright (c) 2015, 2016 City Developer Team
20 * @license GNU GPL 3.0 or any newer version
21 * @link http://www.ship-simu.org
23 * This program is free software: you can redistribute it and/or modify
24 * it under the terms of the GNU General Public License as published by
25 * the Free Software Foundation, either version 3 of the License, or
26 * (at your option) any later version.
28 * This program is distributed in the hope that it will be useful,
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 * GNU General Public License for more details.
33 * You should have received a copy of the GNU General Public License
34 * along with this program. If not, see <http://www.gnu.org/licenses/>.
36 class CityManager extends BaseManager implements ManageableCity {
38 * Protected constructor
42 protected function __construct () {
43 // Call parent constructor
44 parent::__construct(__CLASS__);
48 * Creates an instance of this class
50 * @return $managerInstance An instance of a ManageableCity class
52 public final static function createCityManager () {
54 $managerInstance = new CityManager();
56 // Get database wrapper
57 $wrapperInstance = DatabaseWrapperFactory::createWrapperByConfiguredName('city_info_db_wrapper_class');
60 $managerInstance->setWrapperInstance($wrapperInstance);
62 // Return the prepared instance
63 return $managerInstance;
67 * Checks whether the current user has already founded a city
69 * @return $isFounded Whether the current user has already founded a city
71 public function isCityAlreadyFounded () {
72 // Check if the currently set user has already founded a city
73 $isFounded = $this->getWrapperInstance()->ifUserHasFoundedCity();
80 * Checks whether the given city name is already taken
82 * @para $cityName Name of city
83 * @return $isTaken Whether the given city name is already taken
85 public function ifCityNameExists ($cityName) {
86 // Check if the given city name is taken
87 $isTaken = $this->getWrapperInstance()->ifCityExists($cityName);
94 * Founds the first city. A dummy region will also be created
98 public function foundFirstCity () {
99 // Check on request instance and 'city_name' element
100 assert(FrameworkBootstrap::getRequestInstance() instanceof Requestable);
101 assert(FrameworkBootstrap::getRequestInstance()->isRequestElementSet(CityInformationDatabaseWrapper::DB_COLUMN_CITY_NAME));
104 $cityName = FrameworkBootstrap::getRequestInstance()->getRequestElement(CityInformationDatabaseWrapper::DB_COLUMN_CITY_NAME);
107 assert(!$this->isCityAlreadyFounded());
108 assert(!$this->ifCityNameExists($cityName));
110 // Get region manager
111 $managerInstance = ManagerFactory::createManagerByType('region');
113 // The manager instance should be valid and no region should be created
114 assert($managerInstance instanceof ManageableRegion);
115 assert(!$managerInstance->ifUserHasCreatedRegion());
117 // Create first region and get back whole result
118 $regionResultInstance = $managerInstance->createFirstRegion();
121 $regionData = $regionResultInstance->current();
123 // Add region id from it
124 FrameworkBootstrap::getRequestInstance()->setRequestElement(CityInformationDatabaseWrapper::DB_COLUMN_CITY_REGION_ID, $regionData[RegionInformationDatabaseWrapper::DB_COLUMN_REGION_ID]);
126 // Then create the first city
127 $this->getWrapperInstance()->createCityByRequest(FrameworkBootstrap::getRequestInstance());
131 * Renders the city map and forwards the output to the helper instance.
133 * @param $helperInstance An instance of a HelpableTemplate class
136 public function renderCityMap (HelpableTemplate $helperInstance) {
137 $this->partialStub('Please implement this method.');