8 protected $aLangPrefOrder = array();
10 protected $bAddressDetails = false;
12 function PlaceLookup(&$oDB)
17 function setLanguagePreference($aLangPrefOrder)
19 $this->aLangPrefOrder = $aLangPrefOrder;
22 function setIncludeAddressDetails($bAddressDetails = true)
24 $this->bAddressDetails = $bAddressDetails;
27 function setPlaceID($iPlaceID)
29 $this->iPlaceID = $iPlaceID;
32 function setOSMID($sType, $iID)
34 $sSQL = "select place_id from placex where osm_type = '".pg_escape_string($sType)."' and osm_id = ".(int)$iID." order by type = 'postcode' asc";
35 $this->iPlaceID = $this->oDB->getOne($sSQL);
40 if (!$this->iPlaceID) return null;
42 $sLanguagePrefArraySQL = "ARRAY[".join(',',array_map("getDBQuoted", $this->aLangPrefOrder))."]";
44 $sSQL = "select placex.*,";
45 $sSQL .= " get_address_by_language(place_id, $sLanguagePrefArraySQL) as langaddress,";
46 $sSQL .= " get_name_by_language(name, $sLanguagePrefArraySQL) as placename,";
47 $sSQL .= " get_name_by_language(name, ARRAY['ref']) as ref,";
48 $sSQL .= " st_y(centroid) as lat, st_x(centroid) as lon";
49 $sSQL .= " from placex where place_id = ".(int)$this->iPlaceID;
50 $aPlace = $this->oDB->getRow($sSQL);
52 if (!$aPlace['place_id']) return null;
54 if ($this->bAddressDetails)
56 $aAddress = getAddressDetails($this->oDB, $sLanguagePrefArraySQL, $this->iPlaceID, $aPlace['calculated_country_code']);
57 $aPlace['aAddress'] = $aAddress;
60 $aClassType = getClassTypes();
62 $sClassType = $aPlace['class'].':'.$aPlace['type'].':'.$aPlace['admin_level'];
63 if (isset($aClassType[$sClassType]) && isset($aClassType[$sClassType]['simplelabel']))
65 $sAddressType = $aClassType[$aClassType]['simplelabel'];
69 $sClassType = $aPlace['class'].':'.$aPlace['type'];
70 if (isset($aClassType[$sClassType]) && isset($aClassType[$sClassType]['simplelabel']))
71 $sAddressType = $aClassType[$sClassType]['simplelabel'];
72 else $sAddressType = $aPlace['class'];
75 $aPlace['addresstype'] = $sAddressType;