X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/b7abc8566ed5b67ddbbfed7e10701b4838008f6b..9abb96fa6b87ba2086b0bf32eed0310690931cfe:/lib/AddressDetails.php diff --git a/lib/AddressDetails.php b/lib/AddressDetails.php index 8a4005d9..61823b4c 100644 --- a/lib/AddressDetails.php +++ b/lib/AddressDetails.php @@ -14,24 +14,24 @@ class AddressDetails public function __construct(&$oDB, $iPlaceID, $sHousenumber, $mLangPref) { if (is_array($mLangPref)) { - $mLangPref = 'ARRAY['.join(',', array_map('getDBQuoted', $mLangPref)).']'; + $mLangPref = $oDB->getArraySQL($oDB->getDBQuotedList($mLangPref)); } - if (!$sHousenumber) { + if (!isset($sHousenumber)) { $sHousenumber = -1; } $sSQL = 'SELECT *,'; - $sSQL .= ' get_name_by_language(name,'.$mLangPref.') as localname'; + $sSQL .= ' get_name_by_language(name,'.$mLangPref.') as localname'; $sSQL .= ' FROM get_addressdata('.$iPlaceID.','.$sHousenumber.')'; - $sSQL .= ' ORDER BY rank_address desc,isaddress DESC'; + $sSQL .= ' ORDER BY rank_address DESC, isaddress DESC'; - $this->aAddressLines = chksql($oDB->getAll($sSQL)); + $this->aAddressLines = $oDB->getAll($sSQL); } private static function isAddress($aLine) { - return $aLine['isaddress'] == 't' || $aLine['type'] == 'country_code'; + return $aLine['isaddress'] || $aLine['type'] == 'country_code'; } public function getAddressDetails($bAll = false) @@ -40,7 +40,7 @@ class AddressDetails return $this->aAddressLines; } - return array_filter($this->aAddressLines, 'AddressDetails::isAddress'); + return array_filter($this->aAddressLines, array(__CLASS__, 'isAddress')); } public function getLocaleAddress() @@ -49,7 +49,7 @@ class AddressDetails $sPrevResult = ''; foreach ($this->aAddressLines as $aLine) { - if ($aLine['isaddress'] == 't' && $sPrevResult != $aLine['localname']) { + if ($aLine['isaddress'] && $sPrevResult != $aLine['localname']) { $sPrevResult = $aLine['localname']; $aParts[] = $sPrevResult; } @@ -76,14 +76,14 @@ class AddressDetails $bFallback = true; } - $sName = false; - if (isset($aLine['localname']) && $aLine['localname']) { + $sName = null; + if (isset($aLine['localname']) && $aLine['localname']!=='') { $sName = $aLine['localname']; - } elseif (isset($aLine['housenumber']) && $aLine['housenumber']) { + } elseif (isset($aLine['housenumber']) && $aLine['housenumber']!=='') { $sName = $aLine['housenumber']; } - if ($sName) { + if (isset($sName)) { $sTypeLabel = strtolower(isset($aTypeLabel['simplelabel']) ? $aTypeLabel['simplelabel'] : $aTypeLabel['label']); $sTypeLabel = str_replace(' ', '_', $sTypeLabel); if (!isset($aAddress[$sTypeLabel]) @@ -97,13 +97,14 @@ class AddressDetails } } } + return $aAddress; } public function getAdminLevels() { $aAddress = array(); - foreach ($this->aAddressLines as $aLine) { + foreach (array_reverse($this->aAddressLines) as $aLine) { if (self::isAddress($aLine) && isset($aLine['admin_level']) && $aLine['admin_level'] < 15 @@ -114,4 +115,9 @@ class AddressDetails } return $aAddress; } + + public function debugInfo() + { + return $this->aAddressLines; + } }