5 require_once(CONST_BasePath.'/lib/ClassTypes.php');
 
   8  * Detailed list of address parts for a single result
 
  13     private $aAddressLines;
 
  15     public function __construct(&$oDB, $iPlaceID, $sHousenumber, $mLangPref)
 
  17         $this->iPlaceID = $iPlaceID;
 
  19         if (is_array($mLangPref)) {
 
  20             $mLangPref = $oDB->getArraySQL($oDB->getDBQuotedList($mLangPref));
 
  23         if (!isset($sHousenumber)) {
 
  28         $sSQL .= ' get_name_by_language(name,'.$mLangPref.') as localname';
 
  29         $sSQL .= ' FROM get_addressdata('.$iPlaceID.','.$sHousenumber.')';
 
  30         $sSQL .= ' ORDER BY rank_address DESC, isaddress DESC';
 
  32         $this->aAddressLines = $oDB->getAll($sSQL);
 
  35     private static function isAddress($aLine)
 
  37         return $aLine['isaddress'] || $aLine['type'] == 'country_code';
 
  40     public function getAddressDetails($bAll = false)
 
  43             return $this->aAddressLines;
 
  46         return array_filter($this->aAddressLines, array(__CLASS__, 'isAddress'));
 
  49     public function getLocaleAddress()
 
  54         foreach ($this->aAddressLines as $aLine) {
 
  55             if ($aLine['isaddress'] && $sPrevResult != $aLine['localname']) {
 
  56                 $sPrevResult = $aLine['localname'];
 
  57                 $aParts[] = $sPrevResult;
 
  61         return join(', ', $aParts);
 
  64     public function getAddressNames()
 
  69         foreach ($this->aAddressLines as $aLine) {
 
  70             if (!self::isAddress($aLine)) {
 
  75             $aTypeLabel = ClassTypes\getInfo($aLine);
 
  77             if ($aTypeLabel === false) {
 
  78                 $aTypeLabel = ClassTypes\getFallbackInfo($aLine);
 
  83             if (isset($aLine['localname']) && $aLine['localname']!=='') {
 
  84                 $sName = $aLine['localname'];
 
  85             } elseif (isset($aLine['housenumber']) && $aLine['housenumber']!=='') {
 
  86                 $sName = $aLine['housenumber'];
 
  90                 $sTypeLabel = strtolower(isset($aTypeLabel['simplelabel']) ? $aTypeLabel['simplelabel'] : $aTypeLabel['label']);
 
  91                 $sTypeLabel = str_replace(' ', '_', $sTypeLabel);
 
  92                 if (!isset($aAddress[$sTypeLabel])
 
  93                     || isset($aFallback[$sTypeLabel])
 
  94                     || $aLine['class'] == 'place'
 
  96                     $aAddress[$sTypeLabel] = $sName;
 
  98                         $aFallback[$sTypeLabel] = $bFallback;
 
 108      * Annotates the given json with geocodejson address information fields.
 
 110      * @param array  $aJson  Json hash to add the fields to.
 
 112      * Geocodejson has the following fields:
 
 113      *  street, locality, postcode, city, district,
 
 114      *  county, state, country
 
 116      * Postcode and housenumber are added by type, district is not used.
 
 117      * All other fields are set according to address rank.
 
 119     public function addGeocodeJsonAddressParts(&$aJson)
 
 121         foreach (array_reverse($this->aAddressLines) as $aLine) {
 
 122             if (!$aLine['isaddress']) {
 
 126             if (!isset($aLine['localname']) || $aLine['localname'] == '') {
 
 130             if ($aLine['type'] == 'postcode' || $aLine['type'] == 'postal_code') {
 
 131                 $aJson['postcode'] = $aLine['localname'];
 
 132             } elseif ($aLine['type'] == 'house_number') {
 
 133                 $aJson['housenumber'] = $aLine['localname'];
 
 136             if ($this->iPlaceID == $aLine['place_id']) {
 
 140             $iRank = (int)$aLine['rank_address'];
 
 142             if ($iRank > 25 && $iRank < 28) {
 
 143                 $aJson['street'] = $aLine['localname'];
 
 144             } elseif ($iRank >= 22 && $iRank <= 25) {
 
 145                 $aJson['locality'] = $aLine['localname'];
 
 146             } elseif ($iRank >= 17 && $iRank <= 21) {
 
 147                 $aJson['district'] = $aLine['localname'];
 
 148             } elseif ($iRank >= 13 && $iRank <= 16) {
 
 149                 $aJson['city'] = $aLine['localname'];
 
 150             } elseif ($iRank >= 10 && $iRank <= 12) {
 
 151                 $aJson['county'] = $aLine['localname'];
 
 152             } elseif ($iRank >= 5 && $iRank <= 9) {
 
 153                 $aJson['state'] = $aLine['localname'];
 
 154             } elseif ($iRank == 4) {
 
 155                 $aJson['country'] = $aLine['localname'];
 
 160     public function getAdminLevels()
 
 163         foreach (array_reverse($this->aAddressLines) as $aLine) {
 
 164             if (self::isAddress($aLine)
 
 165                 && isset($aLine['admin_level'])
 
 166                 && $aLine['admin_level'] < 15
 
 167                 && !isset($aAddress['level'.$aLine['admin_level']])
 
 169                 $aAddress['level'.$aLine['admin_level']] = $aLine['localname'];
 
 175     public function debugInfo()
 
 177         return $this->aAddressLines;