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\Middleware\Debug\DebugMiddleware;
13 use Org\Mxchange\CoreFramework\Request\Requestable;
14 use Org\Mxchange\CoreFramework\Response\Responseable;
19 * @author Roland Haeder <webmaster@ship-simu.org>
21 * @copyright Copyright (c) 2015 - 2023 City Developer Team
22 * @license GNU GPL 3.0 or any newer version
23 * @link http://www.ship-simu.org
25 * This program is free software: you can redistribute it and/or modify
26 * it under the terms of the GNU General Public License as published by
27 * the Free Software Foundation, either version 3 of the License, or
28 * (at your option) any later version.
30 * This program is distributed in the hope that it will be useful,
31 * but WITHOUT ANY WARRANTY; without even the implied warranty of
32 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 * GNU General Public License for more details.
35 * You should have received a copy of the GNU General Public License
36 * along with this program. If not, see <http://www.gnu.org/licenses/>.
38 class CityManager extends BaseManager implements ManageableCity {
40 * Protected constructor
44 protected function __construct () {
45 // Call parent constructor
46 parent::__construct(__CLASS__);
50 * Creates an instance of this class
52 * @return $managerInstance An instance of a ManageableCity class
54 public final static function createCityManager () {
56 $managerInstance = new CityManager();
58 // Get database frontend
59 $frontendInstance = DatabaseFrontendFactory::createFrontendByConfiguredName('city_info_db_frontend_class');
62 $managerInstance->setFrontendInstance($frontendInstance);
64 // Return the prepared instance
65 return $managerInstance;
69 * Checks whether the current user has already founded a city
71 * @return $isFounded Whether the current user has already founded a city
73 public function isCityAlreadyFounded () {
74 // Check if the currently set user has already founded a city
75 $isFounded = $this->getFrontendInstance()->ifUserHasFoundedCity();
82 * Checks whether the given city name is already taken
84 * @para $cityName Name of city
85 * @return $isTaken Whether the given city name is already taken
87 public function ifCityNameExists (string $cityName) {
88 // Check if the given city name is taken
89 $isTaken = $this->getFrontendInstance()->ifCityExists($cityName);
96 * Founds the first city. A dummy region will also be created
100 public function foundFirstCity () {
101 // Check on request instance and 'city_name' element
102 assert(FrameworkBootstrap::getRequestInstance() instanceof Requestable);
103 assert(FrameworkBootstrap::getRequestInstance()->isRequestElementSet(CityInformationDatabaseFrontend::DB_COLUMN_CITY_NAME));
106 $cityName = FrameworkBootstrap::getRequestInstance()->getRequestElement(CityInformationDatabaseFrontend::DB_COLUMN_CITY_NAME);
109 assert(!$this->isCityAlreadyFounded());
110 assert(!$this->ifCityNameExists($cityName));
112 // Get region manager
113 $managerInstance = ManagerFactory::createManagerByType('region');
115 // The manager instance should be valid and no region should be created
116 assert($managerInstance instanceof ManageableRegion);
117 assert(!$managerInstance->ifUserHasCreatedRegion());
119 // Create first region and get back whole result
120 $regionResultInstance = $managerInstance->createFirstRegion();
123 $regionData = $regionResultInstance->current();
125 // Add region id from it
126 FrameworkBootstrap::getRequestInstance()->setRequestElement(CityInformationDatabaseFrontend::DB_COLUMN_CITY_REGION_ID, $regionData[RegionInformationDatabaseFrontend::DB_COLUMN_REGION_ID]);
128 // Then create the first city
129 $this->getFrontendInstance()->createCityByRequest(FrameworkBootstrap::getRequestInstance());
133 * Renders the city map and forwards the output to the helper instance.
135 * @param $helperInstance An instance of a HelpableTemplate class
138 public function renderCityMap (HelpableTemplate $helperInstance) {
139 DebugMiddleware::getSelfInstance()->partialStub('Please implement this method.');