+ /*
+ * "Cache" max "radius" for initial city expansion. It is not a real
+ * radius but more a max expansion area (expand +- half of "radius"
+ * from 0/0). The "zero point" is always calculated in.
+ *
+ * This gives a maxium initial area calculated as follows:
+ *
+ * totalInitialSections = (radius + 1) * (radius + 1)
+ */
+ $radius = $this->getConfigInstance()->getConfigEntry('city_max_initial_xy_expansion_radius');
+
+ // Max up and down ...
+ $maxUp = $this->getConfigInstance()->getConfigEntry('city_max_initial_up_expansion');
+ $maxDown = $this->getConfigInstance()->getConfigEntry('city_max_initial_down_expansion');
+
+ // Extremely huge debug message:
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: radius=' . $radius . ',maxUp=' . $maxUp . ',maxDown=' . $maxDown);
+
+ // Get data set instance
+ $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_CITY_SECTIONS));
+
+ // Add values for "zero point"
+ $dataSetInstance->addCriteria(self::DB_COLUMN_SECTION_ID , 1);
+ $dataSetInstance->addCriteria(self::DB_COLUMN_CITY_ID , $cityId);
+ $dataSetInstance->addCriteria(self::DB_COLUMN_LOT_ID , 0);
+ $dataSetInstance->addCriteria(self::DB_COLUMN_SECTION_TYPE , self::SECTION_TYPE_EMPTY_LAND);
+ $dataSetInstance->addCriteria(self::DB_COLUMN_SECTION_SUB_TYPE , self::SUB_SECTION_TYPE_EMPTY);
+ $dataSetInstance->addCriteria(self::DB_COLUMN_SECTION_POSITION_X , 0);
+ $dataSetInstance->addCriteria(self::DB_COLUMN_SECTION_POSITION_Y , 0);
+ $dataSetInstance->addCriteria(self::DB_COLUMN_SECTION_POSITION_Z , 0);
+ $dataSetInstance->addCriteria(self::DB_COLUMN_SECTION_NEIGHBOUR_NORTH_ID, 0);
+ $dataSetInstance->addCriteria(self::DB_COLUMN_SECTION_NEIGHBOUR_SOUTH_ID, 0);
+ $dataSetInstance->addCriteria(self::DB_COLUMN_SECTION_NEIGHBOUR_WEST_ID , 0);
+ $dataSetInstance->addCriteria(self::DB_COLUMN_SECTION_NEIGHBOUR_EAST_ID , 0);
+ $dataSetInstance->addCriteria(self::DB_COLUMN_SECTION_NEIGHBOUR_UP_ID , 0);
+ $dataSetInstance->addCriteria(self::DB_COLUMN_SECTION_NEIGHBOUR_DOWN_ID , 0);
+ $dataSetInstance->addCriteria(self::DB_COLUMN_SECTION_RESERVED , self::IS_NOT_RESERVED);
+
+ // Set primary key to 'city_id'/'section_id'
+ $dataSetInstance->setPrimaryKeyCombined(array(self::DB_COLUMN_CITY_ID, self::DB_COLUMN_SECTION_ID));
+
+ // Add "zero point"
+ $this->queryInsertDataSet($dataSetInstance);
+
+ // Set section id to 2 as 1 is already initialized + init array
+ $sections = array();
+
+ // Output message to ask for user's patience ...
+ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: Writing ' . (($radius + 1) * ($radius + 1) * $maxUp * ($maxDown + 1)) . ' sections for city ' . $cityId . ' ... (this may takes some time)');
+
+ // Expand half of it to north/south (north=positive, south=negative)
+ for ($north = 1; $north < round($radius / 2); $north++) {
+ // Expand half of it to west/east (west=positive, east=negative)
+ for ($west = 1; $west < round($radius / 2); $west++) {
+ // Expand up/down (including "zero point")
+ for ($z = $maxDown; $z < ($maxUp + 1); $z++) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: north=' . $north . ',west=' . $west . ',z=' . $z);
+
+ // Fill array up with south/east/down ids
+ $sections[($north * -1)][($west * -1)][$z]['type'] = self::SECTION_TYPE_EMPTY_LAND;
+ $sections[($north * -1)][($west * -1)][$z]['sub'] = self::SUB_SECTION_TYPE_EMPTY;
+
+ // Fill up array with north/west/up ids
+ $sections[$north][$west][$z]['type'] = self::SECTION_TYPE_EMPTY_LAND;
+ $sections[$north][$west][$z]['sub'] = self::SUB_SECTION_TYPE_EMPTY;
+ } // END - for
+ } // END - for
+ } // END - for
+
+ // Init section id with 2 as 1 is the "zero point"
+ $sectionId = 2;
+
+ // Loop through whole array again for writing it to database: north/south
+ foreach ($sections as $x => $sectionX) {
+ // Loop through west/east values
+ foreach ($sectionX as $y => $sectionY) {
+ // Loop through up/down values
+ foreach ($sectionY as $z => $sectionData) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: x=' . $x . ',y=' . $y . ',z=' . $z . ',sectionId=' . $sectionId);
+
+ // Set all coordinates for positive directions
+ $dataSetInstance->setCriteria(self::DB_COLUMN_SECTION_ID , $sectionId);
+ $dataSetInstance->setCriteria(self::DB_COLUMN_SECTION_POSITION_X, $x);
+ $dataSetInstance->setCriteria(self::DB_COLUMN_SECTION_POSITION_Y, $y);
+ $dataSetInstance->setCriteria(self::DB_COLUMN_SECTION_POSITION_Z, $z);
+ $dataSetInstance->setCriteria(self::DB_COLUMN_SECTION_TYPE , $sectionData['type']);
+ $dataSetInstance->setCriteria(self::DB_COLUMN_SECTION_SUB_TYPE , $sectionData['sub']);
+
+ // Add value to database
+ $this->queryInsertDataSet($dataSetInstance);
+
+ // Count id up
+ $sectionId++;
+ } // END - foreach
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: x=' . $x . ',y=' . $y . ' has been written.');
+ } // END - foreach
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: x=' . $x . ' has been written.');
+ } // END - foreach
+
+ // Thank you for waiting! :-)
+ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: ' . (($radius + 1) * ($radius + 1) * $maxUp * ($maxDown + 1)) . ' sections has been written for city ' . $cityId . '.');