3 namespace Org\Mxchange\City\Manager\City;
5 // Import application-specific stuff
6 use Org\Mxchange\City\Database\Frontend\Information\CityInformationDatabaseFrontend;
7 use Org\Mxchange\City\Factory\Manager\ManagerFactory;
9 // Import framework stuff
10 use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
11 use Org\Mxchange\CoreFramework\Factory\Database\Frontend\DatabaseFrontendFactory;
12 use Org\Mxchange\CoreFramework\Request\Requestable;
13 use Org\Mxchange\CoreFramework\Response\Responseable;
18 * @author Roland Haeder <webmaster@ship-simu.org>
20 * @copyright Copyright (c) 2015 - 2023 City Developer Team
21 * @license GNU GPL 3.0 or any newer version
22 * @link http://www.ship-simu.org
24 * This program is free software: you can redistribute it and/or modify
25 * it under the terms of the GNU General Public License as published by
26 * the Free Software Foundation, either version 3 of the License, or
27 * (at your option) any later version.
29 * This program is distributed in the hope that it will be useful,
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 * GNU General Public License for more details.
34 * You should have received a copy of the GNU General Public License
35 * along with this program. If not, see <http://www.gnu.org/licenses/>.
37 class CityManager extends BaseManager implements ManageableCity {
39 * Protected constructor
43 protected function __construct () {
44 // Call parent constructor
45 parent::__construct(__CLASS__);
49 * Creates an instance of this class
51 * @return $managerInstance An instance of a ManageableCity class
53 public final static function createCityManager () {
55 $managerInstance = new CityManager();
57 // Get database frontend
58 $frontendInstance = DatabaseFrontendFactory::createFrontendByConfiguredName('city_info_db_frontend_class');
61 $managerInstance->setFrontendInstance($frontendInstance);
63 // Return the prepared instance
64 return $managerInstance;
68 * Checks whether the current user has already founded a city
70 * @return $isFounded Whether the current user has already founded a city
72 public function isCityAlreadyFounded () {
73 // Check if the currently set user has already founded a city
74 $isFounded = $this->getFrontendInstance()->ifUserHasFoundedCity();
81 * Checks whether the given city name is already taken
83 * @para $cityName Name of city
84 * @return $isTaken Whether the given city name is already taken
86 public function ifCityNameExists (string $cityName) {
87 // Check if the given city name is taken
88 $isTaken = $this->getFrontendInstance()->ifCityExists($cityName);
95 * Founds the first city. A dummy region will also be created
99 public function foundFirstCity () {
100 // Check on request instance and 'city_name' element
101 assert(FrameworkBootstrap::getRequestInstance() instanceof Requestable);
102 assert(FrameworkBootstrap::getRequestInstance()->isRequestElementSet(CityInformationDatabaseFrontend::DB_COLUMN_CITY_NAME));
105 $cityName = FrameworkBootstrap::getRequestInstance()->getRequestElement(CityInformationDatabaseFrontend::DB_COLUMN_CITY_NAME);
108 assert(!$this->isCityAlreadyFounded());
109 assert(!$this->ifCityNameExists($cityName));
111 // Get region manager
112 $managerInstance = ManagerFactory::createManagerByType('region');
114 // The manager instance should be valid and no region should be created
115 assert($managerInstance instanceof ManageableRegion);
116 assert(!$managerInstance->ifUserHasCreatedRegion());
118 // Create first region and get back whole result
119 $regionResultInstance = $managerInstance->createFirstRegion();
122 $regionData = $regionResultInstance->current();
124 // Add region id from it
125 FrameworkBootstrap::getRequestInstance()->setRequestElement(CityInformationDatabaseFrontend::DB_COLUMN_CITY_REGION_ID, $regionData[RegionInformationDatabaseFrontend::DB_COLUMN_REGION_ID]);
127 // Then create the first city
128 $this->getFrontendInstance()->createCityByRequest(FrameworkBootstrap::getRequestInstance());
132 * Renders the city map and forwards the output to the helper instance.
134 * @param $helperInstance An instance of a HelpableTemplate class
137 public function renderCityMap (HelpableTemplate $helperInstance) {
138 $this->partialStub('Please implement this method.');