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