]> git.mxchange.org Git - city.git/blobdiff - application/city/main/manager/city/class_CityManager.php
Added region database handling and creation (partly finished).
[city.git] / application / city / main / manager / city / class_CityManager.php
index 97abac722ca4f8cd90a31f11ac2dda7290daada3..11d1245fcb03a0d0703e8cb39460f2614bd85c81 100644 (file)
@@ -77,6 +77,42 @@ class CityManager extends BaseManager implements ManageableCity {
                // Return result
                return $isTaken;
        }
+
+       /**
+        * Founds the first city. A dummy region will also be created
+        *
+        * @return      void
+        */
+       public function foundFirstCity () {
+               // Check on request instance and 'city_name' element
+               assert($this->getRequestInstance() instanceof Requestable);
+               assert($this->getRequestInstance()->isRequestElementSet(CityInformationDatabaseWrapper::DB_COLUMN_CITY_NAME));
+
+               // Get city name
+               $cityName = $this->getRequestInstance()->getRequestElement(CityInformationDatabaseWrapper::DB_COLUMN_CITY_NAME);
+
+               // Some pre-checks
+               assert(!$this->isCityAlreadyFounded());
+               assert(!$this->ifCityNameExists($cityName));
+
+               // Get region manager
+               $managerInstance = ManagerFactory::createManagerByType('region');
+
+               // There should be no region created
+               assert(!$managerInstance->ifUserHasCreatedRegion());
+
+               // Create first region and get back whole result
+               $regionResultInstance = $managerInstance->createFirstRegion();
+
+               // Get current entry
+               $regionData = $regionResultInstance->current();
+
+               // Add region id from it
+               $this->getRequestInstance()->setRequestElement(CityInformationDatabaseWrapper::DB_COLUMN_CITY_REGION_ID, $regionData[RegionInformationDatabaseWrapper::DB_COLUMN_REGION_ID]);
+
+               // Then create the first city
+               $this->getWrapperInstance()->createCityByRequest($this->getRequestInstance());
+       }
 }
 
 // [EOF]