* @version 0.0.0 * @copyright Copyright (c) 2015, 2016 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 . */ class CityManager extends BaseManager implements ManageableCity { /** * 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 ManageableCity class */ public final static function createCityManager () { // Get new instance $managerInstance = new CityManager(); // Get database wrapper $wrapperInstance = DatabaseWrapperFactory::createWrapperByConfiguredName('city_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 city * * @return $isFounded Whether the current user has already founded a city */ public function isCityAlreadyFounded () { // Check if the currently set user has already founded a city $isFounded = $this->getWrapperInstance()->ifUserHasFoundedCity(); // Return result return $isFounded; } /** * Checks whether the given city name is already taken * * @para $cityName Name of city * @return $isTaken Whether the given city name is already taken */ public function ifCityNameExists ($cityName) { // Check if the given city name is taken $isTaken = $this->getWrapperInstance()->ifCityExists($cityName); // 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'); // The manager instance should be valid and no region should be created assert($managerInstance instanceof ManageableRegion); 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()); } /** * Renders the city map and forwards the output to the helper instance. * * @param $helperInstance An instance of a HelpableTemplate class * @return void */ public function renderCityMap (HelpableTemplate $helperInstance) { $this->partialStub('Please implement this method.'); } } // [EOF] ?>