3 namespace Org\Mxchange\City\Database\Frontend\Lots;
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
9 * A database wrapper for city lots
11 * @author Roland Haeder <webmaster@shipsimu.org>
13 * @copyright Copyright (c) 2015, 2016 City Developer Team
14 * @license GNU GPL 3.0 or any newer version
15 * @link http://www.shipsimu.org
17 * This program is free software: you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation, either version 3 of the License, or
20 * (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program. If not, see <http://www.gnu.org/licenses/>.
30 class CityLotsDatabaseWrapper extends BaseDatabaseWrapper implements CityLotsWrapper, Registerable {
31 // Constants for database table names
32 const DB_TABLE_CITY_LOTS = 'city_lots';
34 // Section id, an referenced city id and lot id
35 const DB_COLUMN_CITY_ID = 'city_id';
36 const DB_COLUMN_LOT_ID = 'lot_id';
37 const DB_COLUMN_DISTRICT_ID = 'district_id';
40 * Protected constructor
44 protected function __construct () {
45 // Call parent constructor
46 parent::__construct(__CLASS__);
50 * Creates an instance of this database wrapper by a provided user class
52 * @return $wrapperInstance An instance of the created wrapper class
54 public static final function createCityLotsDatabaseWrapper () {
56 $wrapperInstance = new CityLotsDatabaseWrapper();
58 // Set (primary!) table name
59 $wrapperInstance->setTableName(self::DB_TABLE_CITY_LOTS);
61 // Return the instance
62 return $wrapperInstance;
66 * Checks if the given city id is found in lots table
68 * @param $cityId City id to check
69 * @return $isFound Whether the city id is found
71 public function ifCityHasLots ($cityId) {
72 // Get search instance
73 $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
75 // Search for 'city_id'
76 $searchInstance->addCriteria(self::DB_COLUMN_CITY_ID, $cityId);
79 * Only one entry is enough to find, else this query could run very
82 $searchInstance->setLimit(1);
84 // Execute it on database instance
85 $resultInstance = $this->doSelectByCriteria($searchInstance);
87 // Check if there is one entry
88 $isFound = $resultInstance->next();