3 namespace Org\Mxchange\City\Database\Frontend\Districts;
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 districts
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 CityDistrictsDatabaseWrapper extends BaseDatabaseWrapper implements CityDistrictsWrapper, Registerable {
33 // Constants for database table names
34 const DB_TABLE_CITY_DISTRICTS = 'city_districts';
36 // Section id, an referenced city id and district id
37 const DB_COLUMN_CITY_ID = 'city_id';
38 const DB_COLUMN_DISTRICT_ID = 'district_id';
41 * Protected constructor
45 protected function __construct () {
46 // Call parent constructor
47 parent::__construct(__CLASS__);
51 * Creates an instance of this database wrapper by a provided user class
53 * @return $wrapperInstance An instance of the created wrapper class
55 public static final function createCityDistrictsDatabaseWrapper () {
57 $wrapperInstance = new CityDistrictsDatabaseWrapper();
59 // Set (primary!) table name
60 $wrapperInstance->setTableName(self::DB_TABLE_CITY_DISTRICTS);
62 // Return the instance
63 return $wrapperInstance;
67 * Checks if the given city id is found in districts table
69 * @param $cityId City id to check
70 * @return $isFound Whether the city id is found
72 public function ifCityHasDistricts ($cityId) {
73 // Get search instance
74 $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
76 // Search for 'city_id'
77 $searchInstance->addCriteria(self::DB_COLUMN_CITY_ID, $cityId);
80 * Only one entry is enough to find, else this query could run very
83 $searchInstance->setLimit(1);
85 // Execute it on database instance
86 $resultInstance = $this->doSelectByCriteria($searchInstance);
88 // Check if there is one entry
89 $isFound = $resultInstance->next();