Stores more geocoding information in addresses.
authorStéphane Jacob <sj@m4x.org>
Fri, 13 May 2011 08:13:52 +0000 (10:13 +0200)
committerStéphane Jacob <sj@m4x.org>
Fri, 13 May 2011 12:01:35 +0000 (14:01 +0200)
Signed-off-by: Stéphane Jacob <sj@m4x.org>
classes/address.php
classes/gmapsgeocoder.php
templates/geoloc/form.address.tpl
upgrade/1.1.2/01_geocoding.sql

index 65ae7a2..7bea442 100644 (file)
@@ -311,6 +311,8 @@ class Address
     public $partial_match = false;
     public $componentsIds = '';
     public $request = false;
+    public $geocoding_date = null;
+    public $geocoding_calls = 0;
 
     // Database's field required for both 'home' and 'job' addresses.
     public $pub = 'ax';
@@ -614,6 +616,8 @@ class Address
             'location_type'       => $this->location_type,
             'partial_match'       => $this->partial_match,
             'componentsIds'       => $this->componentsIds,
+            'geocoding_date'      => $this->geocoding_date,
+            'geocoding_calls'     => $this->geocoding_calls,
             'request'             => $this->request
         );
 
@@ -682,12 +686,13 @@ class Address
         if (!$this->isEmpty()) {
             XDB::execute('INSERT IGNORE INTO  profile_addresses (pid, jobid, groupid, type, id, flags, text, postalText, pub, comment,
                                                                  types, formatted_address, location_type, partial_match, latitude, longitude,
-                                                                 southwest_latitude, southwest_longitude, northeast_latitude, northeast_longitude)
+                                                                 southwest_latitude, southwest_longitude, northeast_latitude, northeast_longitude,
+                                                                 geocoding_date, geocoding_calls)
                                       VALUES  ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?},
-                                               {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})',
+                                               {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, NOW(), {?})',
                          $this->pid, $this->jobid, $this->groupid, $this->type, $this->id, $this->flags, $this->text, $this->postalText, $this->pub, $this->comment,
                          $this->types, $this->formatted_address, $this->location_type, $this->partial_match, $this->latitude, $this->longitude,
-                         $this->southwest_latitude, $this->southwest_longitude, $this->northeast_latitude, $this->northeast_longitude);
+                         $this->southwest_latitude, $this->southwest_longitude, $this->northeast_latitude, $this->northeast_longitude, $this->geocoding_calls);
 
             if ($this->componentsIds) {
                 foreach (explode(',', $this->componentsIds) as $component_id) {
@@ -721,12 +726,13 @@ class Address
             XDB::execute('UPDATE  profile_addresses
                              SET  text = {?}, postalText = {?}, types = {?}, formatted_address = {?},
                                   location_type = {?}, partial_match = {?}, latitude = {?}, longitude = {?},
-                                  southwest_latitude = {?}, southwest_longitude = {?}, northeast_latitude = {?}, northeast_longitude = {?}
+                                  southwest_latitude = {?}, southwest_longitude = {?}, northeast_latitude = {?}, northeast_longitude = {?},
+                                  geocoding_date = {?}, geocoding_calls = NOW()
                            WHERE  pid = {?} AND jobid = {?} AND groupid = {?} AND type = {?} AND id = {?}',
                          $this->text, $this->postalText, $this->types, $this->formatted_address,
                          $this->location_type, $this->partial_match, $this->latitude, $this->longitude,
                          $this->southwest_latitude, $this->southwest_longitude, $this->northeast_latitude, $this->northeast_longitude,
-                         $this->pid, $this->jobid, $this->groupid, $this->type, $id);
+                         $this->pid, $this->jobid, $this->groupid, $this->type, $id, $this->geocoding_calls);
 
             XDB::execute('DELETE FROM  profile_addresses_components
                                 WHERE  pid = {?} AND jobid = {?} AND groupid = {?} AND type = {?} AND id = {?}',
@@ -901,6 +907,7 @@ class AddressIterator implements PlIterator
         $sql = 'SELECT  pa.pid, pa.jobid, pa.groupid, pa.type, pa.id, pa.flags, pa.text, pa.postalText, pa.pub, pa.comment,
                         pa.types, pa.formatted_address, pa.location_type, pa.partial_match, pa.latitude, pa.longitude,
                         pa.southwest_latitude, pa.southwest_longitude, pa.northeast_latitude, pa.northeast_longitude,
+                        pa.geocoding_date, pa.geocoding_calls,
                         GROUP_CONCAT(DISTINCT pc.component_id SEPARATOR \',\') AS componentsIds,
                         pace1.long_name AS postalCode, pace2.long_name AS locality, pace3.long_name AS administrativeArea, pace4.long_name AS country
                   FROM  profile_addresses                 AS pa
index 9378c1b..5321c72 100644 (file)
@@ -38,6 +38,7 @@ class GMapsGeocoder extends Geocoder {
         }
 
         // Try to geocode the full address.
+        $address->geocoding_calls = 1;
         if (($geocodedData = $this->getPlacemarkForAddress($textAddress, $defaultLanguage))) {
             $this->getUpdatedAddress($address, $geocodedData, null, $forceLanguage);
             return;
@@ -52,6 +53,7 @@ class GMapsGeocoder extends Geocoder {
         for ($i = max(1, $linesCount - self::MAX_GMAPS_RPC_CALLS + 1); $i < $linesCount; ++$i) {
             $extraLines = implode("\n", array_slice($addressLines, 0, $i));
             $toGeocode  = implode("\n", array_slice($addressLines, $i));
+            ++$address->geocoding_calls;
             if (($geocodedData = $this->getPlacemarkForAddress($toGeocode, $defaultLanguage))) {
                 $this->getUpdatedAddress($address, $geocodedData, $extraLines, $forceLanguage);
                 return;
index e419512..33c32a5 100644 (file)
@@ -41,6 +41,8 @@
     <input type="hidden" name="{$prefname}[componentsIds]" value="{$address.componentsIds}" />
     <input type="hidden" name="{$prefname}[changed]" value="0" />
     <input type="hidden" name="{$prefname}[removed]" value="0" />
+    <input type="hidden" name="{$prefname}[geocoding_calls]" value="{$address.geocoding_calls}" />
+    <input type="hidden" name="{$prefname}[geocoding_date]" value="{$address.geocoding_date}" />
 {if t($validation)}
     <br />
     <label><input type="checkbox" name="{$prefname}[modified]"{if $valid->modified} checked="checked"{/if} />Utiliser la version modifiée</label>
index b89083d..051ff08 100644 (file)
@@ -48,6 +48,8 @@ ALTER TABLE profile_addresses ADD COLUMN northeast_latitude FLOAT(10, 7) DEFAULT
 ALTER TABLE profile_addresses ADD COLUMN northeast_longitude FLOAT(10, 7) DEFAULT NULL AFTER northeast_latitude;
 ALTER TABLE profile_addresses ADD COLUMN location_type ENUM('ROOFTOP', 'RANGE_INTERPOLATED', 'GEOMETRIC_CENTER', 'APPROXIMATE') DEFAULT NULL AFTER northeast_longitude;
 ALTER TABLE profile_addresses ADD COLUMN partial_match BOOLEAN NOT NULL DEFAULT false AFTER location_type;
+ALTER TABLE profile_addresses ADD COLUMN geocoding_date DATE DEFAULT NULL;
+ALTER TABLE profile_addresses ADD COLUMN geocoding_calls TINYINT NOT NULL DEFAULT 0;
 
 UPDATE  profile_addresses
    SET  latitude = NULL, longitude = NULL;