]> git.mxchange.org Git - city.git/blob
b7722a603f5266bfaadadf8b57e28cd14348efbd
[city.git] /
1 <?php
2 // Own namespace
3 namespace Org\Mxchange\City\Database\Frontend\Districts;
4
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;
9
10 /**
11  * A database wrapper for city districts
12  *
13  * @author              Roland Haeder <webmaster@shipsimu.org>
14  * @version             0.0.0
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
18  *
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.
23  *
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.
28  *
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/>.
31  */
32 class CityDistrictsDatabaseWrapper extends BaseDatabaseWrapper implements CityDistrictsWrapper, Registerable {
33         // Constants for database table names
34         const DB_TABLE_CITY_DISTRICTS = 'city_districts';
35
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';
39
40         /**
41          * Protected constructor
42          *
43          * @return      void
44          */
45         protected function __construct () {
46                 // Call parent constructor
47                 parent::__construct(__CLASS__);
48         }
49
50         /**
51          * Creates an instance of this database wrapper by a provided user class
52          *
53          * @return      $wrapperInstance        An instance of the created wrapper class
54          */
55         public static final function createCityDistrictsDatabaseWrapper () {
56                 // Get a new instance
57                 $wrapperInstance = new CityDistrictsDatabaseWrapper();
58
59                 // Set (primary!) table name
60                 $wrapperInstance->setTableName(self::DB_TABLE_CITY_DISTRICTS);
61
62                 // Return the instance
63                 return $wrapperInstance;
64         }
65
66         /**
67          * Checks if the given city id is found in districts table
68          *
69          * @param       $cityId         City id to check
70          * @return      $isFound        Whether the city id is found
71          */
72         public function ifCityHasDistricts ($cityId) {
73                 // Get search instance
74                 $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
75
76                 // Search for 'city_id'
77                 $searchInstance->addCriteria(self::DB_COLUMN_CITY_ID, $cityId);
78
79                 /*
80                  * Only one entry is enough to find, else this query could run very
81                  * long on large maps.
82                  */
83                 $searchInstance->setLimit(1);
84
85                 // Execute it on database instance
86                 $resultInstance = $this->doSelectByCriteria($searchInstance);
87
88                 // Check if there is one entry
89                 $isFound = $resultInstance->next();
90
91                 // Return result
92                 return $isFound;
93         }
94 }