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 $sLanguagePrefArraySQL = "ARRAY[".join(',',array_map("getDBQuoted", $this->aLangPrefOrder))."]";
42 $sSQL = "select placex.*,";
43 $sSQL .= " get_address_by_language(place_id, $sLanguagePrefArraySQL) as langaddress,";
44 $sSQL .= " get_name_by_language(name, $sLanguagePrefArraySQL) as placename,";
45 $sSQL .= " get_name_by_language(name, ARRAY['ref']) as ref,";
46 $sSQL .= " st_y(centroid) as lat, st_x(centroid) as lon";
47 $sSQL .= " from placex where place_id = ".(int)$this->iPlaceID;
48 $aPlace = $this->oDB->getRow($sSQL);
50 if ($this->bAddressDetails)
52 $aAddress = getAddressDetails($this->oDB, $sLanguagePrefArraySQL, $this->iPlaceID, $aPlace['calculated_country_code']);
53 $aPlace['aAddress'] = $aAddress;
56 $aClassType = getClassTypes();
58 $sClassType = $aPlace['class'].':'.$aPlace['type'].':'.$aPlace['admin_level'];
59 if (isset($aClassType[$sClassType]) && isset($aClassType[$sClassType]['simplelabel']))
61 $sAddressType = $aClassType[$aClassType]['simplelabel'];
65 $sClassType = $aPlace['class'].':'.$aPlace['type'];
66 if (isset($aClassType[$sClassType]) && isset($aClassType[$sClassType]['simplelabel']))
67 $sAddressType = $aClassType[$sClassType]['simplelabel'];
68 else $sAddressType = $aPlace['class'];
71 $aPlace['addresstype'] = $sAddressType;