5 require_once(CONST_BasePath.'/lib/ClassTypes.php');
8 * Detailed list of address parts for a single result
12 private $aAddressLines;
14 public function __construct(&$oDB, $iPlaceID, $sHousenumber, $mLangPref)
16 if (is_array($mLangPref)) {
17 $mLangPref = 'ARRAY['.join(',', array_map('getDBQuoted', $mLangPref)).']';
25 $sSQL .= ' get_name_by_language(name,'.$mLangPref.') as localname';
26 $sSQL .= ' FROM get_addressdata('.$iPlaceID.','.$sHousenumber.')';
27 $sSQL .= ' ORDER BY rank_address DESC, isaddress DESC';
29 $this->aAddressLines = $oDB->getAll($sSQL);
32 private static function isAddress($aLine)
34 return $aLine['isaddress'] == 't' || $aLine['type'] == 'country_code';
37 public function getAddressDetails($bAll = false)
40 return $this->aAddressLines;
43 return array_filter($this->aAddressLines, array(__CLASS__, 'isAddress'));
46 public function getLocaleAddress()
51 foreach ($this->aAddressLines as $aLine) {
52 if ($aLine['isaddress'] == 't' && $sPrevResult != $aLine['localname']) {
53 $sPrevResult = $aLine['localname'];
54 $aParts[] = $sPrevResult;
58 return join(', ', $aParts);
61 public function getAddressNames()
66 foreach ($this->aAddressLines as $aLine) {
67 if (!self::isAddress($aLine)) {
72 $aTypeLabel = ClassTypes\getInfo($aLine);
74 if ($aTypeLabel === false) {
75 $aTypeLabel = ClassTypes\getFallbackInfo($aLine);
80 if (isset($aLine['localname']) && $aLine['localname']) {
81 $sName = $aLine['localname'];
82 } elseif (isset($aLine['housenumber']) && $aLine['housenumber']) {
83 $sName = $aLine['housenumber'];
87 $sTypeLabel = strtolower(isset($aTypeLabel['simplelabel']) ? $aTypeLabel['simplelabel'] : $aTypeLabel['label']);
88 $sTypeLabel = str_replace(' ', '_', $sTypeLabel);
89 if (!isset($aAddress[$sTypeLabel])
90 || isset($aFallback[$sTypeLabel])
91 || $aLine['class'] == 'place'
93 $aAddress[$sTypeLabel] = $sName;
95 $aFallback[$sTypeLabel] = $bFallback;
103 public function getAdminLevels()
106 foreach (array_reverse($this->aAddressLines) as $aLine) {
107 if (self::isAddress($aLine)
108 && isset($aLine['admin_level'])
109 && $aLine['admin_level'] < 15
110 && !isset($aAddress['level'.$aLine['admin_level']])
112 $aAddress['level'.$aLine['admin_level']] = $aLine['localname'];
118 public function debugInfo()
120 return $this->aAddressLines;