- // Returns the address formated for postal use.
- // The main rules are (cf AFNOR XPZ 10-011):
- // -everything in upper case;
- // -if there are more then than 38 characters in a line, split it;
- // -if there are more then than 32 characters in the description of the "street", use abbreviations.
- private function getPostalAddress($text) {
- static $abbreviations = array(
- 'IMPASSE' => 'IMP',
- 'RUE' => 'R',
- 'AVENUE' => 'AV',
- 'BOULEVARD' => 'BVD',
- 'ROUTE' => 'R',
- 'STREET' => 'ST',
- 'ROAD' => 'RD',
- );
-
- $text = strtoupper($text);
- $arrayText = explode("\n", $text);
- $postalText = '';
-
- foreach ($arrayText as $i => $line) {
- $postalText .= (($i == 0) ? '' : "\n");
- if (($length = strlen($line)) > 32) {
- $words = explode(' ', $line);
- $count = 0;
- foreach ($words as $word) {
- if (isset($abbreviations[$word])) {
- $word = $abbreviations[$word];
+ // Formats the text of the geocoded address using the unused data and
+ // compares it to the given address. If they are too different, the user
+ // will be asked to choose between them.
+ private function formatAddress(Address $address, $extraLines, $forceLanguage)
+ {
+ if ($extraLines) {
+ $address->geocodedText = $extraLines . "\n" . $address->geocodedText;
+ }
+
+ if ($this->compareAddress($address)) {
+ $address->geocodedText = null;
+ } elseif (!$forceLanguage) {
+ $languages = XDB::fetchOneCell('SELECT IF(ISNULL(gc1.belongsTo), gl1.language, gl2.language)
+ FROM geoloc_countries AS gc1
+ INNER JOIN geoloc_languages AS gl1 ON (gc1.iso_3166_1_a2 = gl1.iso_3166_1_a2)
+ LEFT JOIN geoloc_countries AS gc2 ON (gc1.belongsTo = gc2.iso_3166_1_a2)
+ LEFT JOIN geoloc_languages AS gl2 ON (gc2.iso_3166_1_a2 = gl2.iso_3166_1_a2)
+ WHERE gc1.iso_3166_1_a2 = {?}',
+ $address->countryId);
+ $toGeocode = substr($address->text, strlen($extraLines));
+ foreach (explode(',', $languages) as $language) {
+ if ($language != Platal::globals()->geocoder->gmaps_hl) {
+ $geocodedData = $this->getPlacemarkForAddress($toGeocode, $language);
+ $address->geocodedText = str_replace(', ', "\n", $geocodedData['address']);
+ if ($extraLines) {
+ $address->geocodedText = $extraLines . "\n" . $address->geocodedText;