<?php
+// Own namespace
+namespace Org\Mxchange\City\Database\Frontend\Sections;
+
+// Import framework stuff
+use Org\Mxchange\CoreFramework\Database\Frontend\BaseDatabaseWrapper;
+use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
+use Org\Mxchange\CoreFramework\Registry\Registerable;
+
/**
* A database wrapper for city sections. Sections are the smalles entity of a
* city. They can be connected with each other and form a lot. Therefore only
*
* @author Roland Haeder <webmaster@shipsimu.org>
* @version 0.0.0
- * @copyright Copyright (c) 2015 City Developer Team
+ * @copyright Copyright (c) 2015, 2016 City Developer Team
* @license GNU GPL 3.0 or any newer version
* @link http://www.shipsimu.org
*
// Constants for database table names
const DB_TABLE_CITY_SECTIONS = 'city_sections';
+ // Entry id
+ const DB_COLUMN_ENTRY_ID = 'entry_id';
+
// Section id, an referenced city id and lot id
const DB_COLUMN_SECTION_ID = 'city_section_id';
const DB_COLUMN_CITY_ID = 'city_id';
// @TODO "water" is not yet supported and may end up in a very random land.
const SECTION_TYPE_WATER = 'water';
const SECTION_TYPE_EMPTY_LAND = 'land';
+ const SECTION_TYPE_AIR = 'air';
// Sub sections
// @TODO All types of water are not supported yet.
const SECTION_SUB_TYPE_GRASS = 'grass';
+ const SECTION_SUB_TYPE_AIR = 'air';
// Reserved flag
const IS_NOT_RESERVED = 0;
$resultInstance = $this->doSelectByCriteria($searchInstance);
// Check if there is one entry
- $isFound = ($resultInstance->next() == 1);
+ $isFound = $resultInstance->next();
// Return result
return $isFound;
$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);
+ // Calculate total sections
+ $totalSections = (($radius + 1) * ($radius + 1) * $maxUp * ($maxDown + 1));
+
+ // Debug message:
+ /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: radius=' . $radius . ',maxUp=' . $maxUp . ',maxDown=' . $maxDown . ',totalSections=' . $totalSections);
// Get data set instance
$dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_CITY_SECTIONS));
$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::SECTION_SUB_TYPE_GRASS);
+ $dataSetInstance->addCriteria(self::DB_COLUMN_SECTION_TYPE , self::SECTION_TYPE_AIR);
+ $dataSetInstance->addCriteria(self::DB_COLUMN_SECTION_SUB_TYPE , self::SECTION_SUB_TYPE_AIR);
$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);
// Set primary key to 'city_id'/'section_id'
$dataSetInstance->setPrimaryKeyCombined(array(self::DB_COLUMN_CITY_ID, self::DB_COLUMN_SECTION_ID));
+ // Entry id for counting each entry
+ $dataSetInstance->setUniqueKey(self::DB_COLUMN_ENTRY_ID);
+
// Add "zero point"
$this->queryInsertDataSet($dataSetInstance);
$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)');
+ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: Writing ' . $totalSections . ' 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++) {
$sections[($north * -1)][($west * -1)][$z]['type'] = self::SECTION_TYPE_EMPTY_LAND;
$sections[($north * -1)][($west * -1)][$z]['sub'] = self::SECTION_SUB_TYPE_GRASS;
- // Fill up array with north/west/up ids
- $sections[$north][$west][$z]['type'] = self::SECTION_TYPE_EMPTY_LAND;
- $sections[$north][$west][$z]['sub'] = self::SECTION_SUB_TYPE_GRASS;
+ // Fill up array with north/west/up ids (only air)
+ $sections[$north][$west][$z]['type'] = self::SECTION_TYPE_AIR;
+ $sections[$north][$west][$z]['sub'] = self::SECTION_SUB_TYPE_AIR;
} // END - for
} // END - for
} // END - for
} // 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 . '.');
+ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: A total of ' . $totalSections . ' sections has been written for city id ' . $cityId . '.');
}
}
-
-// [EOF]
-?>