3 namespace Org\Mxchange\City\Database\Frontend\Districts;
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Database\Frontend\BaseDatabaseFrontend;
7 use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory;
8 use Org\Mxchange\CoreFramework\Registry\Registerable;
11 * A database frontend 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 CityDistrictsDatabaseFrontend extends BaseDatabaseFrontend implements CityDistrictsFrontend, 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 frontend by a provided user class
53 * @return $frontendInstance An instance of the created frontend class
55 public static final function createCityDistrictsDatabaseFrontend () {
57 $frontendInstance = new CityDistrictsDatabaseFrontend();
59 // Set (primary!) table name
60 $frontendInstance->setTableName(self::DB_TABLE_CITY_DISTRICTS);
62 // Return the instance
63 return $frontendInstance;
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 (int $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();