|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* apparat/object |
|
5
|
|
|
* |
|
6
|
|
|
* @category Apparat |
|
7
|
|
|
* @package Apparat\Object |
|
8
|
|
|
* @subpackage Apparat\Object\Application\Model\Properties\Domain\Traits |
|
9
|
|
|
* @author Joschi Kuphal <[email protected]> / @jkphl |
|
10
|
|
|
* @copyright Copyright © 2016 Joschi Kuphal <[email protected]> / @jkphl |
|
11
|
|
|
* @license http://opensource.org/licenses/MIT The MIT License (MIT) |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
/*********************************************************************************** |
|
15
|
|
|
* The MIT License (MIT) |
|
16
|
|
|
* |
|
17
|
|
|
* Copyright © 2016 Joschi Kuphal <[email protected]> / @jkphl |
|
18
|
|
|
* |
|
19
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of |
|
20
|
|
|
* this software and associated documentation files (the "Software"), to deal in |
|
21
|
|
|
* the Software without restriction, including without limitation the rights to |
|
22
|
|
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of |
|
23
|
|
|
* the Software, and to permit persons to whom the Software is furnished to do so, |
|
24
|
|
|
* subject to the following conditions: |
|
25
|
|
|
* |
|
26
|
|
|
* The above copyright notice and this permission notice shall be included in all |
|
27
|
|
|
* copies or substantial portions of the Software. |
|
28
|
|
|
* |
|
29
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
30
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS |
|
31
|
|
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR |
|
32
|
|
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER |
|
33
|
|
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
|
34
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
|
35
|
|
|
***********************************************************************************/ |
|
36
|
|
|
|
|
37
|
|
|
namespace Apparat\Object\Application\Model\Properties\Domain\Traits; |
|
38
|
|
|
|
|
39
|
|
|
use Apparat\Object\Application\Model\Properties\Datatype\ApparatUrl; |
|
40
|
|
|
use Apparat\Object\Application\Model\Properties\Datatype\Datetime; |
|
41
|
|
|
use Apparat\Object\Application\Model\Properties\Datatype\Email; |
|
42
|
|
|
use Apparat\Object\Application\Model\Properties\Datatype\Sentence; |
|
43
|
|
|
use Apparat\Object\Application\Model\Properties\Datatype\Text; |
|
44
|
|
|
use Apparat\Object\Application\Model\Properties\Datatype\Token; |
|
45
|
|
|
use Apparat\Object\Application\Model\Properties\Datatype\Url; |
|
46
|
|
|
use Apparat\Object\Application\Model\Properties\Domain\Contact; |
|
47
|
|
|
use Apparat\Object\Domain\Contract\ObjectTypesInterface; |
|
48
|
|
|
use Apparat\Object\Domain\Model\Object\ObjectInterface; |
|
49
|
|
|
use Apparat\Object\Domain\Model\Properties\InvalidArgumentException; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Contact properties model trait |
|
53
|
|
|
* |
|
54
|
|
|
* @package Apparat\Object |
|
55
|
|
|
* @subpackage Apparat\Object\Application |
|
56
|
|
|
* @method ObjectInterface getObject() |
|
57
|
|
|
*/ |
|
58
|
|
|
trait ContactPropertiesModelTrait |
|
59
|
|
|
{ |
|
60
|
|
|
/** |
|
61
|
|
|
* Use the external property models |
|
62
|
|
|
*/ |
|
63
|
|
|
use AddressPropertiesModelTrait; |
|
64
|
|
|
/** |
|
65
|
|
|
* Property model: Name |
|
66
|
|
|
* |
|
67
|
|
|
* @var array |
|
68
|
|
|
*/ |
|
69
|
|
|
protected $pmName = [false, [Sentence::class]]; |
|
70
|
|
|
/** |
|
71
|
|
|
* Property model: Given name |
|
72
|
|
|
* |
|
73
|
|
|
* @var array |
|
74
|
|
|
*/ |
|
75
|
|
|
protected $pmGivenName = [false, [Sentence::class]]; |
|
76
|
|
|
/** |
|
77
|
|
|
* Property model: Additional name |
|
78
|
|
|
* |
|
79
|
|
|
* @var array |
|
80
|
|
|
*/ |
|
81
|
|
|
protected $pmAdditionalName = [false, [Sentence::class]]; |
|
82
|
|
|
/** |
|
83
|
|
|
* Property model: Family name |
|
84
|
|
|
* |
|
85
|
|
|
* @var array |
|
86
|
|
|
*/ |
|
87
|
|
|
protected $pmFamilyName = [false, [Sentence::class]]; |
|
88
|
|
|
/** |
|
89
|
|
|
* Property model: Nickname |
|
90
|
|
|
* |
|
91
|
|
|
* @var array |
|
92
|
|
|
*/ |
|
93
|
|
|
protected $pmNickname = [false, [Sentence::class]]; |
|
94
|
|
|
/** |
|
95
|
|
|
* Property model: Sort string |
|
96
|
|
|
* |
|
97
|
|
|
* @var array |
|
98
|
|
|
*/ |
|
99
|
|
|
protected $pmSortString = [false, [Sentence::class]]; |
|
100
|
|
|
/** |
|
101
|
|
|
* Property model: Honorific prefix |
|
102
|
|
|
* |
|
103
|
|
|
* @var array |
|
104
|
|
|
*/ |
|
105
|
|
|
protected $pmHonorificPrefix = [false, [Sentence::class]]; |
|
106
|
|
|
/** |
|
107
|
|
|
* Property model: Honorific suffix |
|
108
|
|
|
* |
|
109
|
|
|
* @var array |
|
110
|
|
|
*/ |
|
111
|
|
|
protected $pmHonorificSuffix = [false, [Sentence::class]]; |
|
112
|
|
|
/** |
|
113
|
|
|
* Property model: Email |
|
114
|
|
|
* |
|
115
|
|
|
* @var array |
|
116
|
|
|
*/ |
|
117
|
|
|
protected $pmEmail = [true, [Email::class]]; |
|
118
|
|
|
/** |
|
119
|
|
|
* Property model: Logo |
|
120
|
|
|
* |
|
121
|
|
|
* @var array |
|
122
|
|
|
*/ |
|
123
|
|
|
protected $pmLogo = [true, [ApparatUrl::class, Url::class], [ApparatUrl::class => [ObjectTypesInterface::IMAGE]]]; |
|
124
|
|
|
/** |
|
125
|
|
|
* Property model: Photo |
|
126
|
|
|
* |
|
127
|
|
|
* @var array |
|
128
|
|
|
*/ |
|
129
|
|
|
protected $pmPhoto = [true, [ApparatUrl::class, Url::class], [ApparatUrl::class => [ObjectTypesInterface::IMAGE]]]; |
|
130
|
|
|
/** |
|
131
|
|
|
* Property model: URL |
|
132
|
|
|
* |
|
133
|
|
|
* @var array |
|
134
|
|
|
*/ |
|
135
|
|
|
protected $pmUrl = [true, [Url::class]]; |
|
136
|
|
|
/** |
|
137
|
|
|
* Property model: Address |
|
138
|
|
|
* |
|
139
|
|
|
* @var array |
|
140
|
|
|
*/ |
|
141
|
|
|
protected $pmAdr = [true, [ApparatUrl::class, Text::class]]; |
|
142
|
|
|
/** |
|
143
|
|
|
* Property model: Telephone number |
|
144
|
|
|
* |
|
145
|
|
|
* @var array |
|
146
|
|
|
*/ |
|
147
|
|
|
protected $pmTel = [true, [Sentence::class]]; |
|
148
|
|
|
/** |
|
149
|
|
|
* Property model: Note |
|
150
|
|
|
* |
|
151
|
|
|
* @var array |
|
152
|
|
|
*/ |
|
153
|
|
|
protected $pmNote = [true, [Text::class]]; |
|
154
|
|
|
/** |
|
155
|
|
|
* Property model: Birthday |
|
156
|
|
|
* |
|
157
|
|
|
* @var array |
|
158
|
|
|
*/ |
|
159
|
|
|
protected $pmBday = [false, [Datetime::class]]; |
|
160
|
|
|
/** |
|
161
|
|
|
* Property model: Cryptographic public key |
|
162
|
|
|
* |
|
163
|
|
|
* @var array |
|
164
|
|
|
*/ |
|
165
|
|
|
protected $pmKey = [true, [Url::class]]; |
|
166
|
|
|
/** |
|
167
|
|
|
* Property model: Organization |
|
168
|
|
|
* |
|
169
|
|
|
* @var array |
|
170
|
|
|
*/ |
|
171
|
|
|
protected $pmOrg = [ |
|
172
|
|
|
true, |
|
173
|
|
|
[ApparatUrl::class, Sentence::class], |
|
174
|
|
|
[ApparatUrl::class => [ObjectTypesInterface::CONTACT]] |
|
175
|
|
|
]; |
|
176
|
|
|
/** |
|
177
|
|
|
* Property model: Job title |
|
178
|
|
|
* |
|
179
|
|
|
* @var array |
|
180
|
|
|
*/ |
|
181
|
|
|
protected $pmJobTitle = [true, [Sentence::class]]; |
|
182
|
|
|
/** |
|
183
|
|
|
* Property model: Instant messaging |
|
184
|
|
|
* |
|
185
|
|
|
* @var array |
|
186
|
|
|
*/ |
|
187
|
|
|
protected $pmImpp = [true, [Url::class]]; |
|
188
|
|
|
/** |
|
189
|
|
|
* Property model: Biological sex |
|
190
|
|
|
* |
|
191
|
|
|
* @var array |
|
192
|
|
|
*/ |
|
193
|
|
|
protected $pmSex = [false, [Token::class]]; |
|
194
|
|
|
/** |
|
195
|
|
|
* Property model: Gender identity |
|
196
|
|
|
* |
|
197
|
|
|
* @var array |
|
198
|
|
|
*/ |
|
199
|
|
|
protected $pmGenderIdentity = [false, [Sentence::class]]; |
|
200
|
|
|
/** |
|
201
|
|
|
* Property model: Anniversary |
|
202
|
|
|
* |
|
203
|
|
|
* @var array |
|
204
|
|
|
*/ |
|
205
|
|
|
protected $pmAnniversary = [true, [Datetime::class]]; |
|
206
|
|
|
|
|
207
|
|
|
/** |
|
208
|
|
|
* Set the given name |
|
209
|
|
|
* |
|
210
|
|
|
* @param string $property Property |
|
211
|
|
|
* @param string $value Given name |
|
212
|
|
|
*/ |
|
213
|
2 |
|
public function setPmGivenName(&$property, $value) |
|
214
|
|
|
{ |
|
215
|
2 |
|
$property = $value; |
|
216
|
2 |
|
$this->composeFullName(Contact::GIVEN_NAME, $value); |
|
217
|
2 |
|
} |
|
218
|
|
|
|
|
219
|
|
|
/** |
|
220
|
|
|
* Set the nickname |
|
221
|
|
|
* |
|
222
|
|
|
* @param string $property Property |
|
223
|
|
|
* @param string $value Nickname |
|
224
|
|
|
*/ |
|
225
|
1 |
|
public function setPmNickname(&$property, $value) |
|
226
|
|
|
{ |
|
227
|
1 |
|
$property = $value; |
|
228
|
1 |
|
$this->composeFullName(Contact::NICKNAME, $value); |
|
229
|
1 |
|
} |
|
230
|
|
|
|
|
231
|
|
|
/** |
|
232
|
|
|
* Set the additional name |
|
233
|
|
|
* |
|
234
|
|
|
* @param string $property Property |
|
235
|
|
|
* @param string $value Additional name |
|
236
|
|
|
*/ |
|
237
|
1 |
|
public function setPmAdditionalName(&$property, $value) |
|
238
|
|
|
{ |
|
239
|
1 |
|
$property = $value; |
|
240
|
1 |
|
$this->composeFullName(Contact::ADDITIONAL_NAME, $value); |
|
241
|
1 |
|
} |
|
242
|
|
|
|
|
243
|
|
|
/** |
|
244
|
|
|
* Set the given name |
|
245
|
|
|
* |
|
246
|
|
|
* @param string $property Property |
|
247
|
|
|
* @param string $value Given name |
|
248
|
|
|
*/ |
|
249
|
1 |
|
public function setPmFamilyName(&$property, $value) |
|
250
|
|
|
{ |
|
251
|
1 |
|
$property = $value; |
|
252
|
1 |
|
$this->composeFullName(Contact::FAMILY_NAME, $value); |
|
253
|
1 |
|
} |
|
254
|
|
|
|
|
255
|
|
|
/** |
|
256
|
|
|
* Set the honorific prefix |
|
257
|
|
|
* |
|
258
|
|
|
* @param string $property Property |
|
259
|
|
|
* @param string $value Honorific prefix |
|
260
|
|
|
*/ |
|
261
|
1 |
|
public function setPmHonorificPrefix(&$property, $value) |
|
262
|
|
|
{ |
|
263
|
1 |
|
$property = $value; |
|
264
|
1 |
|
$this->composeFullName(Contact::HONORIFIC_PREFIX, $value); |
|
265
|
1 |
|
} |
|
266
|
|
|
|
|
267
|
|
|
/** |
|
268
|
|
|
* Set the honorific suffix |
|
269
|
|
|
* |
|
270
|
|
|
* @param string $property Property |
|
271
|
|
|
* @param string $value Honorific suffix |
|
272
|
|
|
*/ |
|
273
|
1 |
|
public function setPmHonorificSuffix(&$property, $value) |
|
274
|
|
|
{ |
|
275
|
1 |
|
$property = $value; |
|
276
|
1 |
|
$this->composeFullName(Contact::HONORIFIC_SUFFIX, $value); |
|
277
|
1 |
|
} |
|
278
|
|
|
|
|
279
|
|
|
/** |
|
280
|
|
|
* Set the full contact name |
|
281
|
|
|
* |
|
282
|
|
|
* @param string $propertyName Current name property |
|
283
|
|
|
* @param string $propertyValue Current name property value |
|
284
|
|
|
*/ |
|
285
|
2 |
|
protected function composeFullName($propertyName, $propertyValue) |
|
286
|
|
|
{ |
|
287
|
|
|
$nameProperties = [ |
|
288
|
2 |
|
Contact::HONORIFIC_PREFIX => '', |
|
289
|
|
|
Contact::GIVEN_NAME => '', |
|
290
|
|
|
Contact::NICKNAME => '', |
|
291
|
|
|
Contact::ADDITIONAL_NAME => '', |
|
292
|
|
|
Contact::FAMILY_NAME => '', |
|
293
|
|
|
Contact::HONORIFIC_SUFFIX => '' |
|
294
|
|
|
]; |
|
295
|
2 |
|
foreach (array_keys($nameProperties) as $name) { |
|
296
|
|
|
try { |
|
297
|
2 |
|
$nameProperty = trim($this->getObject()->getDomainProperty($name)); |
|
298
|
1 |
|
if (strlen($nameProperty)) { |
|
299
|
1 |
|
$nameProperties[$name] = $nameProperty; |
|
300
|
|
|
} |
|
301
|
2 |
|
} catch (InvalidArgumentException $e) { |
|
302
|
2 |
|
continue; |
|
303
|
|
|
} |
|
304
|
|
|
} |
|
305
|
2 |
|
$nameProperties[$propertyName] = $propertyValue; |
|
306
|
2 |
|
if (!empty($nameProperties[Contact::NICKNAME])) { |
|
307
|
1 |
|
$nameProperties[Contact::NICKNAME] = '"'.$nameProperties[Contact::NICKNAME].'"'; |
|
308
|
|
|
} |
|
309
|
2 |
|
$this->getObject()->setTitle(implode(' ', array_filter($nameProperties))); |
|
310
|
|
|
} |
|
311
|
|
|
} |