3 namespace Org\Mxchange\City\Database\Frontend\Districts;
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
9 * A database wrapper for city districts
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 CityDistrictsDatabaseWrapper extends BaseDatabaseWrapper implements CityDistrictsWrapper, Registerable {
31 // Constants for database table names
32 const DB_TABLE_CITY_DISTRICTS = 'city_districts';
34 // Section id, an referenced city id and district id
35 const DB_COLUMN_CITY_ID = 'city_id';
36 const DB_COLUMN_DISTRICT_ID = 'district_id';
39 * Protected constructor
43 protected function __construct () {
44 // Call parent constructor
45 parent::__construct(__CLASS__);
49 * Creates an instance of this database wrapper by a provided user class
51 * @return $wrapperInstance An instance of the created wrapper class
53 public static final function createCityDistrictsDatabaseWrapper () {
55 $wrapperInstance = new CityDistrictsDatabaseWrapper();
57 // Set (primary!) table name
58 $wrapperInstance->setTableName(self::DB_TABLE_CITY_DISTRICTS);
60 // Return the instance
61 return $wrapperInstance;
65 * Checks if the given city id is found in districts table
67 * @param $cityId City id to check
68 * @return $isFound Whether the city id is found
70 public function ifCityHasDistricts ($cityId) {
71 // Get search instance
72 $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
74 // Search for 'city_id'
75 $searchInstance->addCriteria(self::DB_COLUMN_CITY_ID, $cityId);
78 * Only one entry is enough to find, else this query could run very
81 $searchInstance->setLimit(1);
83 // Execute it on database instance
84 $resultInstance = $this->doSelectByCriteria($searchInstance);
86 // Check if there is one entry
87 $isFound = $resultInstance->next();