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