|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace CultuurNet\UDB3; |
|
4
|
|
|
|
|
5
|
|
|
use Broadway\Serializer\SerializableInterface; |
|
6
|
|
|
use CultuurNet\UDB3\Model\ValueObject\Contact\ContactPoint as Udb3ModelContactPoint; |
|
7
|
|
|
use CultuurNet\UDB3\Model\ValueObject\Contact\TelephoneNumber; |
|
8
|
|
|
use CultuurNet\UDB3\Model\ValueObject\Web\EmailAddress; |
|
9
|
|
|
use CultuurNet\UDB3\Model\ValueObject\Web\Url; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* ContactPoint info. |
|
13
|
|
|
*/ |
|
14
|
|
|
class ContactPoint implements SerializableInterface, JsonLdSerializableInterface |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* @var array |
|
18
|
|
|
*/ |
|
19
|
|
|
protected $phones = array(); |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @var array |
|
23
|
|
|
*/ |
|
24
|
|
|
protected $emails = array(); |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var array |
|
28
|
|
|
*/ |
|
29
|
|
|
protected $urls = array(); |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Constructor. |
|
33
|
|
|
* @param array $phones |
|
34
|
|
|
* @param array $emails |
|
35
|
|
|
* @param array $urls |
|
36
|
|
|
*/ |
|
37
|
|
|
public function __construct(array $phones = array(), array $emails = array(), array $urls = array()) |
|
38
|
|
|
{ |
|
39
|
|
|
$this->phones = $phones; |
|
40
|
|
|
$this->emails = $emails; |
|
41
|
|
|
$this->urls = $urls; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @return array |
|
46
|
|
|
*/ |
|
47
|
|
|
public function getPhones() |
|
48
|
|
|
{ |
|
49
|
|
|
return $this->phones; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @return array |
|
54
|
|
|
*/ |
|
55
|
|
|
public function getEmails() |
|
56
|
|
|
{ |
|
57
|
|
|
return $this->emails; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @return array |
|
62
|
|
|
*/ |
|
63
|
|
|
public function getUrls() |
|
64
|
|
|
{ |
|
65
|
|
|
return $this->urls; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* {@inheritdoc} |
|
70
|
|
|
*/ |
|
71
|
|
|
public function serialize() |
|
72
|
|
|
{ |
|
73
|
|
|
return [ |
|
74
|
|
|
'phone' => $this->phones, |
|
75
|
|
|
'email' => $this->emails, |
|
76
|
|
|
'url' => $this->urls, |
|
77
|
|
|
]; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* {@inheritdoc} |
|
82
|
|
|
*/ |
|
83
|
|
|
public static function deserialize(array $data) |
|
84
|
|
|
{ |
|
85
|
|
|
return new static( |
|
86
|
|
|
$data['phone'], $data['email'], $data['url'] |
|
87
|
|
|
); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* {@inheritdoc} |
|
92
|
|
|
*/ |
|
93
|
|
|
public function toJsonLd() |
|
94
|
|
|
{ |
|
95
|
|
|
// Serialized version is the same. |
|
96
|
|
|
return $this->serialize(); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* @param ContactPoint $otherContactPoint |
|
101
|
|
|
* @return bool |
|
102
|
|
|
*/ |
|
103
|
|
|
public function sameAs(ContactPoint $otherContactPoint) |
|
104
|
|
|
{ |
|
105
|
|
|
return $this->toJsonLd() == $otherContactPoint->toJsonLd(); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* @param Udb3ModelContactPoint $contactPoint |
|
110
|
|
|
* @return ContactPoint |
|
111
|
|
|
*/ |
|
112
|
|
|
public static function fromUdb3ModelContactPoint(Udb3ModelContactPoint $contactPoint) |
|
113
|
|
|
{ |
|
114
|
|
|
$phones = array_map( |
|
115
|
|
|
function (TelephoneNumber $phone) { |
|
116
|
|
|
return $phone->toString(); |
|
117
|
|
|
}, |
|
118
|
|
|
$contactPoint->getTelephoneNumbers()->toArray() |
|
119
|
|
|
); |
|
120
|
|
|
|
|
121
|
|
|
$emails = array_map( |
|
122
|
|
|
function (EmailAddress $emailAddress) { |
|
123
|
|
|
return $emailAddress->toString(); |
|
124
|
|
|
}, |
|
125
|
|
|
$contactPoint->getEmailAddresses()->toArray() |
|
126
|
|
|
); |
|
127
|
|
|
|
|
128
|
|
|
$urls = array_map( |
|
129
|
|
|
function (Url $url) { |
|
130
|
|
|
return $url->toString(); |
|
131
|
|
|
}, |
|
132
|
|
|
$contactPoint->getUrls()->toArray() |
|
133
|
|
|
); |
|
134
|
|
|
|
|
135
|
|
|
return new ContactPoint($phones, $emails, $urls); |
|
136
|
|
|
} |
|
137
|
|
|
} |
|
138
|
|
|
|