* @version 0.0.0 * @copyright Copyright (c) 2015, 2016 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 . */ class CityLotsDatabaseWrapper extends BaseDatabaseWrapper implements CityLotsWrapper, Registerable { // Constants for database table names const DB_TABLE_CITY_LOTS = 'city_lots'; // Section id, an referenced city id and lot id const DB_COLUMN_CITY_ID = 'city_id'; const DB_COLUMN_LOT_ID = 'lot_id'; const DB_COLUMN_DISTRICT_ID = 'district_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 createCityLotsDatabaseWrapper () { // Get a new instance $wrapperInstance = new CityLotsDatabaseWrapper(); // Set (primary!) table name $wrapperInstance->setTableName(self::DB_TABLE_CITY_LOTS); // Return the instance return $wrapperInstance; } /** * Checks if the given city id is found in lots table * * @param $cityId City id to check * @return $isFound Whether the city id is found */ public function ifCityHasLots ($cityId) { // Get search instance $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class'); // Search for 'city_id' $searchInstance->addCriteria(self::DB_COLUMN_CITY_ID, $cityId); /* * Only one entry is enough to find, else this query could run very * long on large maps. */ $searchInstance->setLimit(1); // Execute it on database instance $resultInstance = $this->doSelectByCriteria($searchInstance); // Check if there is one entry $isFound = $resultInstance->next(); // Return result return $isFound; } }