/** * Constructor * * @param string $code */ public function __construct($code) { parent::__construct(); $this->code = $code; $this->url = new Url("/locations/" . strtolower($this->code)); $countries = ISO_3166::get_countries(); if (strlen($this->code) == 2) { $this->name = $countries[$code]['name']; } else { foreach ($countries as $cc => $data) { if (strtolower($data['name']) == strtolower($this->code)) { $this->code = $cc; $this->url = new Url("/locations/" . strtolower($this->code)); $this->name = $data['name']; } } } Debug::RecordInstance(); $timer = Debug::GetTimer(); if (!$this->loadFromCache() || empty($this->name)) { $woe = Place::getWOEData(strtoupper($code)); if (isset($woe['places']['place'][0]['name'])) { $woe = $woe['places']['place'][0]; $data = ["point" => new Zend_Db_Expr(sprintf("GeomFromText('POINT(%s %s)')", $woe['centroid']['latitude'], $woe['centroid']['longitude'])), "bb_southwest" => new Zend_Db_Expr(sprintf("GeomFromText('POINT(%s %s)')", $woe['boundingBox']['southWest']['latitude'], $woe['boundingBox']['southWest']['longitude'])), "bb_northeast" => new Zend_Db_Expr(sprintf("GeomFromText('POINT(%s %s)')", $woe['boundingBox']['northEast']['latitude'], $woe['boundingBox']['northEast']['longitude'])), "country_code" => $woe['country attrs']['code'], "country_name" => $woe['name'], "timezone" => isset($woe['timezone']) ? $woe['timezone'] : ""]; $this->db->insert("geoplace", $data); $this->name = $woe['name']; $this->centre = new stdClass(); $this->centre->lat = $woe['centroid']['latitude']; $this->centre->lon = $woe['centroid']['longitude']; $this->boundingBox = new stdClass(); $this->boundingBox->northEast = new stdClass(); $this->boundingBox->northEast->lat = $woe['boundingBox']['northEast']['latitude']; $this->boundingBox->northEast->lon = $woe['boundingBox']['northEast']['longitude']; $this->boundingBox->southWest = new stdClass(); $this->boundingBox->southWest->lat = $woe['boundingBox']['southWest']['latitude']; $this->boundingBox->southWest->lon = $woe['boundingBox']['southWest']['longitude']; } } /** * Fetch the WOE (Where On Earth) data from Yahoo */ Debug::LogEvent(__METHOD__, $timer); }
/** * Populate this object * @since Version 3.9.1 * * @param string $country * @param string $region * * @return void */ private function load($country, $region) { if (filter_var($country, FILTER_VALIDATE_INT)) { // We're looking up a WoE ID $woe = $this->fetchWoE($country, $region); $country = $woe['country attrs']['code']; $region = str_replace($country . "-", "", $woe['admin1 attrs']['code']); $this->Country = Factory::CreateCountry($country); } /* $query = "SELECT DISTINCT country_name, region_name FROM geoplace WHERE country_code = ? AND region_code = ?"; $result = $this->db->fetchRow($query, array( strtoupper($country), strtoupper($region) )); list ( $country_name, $region_name ) = $result; */ /** * Fetch the WOE (Where On Earth) data from Yahoo */ if (!isset($woe)) { $this->Country = Factory::CreateCountry($country); $woe = $this->fetchWoE($this->Country->code, $region); } //if (empty($this->Country->name) && !preg_match("@[a-zA-Z]+@", $country) && isset($woe['country'])) { // $this->Country = Factory::CreateCountry($woe['country']); //} #$regions = ISO_3166::regions_by_country($country); $this->code = strtoupper($region); $this->name = ISO_3166::getRegionName($this->Country->code, $region); $this->url = new Url(sprintf("%s/%s", $this->Country->url, $this->slug)); $this->centre = new stdClass(); $this->centre->lat = $woe['centroid']['latitude']; $this->centre->lon = $woe['centroid']['longitude']; $this->boundingBox = new stdClass(); $this->boundingBox->northEast = new stdClass(); $this->boundingBox->northEast->lat = $woe['boundingBox']['northEast']['latitude']; $this->boundingBox->northEast->lon = $woe['boundingBox']['northEast']['longitude']; $this->boundingBox->southWest = new stdClass(); $this->boundingBox->southWest->lat = $woe['boundingBox']['southWest']['latitude']; $this->boundingBox->southWest->lon = $woe['boundingBox']['southWest']['longitude']; if (isset($woe['timezone'])) { $this->timezone = $woe['timezone']; } if (empty($this->name)) { $this->name = ucwords(strtolower(str_replace("-", " ", $this->code))); } }