-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontact.class.php
93 lines (77 loc) · 2.75 KB
/
contact.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?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 contact.class.php
* @ingroup plurioparser
*/
class Contact {
private $_areaCode = '+352'; // phone number area code
private $_phoneNumber; // contact phone number
private $_url; // store custom url
private $_emailAddress; // store custom email address
public function __construct(){
global $config;
// set defaults
$this->_phoneNumber = $config['org.phone'];
$this->_url = $config['org.url'];
$this->_emailAddress = $config['org.email'];
}
public function addTo( $entity, $caller ){
$childname = 'contact' . ucfirst( get_class( $caller ) );
$contact = $entity->addChild( $childname );
$this->_addContactPhoneNumbers( $contact ); // 1
if( !empty( $this->_url ) ) {
$this->_addWebsite( $contact ); // 2 order is important!
}
$this->_addContactEmail( $contact ); // 3
}
/**
* Allows to set a specific url
*/
public function setWebsiteUrl( $url ){
// we should probably do regex here first
// we should also test for arrays like this in address.class
$this->_url = is_array( $url ) ? $url[0] : $url;
}
public function setEmailAddress( $address ){
// we should probably do regex here first
$this->_emailAddress = is_array( $address ) ? $address[0] : $address;
}
public function setPhoneNumber( $phoneNumber ){
$phoneNumber = is_array( $phoneNumber ) ? $phoneNumber[0] : $phoneNumber;
if( preg_match( '/^(\+\d{1,3})\.(\d+)$/', $phoneNumber, $matches) ) {
$this->_areaCode = $matches[1];
$this->_phoneNumber = $matches[2];
} else $this->_phoneNumber = $phoneNumber;
}
/**
* Used by the event class for ticketing
*/
public function addPhoneNumber( $entity ) {
$this->_addSingleNumber( $entity );
}
private function _addContactPhoneNumbers( $contact ){
if( $this->_phoneNumber != '' ) {
$phoneNumbers = $contact->addChild( 'phoneNumbers' );
$this->_addSingleNumber( $phoneNumbers );
}
}
private function _addSingleNumber( $parent ) {
$phoneNumber = $parent->addChild( 'phoneNumber' );
$phoneNumber->addAttribute('phoneType','phone'); // FIXME
$phoneNumber->addChild('phoneNumberFunctionId','pn08'); // = Info
$phoneNumber->addChild('phoneNumberAreaCode', $this->_areaCode );
$phoneNumber->addChild('mainNumber', $this->_phoneNumber);
}
private function _addContactEmail( $contact ){
$email = $contact->addChild('emailAdresses')->addChild('emailAdress'); // sic
$email->addChild('emailAdressUrl',$this->_emailAddress); // sic
$email->addChild('emailAdressFunctionId','ea01'); // = Info (sic)
}
private function _addWebsite( $contact ) {
$contact->addChild( 'websites' )->addChild( 'website', $this->_url);
}
}