Example #1
0
 /**
  * Get the regions in the locations database.
  * If $country is not specified, it will return all regions for all countries
  * @since Version 3.0
  * @param string $country An optional two letter country code we want to search for
  * @return array
  */
 public function getRegions($country = false)
 {
     if (RP_DEBUG) {
         global $site_debug;
         $debug_timer_start = microtime(true);
     }
     $return = false;
     $mckey = $country ? "railpage:locations.regions.country=" . $country : "railpage:locations.regions";
     #deleteMemcacheObject($mckey);
     if ($return = getMemcacheObject($mckey)) {
         // Do nothing
     } else {
         $return = array();
         if ($country) {
             foreach ($this->db->fetchAll("SELECT DISTINCT region FROM location WHERE country = ? AND active = 1 ORDER BY region ASC", $country) as $row) {
                 $woe = getWOEData($country);
                 if (isset($woe['places']['place'][0])) {
                     $return[$country]['woe'] = $woe['places']['place'][0];
                 }
                 $datarow = array("region" => $row['region'], "url" => $this->makeRegionPermalink($country, $row['region']), "count" => $this->db->fetchOne("SELECT COUNT(id) FROM location WHERE country = ? AND region = ?", array($country, $row['region'])));
                 $woe = getWOEData($row['region'] . "," . $country);
                 if (isset($woe['places']['place'][0])) {
                     $datarow['woe'] = $woe['places']['place'][0];
                 }
                 $return[$country]['children'][] = $datarow;
             }
         } else {
             foreach ($this->db->fetchAll("SELECT DISTINCT region, country FROM location WHERE country IN (SELECT DISTINCT country FROM location ORDER BY country) AND active = 1 ORDER BY region desc") as $row) {
                 if (!empty($row['country'])) {
                     $woe = getWOEData(strtoupper($row['region']));
                     if (isset($woe['places']['place'][0])) {
                         $return[$row['country']]['woe'] = $woe['places']['place'][0];
                     }
                     $return[$row['country']]['children'][] = $row['region'];
                 }
             }
         }
         // Cache it
         setMemcacheObject($mckey, $return, strtotime("+1 day"));
     }
     if (RP_DEBUG) {
         $site_debug[] = "Zend_DB: SUCCESS select all locations regions in " . round(microtime(true) - $debug_timer_start, 5) . "s";
     }
     return $return;
 }
Example #2
0
 /**
  * Get regions within this country
  * @return array
  * @param string $country Kept in for backwards compatibility with parent::getRegions()
  */
 public function getRegions($country = false)
 {
     $query = "SELECT COUNT(id) AS count, region AS name, region_slug AS slug FROM location WHERE country = ? GROUP BY region ORDER BY region ASC";
     $regions = array();
     foreach ($this->db->fetchAll($query, $this->code) as $row) {
         if (empty($row['slug'])) {
             $data = array("region_slug" => $this->makeRegionSlug($row['name']));
             $where = array("region = ?" => $row['name'], "country = ?" => $this->code);
             $this->db->update("location", $data, $where);
             $row['slug'] = $this->makeRegionSlug($row['name']);
         }
         $row['url'] = $this->url . "/" . $row['slug'];
         /**
          * Get WOE data for this region
          */
         $woe = getWOEData($row['name'] . "," . $this->code);
         $shortname = $row['name'];
         if (isset($woe['places']['place'][0]['name'])) {
             $row['name'] = $woe['places']['place'][0]['name'];
         }
         if (!empty($this->timezone)) {
             $row['timezone'] = $this->timezone;
         }
         if (isset($woe['places']['place'][0]['timezone'])) {
             $row['timezone'] = $woe['places']['place'][0]['timezone'];
         }
         $row['glyph'] = strtolower(sprintf("map-%s", $this->code));
         /**
          * Assign a map glyph
          */
         switch (strtolower($this->code)) {
             case "au":
                 $row['glyph'] = strtolower(sprintf("map-%s-%s", $this->code, str_replace(array("ACT", "NSW", "QLD", "TAS", "VIC"), array("AC", "NW", "QL", "TS", "VC"), strtoupper($shortname))));
                 break;
             case "gb":
                 $row['glyph'] = "map-uk";
                 break;
             case "us":
                 $find = array("alaska", "alabama", "arizona", "arkansas", "california", "colorado", "Connecticut", "delaware", "district of columbia", "florida", "georgia", "hawaii", "idaho", "illinois", "indiana", "iowa", "kansas", "kentucky", "louisiana", "maine", "maryland", "massachusetts", "michigan", "minnesota", "mississippi", "missouri", "montana", "nebraska", "nevada", "new hampshire", "new jersey", "new mexico", "new york", "north carolina", "north dakota", "ohio", "oklahoma", "oregon", "pennsylvania", "rhode island", "south carolina", "south dakota", "tennessee", "texas", "utah", "vermont", "virginia", "washington", "west virginia", "wisconsin", "wyoming");
                 $replace = array("ak", "al", "az", "ar", "ca", "co", "ct", "de", "dc", "fl", "ga", "hi", "id", "il", "in", "ia", "ks", "ky", "la", "me", "md", "ma", "mi", "mn", "ms", "mo", "mt", "ne", "nv", "nh", "nj", "nm", "ny", "nc", "nd", "oh", "ok", "or", "pa", "ri", "sc", "sd", "tn", "tx", "ut", "vt", "va", "wa", "wv", "wi", "wy");
                 $row['glyph'] = strtolower(sprintf("map-%s-%s", $this->code, str_ireplace($find, $replace, $shortname)));
                 break;
         }
         $regions[] = $row;
     }
     return $regions;
 }