Non geocoded addresses could not be saved.
[platal.git] / include / geocoding.inc.php
index 816afeb..fc812fa 100644 (file)
@@ -27,6 +27,9 @@ abstract class Geocoder {
     // Unknown key-value pairs available in the input map are retained as-is.
     abstract public function getGeocodedAddress(array $address);
 
+    // Cleans the address from its geocoded data
+    abstract public function stripGeocodingFromAddress(array $address);
+
     // Updates geoloc_administrativeareas, geoloc_subadministrativeareas and
     // geoloc_localities databases with new geocoded data and returns the
     // corresponding id.
@@ -52,6 +55,19 @@ abstract class Geocoder {
             }
         }
     }
+
+    // Returns the part of the text preceeding the line with the postal code
+    // and the city name, within the limit of $limit number of lines.
+    static public function getFirstLines($text, $postalCode, $limit)
+    {
+        $textArray  = explode("\n", $text);
+        for ($i = 0; $i < count($textArray); ++$i) {
+            if ($i > $limit || strpos($textLine, $postalCode) !== false) {
+                $limit = $i; break;
+            }
+        }
+        return implode("\n", array_slice($textArray, 0, $limit));
+    }
 }
 
 // Implementation of a Geocoder using the Google Maps API. Please refer to
@@ -94,6 +110,15 @@ class GMapsGeocoder extends Geocoder {
         return $address;
     }
 
+    public function stripGeocodingFromAddress(array $address) {
+        unset($address['geoloc'], $address['geoloc_choice'], $address['countryId'],
+              $address['country'], $address['administrativeAreaName'],
+              $address['subAdministrativeAreaName'], $address['localityName'],
+              $address['thoroughfareName'], $address['postalCode']);
+        $address['accuracy'] = 0;
+        return $address;
+    }
     // Updates the address with the geocoded information from Google Maps. Also
     // cleans up the final informations.
     private function getUpdatedAddress(array $address, array $geocodedData, $extraLines) {