1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the TheAlternativeZurich/events project. |
5
|
|
|
* |
6
|
|
|
* (c) Florian Moser <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace App\Entity\Traits; |
13
|
|
|
|
14
|
|
|
use Doctrine\ORM\Mapping as ORM; |
15
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
16
|
|
|
|
17
|
|
|
/* |
18
|
|
|
* Attendee information |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
trait ContactInformationTrait |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var string|null |
25
|
|
|
* |
26
|
|
|
* @ORM\Column(type="text") |
27
|
|
|
*/ |
28
|
|
|
private $givenName; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var string|null |
32
|
|
|
* |
33
|
|
|
* @ORM\Column(type="text") |
34
|
|
|
*/ |
35
|
|
|
private $familyName; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var string|null |
39
|
|
|
* |
40
|
|
|
* @ORM\Column(type="text") |
41
|
|
|
*/ |
42
|
|
|
private $phone; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var string|null |
46
|
|
|
* |
47
|
|
|
* @ORM\Column(type="text") |
48
|
|
|
*/ |
49
|
|
|
private $email; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @var string|null |
53
|
|
|
* |
54
|
|
|
* @ORM\Column(type="text") |
55
|
|
|
*/ |
56
|
|
|
private $streetAddress; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @var int|null |
60
|
|
|
* |
61
|
|
|
* @ORM\Column(type="integer") |
62
|
|
|
*/ |
63
|
|
|
private $postalCode; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @var string|null |
67
|
|
|
* |
68
|
|
|
* @ORM\Column(type="text") |
69
|
|
|
*/ |
70
|
|
|
private $locality; |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @var string|null |
74
|
|
|
* |
75
|
|
|
* @ORM\Column(type="string", nullable=true) |
76
|
|
|
*/ |
77
|
|
|
private $canton; |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @var string |
81
|
|
|
* |
82
|
|
|
* @ORM\Column(type="text", nullable=true) |
83
|
|
|
* @Assert\Country() |
84
|
|
|
*/ |
85
|
|
|
private $country = 'CH'; |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @param ContactInformationTrait $other |
89
|
|
|
*/ |
90
|
|
|
protected function fromOtherContactInformation($other) |
91
|
|
|
{ |
92
|
|
|
$this->givenName = $other->getGivenName(); |
93
|
|
|
$this->familyName = $other->getFamilyName(); |
94
|
|
|
$this->phone = $other->getPhone(); |
95
|
|
|
$this->email = $other->getEmail(); |
96
|
|
|
$this->streetAddress = $other->getStreetAddress(); |
97
|
|
|
$this->postalCode = $other->getPostalCode(); |
98
|
|
|
$this->locality = $other->getLocality(); |
99
|
|
|
$this->canton = $other->getCanton(); |
100
|
|
|
$this->country = $other->getCountry(); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
protected function toContactInformationArray(): array |
104
|
|
|
{ |
105
|
|
|
return [ |
106
|
|
|
'given name' => $this->givenName, |
107
|
|
|
'family name' => $this->familyName, |
108
|
|
|
'phone' => $this->phone, |
109
|
|
|
'email' => $this->email, |
110
|
|
|
'street address' => $this->streetAddress, |
111
|
|
|
'postal code' => $this->postalCode, |
112
|
|
|
'locality' => $this->locality, |
113
|
|
|
'canton' => $this->canton, |
114
|
|
|
'country' => $this->country, |
115
|
|
|
]; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
public function getGivenName(): ?string |
119
|
|
|
{ |
120
|
|
|
return $this->givenName; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
public function setGivenName(?string $givenName): void |
124
|
|
|
{ |
125
|
|
|
$this->givenName = $givenName; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
public function getFamilyName(): ?string |
129
|
|
|
{ |
130
|
|
|
return $this->familyName; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
public function setFamilyName(?string $familyName): void |
134
|
|
|
{ |
135
|
|
|
$this->familyName = $familyName; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
public function getPhone(): ?string |
139
|
|
|
{ |
140
|
|
|
return $this->phone; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
public function setPhone(?string $phone): void |
144
|
|
|
{ |
145
|
|
|
$this->phone = $phone; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
public function getEmail(): ?string |
149
|
|
|
{ |
150
|
|
|
return $this->email; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
public function setEmail(?string $email): void |
154
|
|
|
{ |
155
|
|
|
$this->email = $email; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
public function getStreetAddress(): ?string |
159
|
|
|
{ |
160
|
|
|
return $this->streetAddress; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
public function setStreetAddress(?string $streetAddress): void |
164
|
|
|
{ |
165
|
|
|
$this->streetAddress = $streetAddress; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
public function getPostalCode(): ?int |
169
|
|
|
{ |
170
|
|
|
return $this->postalCode; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
public function setPostalCode(?int $postalCode): void |
174
|
|
|
{ |
175
|
|
|
$this->postalCode = $postalCode; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
public function getLocality(): ?string |
179
|
|
|
{ |
180
|
|
|
return $this->locality; |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
public function setLocality(?string $locality): void |
184
|
|
|
{ |
185
|
|
|
$this->locality = $locality; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
public function getCanton(): ?string |
189
|
|
|
{ |
190
|
|
|
return $this->canton; |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
public function setCanton(?string $canton): void |
194
|
|
|
{ |
195
|
|
|
$this->canton = $canton; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
public function getCountry(): string |
199
|
|
|
{ |
200
|
|
|
return $this->country; |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
public function setCountry(string $country): void |
204
|
|
|
{ |
205
|
|
|
$this->country = $country; |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* returns all non-empty address lines. |
210
|
|
|
* |
211
|
|
|
* @return string[] |
212
|
|
|
*/ |
213
|
|
|
public function getAddressLines() |
214
|
|
|
{ |
215
|
|
|
$res = explode("\n", $this->getStreetAddress()); |
216
|
|
|
$prefix = ''; |
217
|
|
|
if (mb_strlen($this->getCountry()) > 0) { |
218
|
|
|
$prefix = $this->getCountry().((mb_strlen($this->getPostalCode()) > 0) ? '-' : ' '); |
219
|
|
|
} |
220
|
|
|
if (mb_strlen($this->getPostalCode()) > 0) { |
221
|
|
|
$prefix .= $this->getPostalCode().' '; |
222
|
|
|
} |
223
|
|
|
if (mb_strlen($this->getLocality()) > 0) { |
224
|
|
|
$prefix .= $this->getLocality().' '; |
225
|
|
|
} |
226
|
|
|
if (mb_strlen($this->getCanton()) > 0) { |
227
|
|
|
$prefix .= $this->getCanton().' '; |
228
|
|
|
} |
229
|
|
|
$res[] = trim($prefix); |
230
|
|
|
|
231
|
|
|
$result = []; |
232
|
|
|
foreach ($res as $entry) { |
233
|
|
|
if (mb_strlen($entry) > 0) { |
234
|
|
|
$result[] = $entry; |
235
|
|
|
} |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
return $result; |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
public function getAddress() |
242
|
|
|
{ |
243
|
|
|
$street = str_replace("\n", ',', $this->getStreetAddress()); |
244
|
|
|
$locality = $this->postalCode.' '.$this->locality; |
245
|
|
|
|
246
|
|
|
return $street.', '.$locality.', '.$this->canton.' '.$this->country; |
247
|
|
|
} |
248
|
|
|
|
249
|
|
|
public function getName() |
250
|
|
|
{ |
251
|
|
|
return $this->givenName.' '.$this->familyName; |
252
|
|
|
} |
253
|
|
|
} |
254
|
|
|
|