/**
  * Standard SS function
  * Creating level of detail
  * Note that the _GET variable "geobuild" needs to be turned on.
  **/
 public function requireDefaultRecords()
 {
     parent::requireDefaultRecords();
     $bt = defined('DB::USE_ANSI_SQL') ? "\"" : "`";
     $parents = DataObject::get("BrowseWorldPage");
     if ($parents && isset($_GET["geobuild"]) && $_GET["geobuild"]) {
         foreach ($parents as $parent) {
             if ($parent->CreateChildren) {
                 echo "<li>creating continents for " . $parent->Title . "<ul>";
                 $continents = $this->getDataFromTable("continents", null, "Continent");
                 foreach ($continents as $continent) {
                     if (!DataObject::get("BrowseContinentsPage", "{$bt}BrowseAbstractPage{$bt}.{$bt}HiddenDataID{$bt} = " . $continent["ContinentID"])) {
                         $page = new BrowseContinentsPage();
                         $page->CreateContinent($continent, $parent);
                         $page->destroy();
                     }
                 }
                 echo "</ul></li>";
             }
         }
     }
 }
    /**
     * This static method creates a city page and all the required parent pages...
     *@param Int - $CityID: the ID for the city to create
     **/
    public static function create_city_and_parents($CityID)
    {
        $cityPage = null;
        //check if the city exists at all
        $sql = '
			SELECT cities.RegionID, regions.CountryID, countries.ContinentID From cities, regions, countries, continents
			WHERE
				cities.RegionID = regions.RegionID AND
				regions.CountryID = countries.CountryID AND
				countries.ContinentID = continents.ContinentID AND
				cities.CityID = ' . $CityID . '
			LIMIT 1;';
        $result = DB::query($sql);
        foreach ($result as $row) {
            break;
        }
        $abstractHelpPage = new BrowseAbstractPage();
        if ($row) {
            //1 check if world exists
            if ($worldPage = DataObject::get_one("BrowseWorldPage")) {
                //do nothing
            } else {
                $worldPage = new BrowseWorldPage();
                $name = "Find";
                $worldPage->Title = $name;
                $worldPage->MetaTitle = $name;
                $worldPage->MenuTitle = $name;
                $worldPage->writeToStage('Stage');
                $worldPage->publish('Stage', 'Live');
                $worldPage->flushCache();
            }
            //2 check if continent exists
            $ContinentID = $row["ContinentID"];
            if ($continentPage = DataObject::get_one("BrowseContinentsPage", 'HiddenDataID = ' . $ContinentID)) {
                //debug::show("continent exists");
            } else {
                //create continent
                $continents = $abstractHelpPage->getDataFromTable("continents", "ContinentID = " . $ContinentID, null);
                foreach ($continents as $continentData) {
                    $continentPage = new BrowseContinentsPage();
                    $continentPage->CreateContinent($continentData, $worldPage);
                }
            }
            //3 check if country exists
            $CountryID = $row["CountryID"];
            if ($countryPage = DataObject::get_one("BrowseCountriesPage", 'HiddenDataID = ' . $CountryID)) {
                //debug::show("country exists");
            } else {
                //create Country
                $countries = $abstractHelpPage->getDataFromTable("countries", "CountryID = " . $CountryID, null);
                foreach ($countries as $countryData) {
                    $countryPage = new BrowseCountriesPage();
                    $countryPage->CreateCountry($countryData, $continentPage);
                }
            }
            //4 check if region exists
            $RegionID = $row["RegionID"];
            if ($regionPage = DataObject::get_one("BrowseRegionsPage", 'HiddenDataID = ' . $RegionID)) {
                //debug::show("region exists");
            } else {
                //create region
                $regions = $abstractHelpPage->getDataFromTable("regions", "RegionID = " . $RegionID, null);
                foreach ($regions as $regionData) {
                    $regionPage = new BrowseRegionsPage();
                    $regionPage->CreateRegion($regionData, $countryPage);
                }
            }
            if ($cityPage = DataObject::get_one("BrowseCitiesPage", 'HiddenDataID = ' . $CityID)) {
                //debug::show("city exists");
            } else {
                //create region
                $cities = $abstractHelpPage->getDataFromTable("cities", "CityID = " . $CityID, null);
                foreach ($cities as $city) {
                    $cityPage = new BrowseCitiesPage();
                    $cityPage->CreateCity($city, $regionPage);
                }
            }
        }
        return $cityPage;
    }