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