Changeset 683

Show
Ignore:
Timestamp:
08/10/05 17:13:57 (8 years ago)
Author:
fproulx
Message:

2005-08-10 Francois Proulx <francois.proulx@…>

  • More GIS stuff
Location:
trunk/wifidog-auth
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/wifidog-auth/ChangeLog

    r682 r683  
    1 2005-07-25 Francois Proulx <francois.proulx@gmail.com> 
     12005-08-10 Francois Proulx <francois.proulx@gmail.com> 
     2        * More GIS stuff 
     3         
     42005-08-10 Francois Proulx <francois.proulx@gmail.com> 
    25        * Added Geocoders 
    36                * /classes/AbstractGeocoder.php 
  • trunk/wifidog-auth/wifidog/classes/AbstractGeocoder.php

    r682 r683  
    11<?php 
    2  
    32/********************************************************************\ 
    43 * This program is free software; you can redistribute it and/or    * 
     
    2322 * @author Copyright (C) 2005 François Proulx <francois.proulx@gmail.com> 
    2423 */ 
    25   
     24 
    2625require_once BASEPATH.'include/common.php'; 
     26require_once BASEPATH.'classes/FormSelectGenerator.php'; 
    2727require_once BASEPATH.'classes/GenericObject.php'; 
    2828 
     
    3838        private $country = ""; 
    3939        private $postal_code = ""; 
    40          
     40 
    4141        // Implementation attributes 
    4242        private $endpoint_url; 
    4343        // 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 
    4646        // 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 
    4949        /** Returns a list of countries for which we provide a geocoder implementation  
    5050         * @return array Array of string keys 
     
    5252        public static function getAvailableCountriesList() 
    5353        { 
    54                 return array_keys(self::$implementations_map); 
     54                return array_keys(self :: $implementations_map); 
    5555        } 
    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 
    5768        /** Returns a list of available geocoders implementations 
    5869         * @return array Array of string keys 
     
    6071        public static function getAvailableGeocoderImplementations() 
    6172        { 
    62                 return array_values(self::$implementations_map); 
     73                return array_values(self :: $implementations_map); 
    6374        } 
    64          
     75 
    6576        /** Instanciates a new Geocoder implementation 
    6677         * @param String $country_key The key corresponding to an entry given by getAvailableCountriesList 
     
    7081        { 
    7182                // Return the mapped implementation 
    72                 if(!isset(self::$implementations_map[$country_key])) 
     83                if (!isset (self :: $implementations_map[$country_key])) 
    7384                        return null; 
    74                 $class_name = self::$implementations_map[$country_key]; 
     85                $class_name = self :: $implementations_map[$country_key]; 
    7586                return new $class_name; 
    7687        } 
    77          
     88 
    7889        public function getCivicNumber() 
    7990        { 
    8091                return $this->civic_number; 
    8192        } 
    82          
     93 
    8394        public function setCivicNumber($civic_number) 
    8495        { 
     
    8697                $this->civic_number = $civic_number; 
    8798        } 
    88          
     99 
    89100        public function getStreetName() 
    90101        { 
    91102                return $this->street_name; 
    92103        } 
    93          
     104 
    94105        public function setStreetName($street_name) 
    95106        { 
     
    97108                $this->street_name = $street_name; 
    98109        } 
    99          
     110 
    100111        public function getCity() 
    101112        { 
    102113                return $this->city; 
    103114        } 
    104          
     115 
    105116        public function setCity($city) 
    106117        { 
     
    108119                $this->city = $city; 
    109120        } 
    110          
     121 
    111122        public function getProvince() 
    112123        { 
    113124                return $this->province; 
    114125        } 
    115          
     126 
    116127        public function setProvince($province) 
    117128        { 
     
    119130                $this->province = $province; 
    120131        } 
    121          
     132 
    122133        public function getCountry() 
    123134        { 
    124135                return $this->country; 
    125136        } 
    126          
     137 
    127138        protected function setCountry($country) 
    128139        { 
     
    130141                $this->country = $country; 
    131142        } 
    132          
     143 
    133144        public function getPostalCode() 
    134145        { 
    135146                return $this->postal_code; 
    136147        } 
    137          
     148 
    138149        public function setPostalCode($postal_code) 
    139150        { 
     
    141152                $this->postal_code = $postal_code; 
    142153        } 
    143          
     154 
    144155        public function getEndpointUrl() 
    145156        { 
    146157                return $this->endpoint_url; 
    147158        } 
    148          
     159 
    149160        protected function setEndpointUrl($url) 
    150161        { 
     
    152163                $this->endpoint_url = $url; 
    153164        } 
    154          
     165 
    155166        protected function shouldExecuteQuery() 
    156167        { 
    157168                return $this->execute_query; 
    158169        } 
    159          
     170 
    160171        protected function trashResponse() 
    161172        { 
    162173                $this->execute_query = true; 
    163174        } 
    164          
     175 
    165176        protected function keepResponse() 
    166177        { 
    167178                $this->execute_query = false; 
    168179        } 
    169          
     180 
    170181        abstract public function validateAddress(); 
    171182        abstract public function getLatitude(); 
     
    178189foreach ($class_names as $class_name) 
    179190        require_once BASEPATH.'classes/Geocoders/'.$class_name.'.php'; 
    180  
    181191?> 
  • trunk/wifidog-auth/wifidog/classes/Geocoders/GeocoderCanada.php

    r682 r683  
    11<?php 
     2 
    23 
    34/********************************************************************\ 
     
    3233        private $cached_latitude; 
    3334        private $cached_longitude; 
    34          
     35 
    3536        public function __construct() 
    3637        { 
     
    4748                return preg_match("/^[A-Z]\d[A-Z]\s?\d[A-Z]\d$/i", $this->getPostalCode()); 
    4849        } 
    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 
    5059        /** Validate address, making sure we don't send an HTTP for nothing 
    5160         * @return boolean  
     
    5463        { 
    5564                // 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()) 
    5766                        return false; 
    5867                return true; 
     
    7584        { 
    7685                // Don't send multiple queries when the input has not changed 
    77                 if($this->shouldExecuteQuery() == true) 
     86                if ($this->shouldExecuteQuery() == true) 
    7887                { 
     88                         
    7989                        // Load the XML document 
    8090                        if (($dom = DOMDocument :: load($this->buildQuery())) !== false) 
    8191                        { 
    8292                                $xpath = new DOMXpath($dom); 
    83                                  
     93 
    8494                                // Skip if there was an error 
    85                                 if($xpath->query("/geodata/error")->length >= 1) 
     95                                if ($xpath->query("/geodata/error")->length >= 1) 
    8696                                        return false; 
    87                          
     97 
    8898                                // Run XPath quries to extract data              
    8999                                $this->cached_latitude = $xpath->query("//geodata/latt")->item(0)->nodeValue; 
    90100                                $this->cached_longitude = $xpath->query("//geodata/longt")->item(0)->nodeValue; 
    91                                  
     101 
    92102                                // Prevent from sending multiple queries. 
    93103                                $this->keepResponse();