Changeset 683
- Timestamp:
- 08/10/05 17:13:57 (8 years ago)
- Location:
- trunk/wifidog-auth
- Files:
-
- 3 modified
-
ChangeLog (modified) (1 diff)
-
wifidog/classes/AbstractGeocoder.php (modified) (14 diffs)
-
wifidog/classes/Geocoders/GeocoderCanada.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wifidog-auth/ChangeLog
r682 r683 1 2005-07-25 Francois Proulx <francois.proulx@gmail.com> 1 2005-08-10 Francois Proulx <francois.proulx@gmail.com> 2 * More GIS stuff 3 4 2005-08-10 Francois Proulx <francois.proulx@gmail.com> 2 5 * Added Geocoders 3 6 * /classes/AbstractGeocoder.php -
trunk/wifidog-auth/wifidog/classes/AbstractGeocoder.php
r682 r683 1 1 <?php 2 3 2 /********************************************************************\ 4 3 * This program is free software; you can redistribute it and/or * … … 23 22 * @author Copyright (C) 2005 François Proulx <francois.proulx@gmail.com> 24 23 */ 25 24 26 25 require_once BASEPATH.'include/common.php'; 26 require_once BASEPATH.'classes/FormSelectGenerator.php'; 27 27 require_once BASEPATH.'classes/GenericObject.php'; 28 28 … … 38 38 private $country = ""; 39 39 private $postal_code = ""; 40 40 41 41 // Implementation attributes 42 42 private $endpoint_url; 43 43 // This value is only used to prevent from running to same query twice 44 private $execute_query = true; 45 44 private $execute_query = true; 45 46 46 // Factory method hash map 47 private static $implementations_map = array ("Canada" => "GeocoderCanada", "USA" => "GeocoderUsa");48 47 private static $implementations_map = array ("Canada" => "GeocoderCanada", "USA" => "GeocoderUsa"); 48 49 49 /** Returns a list of countries for which we provide a geocoder implementation 50 50 * @return array Array of string keys … … 52 52 public static function getAvailableCountriesList() 53 53 { 54 return array_keys(self ::$implementations_map);54 return array_keys(self :: $implementations_map); 55 55 } 56 56 57 /** Return a string containing HTML definition of a forms select box containing countries 58 * @return string 59 */ 60 public static function getAvailableCountriesFormSelect() 61 { 62 $array_tmp = array(); 63 foreach(self::$implementations_map as $key => $value) 64 $array_tmp[] = array($key, $key); 65 return FormSelectGenerator :: generateFromArray($array_tmp, null, "country", null, false); 66 } 67 57 68 /** Returns a list of available geocoders implementations 58 69 * @return array Array of string keys … … 60 71 public static function getAvailableGeocoderImplementations() 61 72 { 62 return array_values(self ::$implementations_map);73 return array_values(self :: $implementations_map); 63 74 } 64 75 65 76 /** Instanciates a new Geocoder implementation 66 77 * @param String $country_key The key corresponding to an entry given by getAvailableCountriesList … … 70 81 { 71 82 // Return the mapped implementation 72 if (!isset(self::$implementations_map[$country_key]))83 if (!isset (self :: $implementations_map[$country_key])) 73 84 return null; 74 $class_name = self ::$implementations_map[$country_key];85 $class_name = self :: $implementations_map[$country_key]; 75 86 return new $class_name; 76 87 } 77 88 78 89 public function getCivicNumber() 79 90 { 80 91 return $this->civic_number; 81 92 } 82 93 83 94 public function setCivicNumber($civic_number) 84 95 { … … 86 97 $this->civic_number = $civic_number; 87 98 } 88 99 89 100 public function getStreetName() 90 101 { 91 102 return $this->street_name; 92 103 } 93 104 94 105 public function setStreetName($street_name) 95 106 { … … 97 108 $this->street_name = $street_name; 98 109 } 99 110 100 111 public function getCity() 101 112 { 102 113 return $this->city; 103 114 } 104 115 105 116 public function setCity($city) 106 117 { … … 108 119 $this->city = $city; 109 120 } 110 121 111 122 public function getProvince() 112 123 { 113 124 return $this->province; 114 125 } 115 126 116 127 public function setProvince($province) 117 128 { … … 119 130 $this->province = $province; 120 131 } 121 132 122 133 public function getCountry() 123 134 { 124 135 return $this->country; 125 136 } 126 137 127 138 protected function setCountry($country) 128 139 { … … 130 141 $this->country = $country; 131 142 } 132 143 133 144 public function getPostalCode() 134 145 { 135 146 return $this->postal_code; 136 147 } 137 148 138 149 public function setPostalCode($postal_code) 139 150 { … … 141 152 $this->postal_code = $postal_code; 142 153 } 143 154 144 155 public function getEndpointUrl() 145 156 { 146 157 return $this->endpoint_url; 147 158 } 148 159 149 160 protected function setEndpointUrl($url) 150 161 { … … 152 163 $this->endpoint_url = $url; 153 164 } 154 165 155 166 protected function shouldExecuteQuery() 156 167 { 157 168 return $this->execute_query; 158 169 } 159 170 160 171 protected function trashResponse() 161 172 { 162 173 $this->execute_query = true; 163 174 } 164 175 165 176 protected function keepResponse() 166 177 { 167 178 $this->execute_query = false; 168 179 } 169 180 170 181 abstract public function validateAddress(); 171 182 abstract public function getLatitude(); … … 178 189 foreach ($class_names as $class_name) 179 190 require_once BASEPATH.'classes/Geocoders/'.$class_name.'.php'; 180 181 191 ?> -
trunk/wifidog-auth/wifidog/classes/Geocoders/GeocoderCanada.php
r682 r683 1 1 <?php 2 2 3 3 4 /********************************************************************\ … … 32 33 private $cached_latitude; 33 34 private $cached_longitude; 34 35 35 36 public function __construct() 36 37 { … … 47 48 return preg_match("/^[A-Z]\d[A-Z]\s?\d[A-Z]\d$/i", $this->getPostalCode()); 48 49 } 49 50 51 /** Validates province code 52 * @return boolean 53 */ 54 private function validateProvince() 55 { 56 return in_array($this->getProvince(), array ("AB", "BC", "MB", "NB", "NL", "NS", "NT", "NU", "ON", "PE", "QC", "SK", "YT")); 57 } 58 50 59 /** Validate address, making sure we don't send an HTTP for nothing 51 60 * @return boolean … … 54 63 { 55 64 // Make sure a city or a postal code has been entered 56 if (($this->getCivicNumber() || $this->getStreetName() == "" || $this->getCity() == "" || $this->getProvince() == "") && !$this->validatePostalCode())65 if (($this->getCivicNumber() == "" || $this->getStreetName() == "" || $this->getCity() == "" || !$this->validateProvince()) && !$this->validatePostalCode()) 57 66 return false; 58 67 return true; … … 75 84 { 76 85 // Don't send multiple queries when the input has not changed 77 if ($this->shouldExecuteQuery() == true)86 if ($this->shouldExecuteQuery() == true) 78 87 { 88 79 89 // Load the XML document 80 90 if (($dom = DOMDocument :: load($this->buildQuery())) !== false) 81 91 { 82 92 $xpath = new DOMXpath($dom); 83 93 84 94 // Skip if there was an error 85 if ($xpath->query("/geodata/error")->length >= 1)95 if ($xpath->query("/geodata/error")->length >= 1) 86 96 return false; 87 97 88 98 // Run XPath quries to extract data 89 99 $this->cached_latitude = $xpath->query("//geodata/latt")->item(0)->nodeValue; 90 100 $this->cached_longitude = $xpath->query("//geodata/longt")->item(0)->nodeValue; 91 101 92 102 // Prevent from sending multiple queries. 93 103 $this->keepResponse();
