-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddress.class.php
73 lines (59 loc) · 1.95 KB
/
address.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
/**
* Parser that uses data from a semantic wiki and outputs an
* XML file for import into plurio.net
*
* @author David Raison <[email protected]>
* @file address.class.php
* @ingroup plurioparser
*/
class Address {
private static $_localisation_ids;
private $_values; // Store values for an address
private static $_calls;
public function __construct( ){
global $config;
if( !isset( self::$_localisation_ids ) )
self::$_localisation_ids = simplexml_load_file( $config['localisation.dst'] );
// Sum calls to class for debug
self::$_calls++;
}
public function __set( $name, $value ){
$this->_values[$name] = $value;
}
/**
* Values for this are looked up in the wiki and that is being
* done in the Building->Entity->WikiApiClient class.
*/
public function addTo( &$entity ) {
$address = $entity->addChild('adress'); // (sic)
$address->street = $this->_values['street'];
$address->addChild('houseNumber',$this->_values['number']);
$address->placing = $this->_values['venue'];
$address->addChild('poBox', $this->_values['zipcode']);
// Fetch the LocalisationId from the XML file supplied by plurio
$lid = $this->_fetchLocalisationId( $this->_values['city'], $this->_values['zipcode'] );
$address->addChild( 'localisationId', $lid );
}
/**
* Look up this location's localisation ID from the plurio file
*/
private function _fetchLocalisationId( $city, $zipcode ) {
global $config;
foreach( self::$_localisation_ids as $localisation ) {
if(
strtolower( $localisation->city ) == strtolower( $city )
&& (
$localisation->zipcode == $zipcode
|| $localisation->zipcode == 'L-' . $zipcode
)
) {
$config['debug'] && printf( "Region is %s\n", $localisation->region);
return $localisation['id'];
}
}
throw new Exception(
sprintf( "LocalisationID for city %s and zipcode %d not found!\n", $this->_values['city'], $this->_values['zipcode'] ),
900 );
}
}