]> git.mxchange.org Git - city.git/blob - application/city/classes/database/frontend/city_entities/lots/class_CityLotsDatabaseWrapper.php
Continued:
[city.git] / application / city / classes / database / frontend / city_entities / lots / class_CityLotsDatabaseWrapper.php
1 <?php
2 // Own namespace
3 namespace Org\Mxchange\City\Database\Frontend\Lots;
4
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
7
8 /**
9  * A database wrapper for city lots
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 CityLotsDatabaseWrapper extends BaseDatabaseWrapper implements CityLotsWrapper, Registerable {
31         // Constants for database table names
32         const DB_TABLE_CITY_LOTS = 'city_lots';
33
34         // Section id, an referenced city id and lot id
35         const DB_COLUMN_CITY_ID                = 'city_id';
36         const DB_COLUMN_LOT_ID                 = 'lot_id';
37         const DB_COLUMN_DISTRICT_ID            = 'district_id';
38
39         /**
40          * Protected constructor
41          *
42          * @return      void
43          */
44         protected function __construct () {
45                 // Call parent constructor
46                 parent::__construct(__CLASS__);
47         }
48
49         /**
50          * Creates an instance of this database wrapper by a provided user class
51          *
52          * @return      $wrapperInstance        An instance of the created wrapper class
53          */
54         public static final function createCityLotsDatabaseWrapper () {
55                 // Get a new instance
56                 $wrapperInstance = new CityLotsDatabaseWrapper();
57
58                 // Set (primary!) table name
59                 $wrapperInstance->setTableName(self::DB_TABLE_CITY_LOTS);
60
61                 // Return the instance
62                 return $wrapperInstance;
63         }
64
65         /**
66          * Checks if the given city id is found in lots table
67          *
68          * @param       $cityId         City id to check
69          * @return      $isFound        Whether the city id is found
70          */
71         public function ifCityHasLots ($cityId) {
72                 // Get search instance
73                 $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
74
75                 // Search for 'city_id'
76                 $searchInstance->addCriteria(self::DB_COLUMN_CITY_ID, $cityId);
77
78                 /*
79                  * Only one entry is enough to find, else this query could run very
80                  * long on large maps.
81                  */
82                 $searchInstance->setLimit(1);
83
84                 // Execute it on database instance
85                 $resultInstance = $this->doSelectByCriteria($searchInstance);
86
87                 // Check if there is one entry
88                 $isFound = $resultInstance->next();
89
90                 // Return result
91                 return $isFound;
92         }
93 }