|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* YAWIK |
|
4
|
|
|
* |
|
5
|
|
|
* @filesource |
|
6
|
|
|
* @license MIT |
|
7
|
|
|
* @copyright https://yawik.org/COPYRIGHT.php |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
/** */ |
|
11
|
|
|
namespace Organizations\Entity; |
|
12
|
|
|
|
|
13
|
|
|
use Auth\Entity\UserInterface; |
|
14
|
|
|
use Core\Entity\EntityInterface; |
|
15
|
|
|
use Core\Entity\MetaDataProviderTrait; |
|
16
|
|
|
use Core\Entity\PermissionsInterface; |
|
17
|
|
|
use Doctrine\Common\Collections\Collection; |
|
18
|
|
|
use Organizations\Repository\Organization as OrganizationRepository; |
|
19
|
|
|
use Laminas\Hydrator\HydratorInterface; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Manages reference to an organization. |
|
23
|
|
|
* |
|
24
|
|
|
* As OrganizationInterface is also implemented (and all methods are proxied to the "real" organization |
|
25
|
|
|
* object), this class can be used as an organization. |
|
26
|
|
|
* |
|
27
|
|
|
* @author Mathias Gelhausen <[email protected]> |
|
28
|
|
|
* @todo update test |
|
29
|
|
|
*/ |
|
30
|
|
|
class OrganizationReference implements |
|
31
|
|
|
OrganizationInterface, |
|
32
|
|
|
OrganizationReferenceInterface |
|
33
|
|
|
{ |
|
34
|
|
|
use MetaDataProviderTrait; |
|
35
|
|
|
|
|
36
|
|
|
/* |
|
37
|
|
|
* Note: We start property names with an underscore to prevent |
|
38
|
|
|
* name collisions with the OrganizationInterface. |
|
39
|
|
|
*/ |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* The user id of the parent document. |
|
43
|
|
|
* |
|
44
|
|
|
* @var string |
|
45
|
|
|
*/ |
|
46
|
|
|
protected $_userId; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* The organization repository. |
|
50
|
|
|
* |
|
51
|
|
|
* @var \Organizations\Repository\Organization |
|
52
|
|
|
*/ |
|
53
|
|
|
protected $_repository; |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* The organization |
|
57
|
|
|
* |
|
58
|
|
|
* @var Organization |
|
59
|
|
|
*/ |
|
60
|
|
|
protected $_organization; |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Reference type. |
|
64
|
|
|
* |
|
65
|
|
|
* @internal |
|
66
|
|
|
* Initial value is null, so we can determine in {@link load()} if it has already run once. |
|
67
|
|
|
* |
|
68
|
|
|
* @var string |
|
69
|
|
|
*/ |
|
70
|
|
|
protected $_type; |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Creates an instance. |
|
74
|
|
|
* |
|
75
|
|
|
* @param string $userId |
|
76
|
|
|
* @param OrganizationRepository $repository |
|
77
|
|
|
*/ |
|
78
|
46 |
|
public function __construct($userId, OrganizationRepository $repository) |
|
79
|
|
|
{ |
|
80
|
46 |
|
$this->_userId = $userId; |
|
81
|
46 |
|
$this->_repository = $repository; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
1 |
|
public function isOwner() |
|
85
|
|
|
{ |
|
86
|
1 |
|
$this->load(); |
|
87
|
|
|
|
|
88
|
1 |
|
return self::TYPE_OWNER == $this->_type; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
1 |
|
public function isEmployee() |
|
92
|
|
|
{ |
|
93
|
1 |
|
$this->load(); |
|
94
|
|
|
|
|
95
|
1 |
|
return self::TYPE_EMPLOYEE == $this->_type; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
45 |
|
public function hasAssociation() |
|
99
|
|
|
{ |
|
100
|
45 |
|
$this->load(); |
|
101
|
|
|
|
|
102
|
45 |
|
return self::TYPE_NONE != $this->_type; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
1 |
|
public function getOrganization() |
|
106
|
|
|
{ |
|
107
|
1 |
|
$this->load(); |
|
108
|
|
|
|
|
109
|
1 |
|
return $this->_organization; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* Loads the organization from the database and sets the reference type. |
|
114
|
|
|
*/ |
|
115
|
45 |
|
protected function load() |
|
116
|
|
|
{ |
|
117
|
45 |
|
if (null !== $this->_type) { |
|
118
|
29 |
|
return; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
// Is the user the owner of the referenced organization? |
|
122
|
45 |
|
$org = $this->_repository->findByUser($this->_userId); |
|
123
|
|
|
|
|
124
|
45 |
|
if ($org) { |
|
125
|
23 |
|
$this->_type = self::TYPE_OWNER; |
|
126
|
23 |
|
$this->_organization = $org; |
|
127
|
|
|
|
|
128
|
23 |
|
return; |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
// Is the user employed by the referenced organization? |
|
132
|
23 |
|
$org = $this->_repository->findByEmployee($this->_userId); |
|
133
|
|
|
|
|
134
|
23 |
|
if ($org) { |
|
135
|
1 |
|
$this->_type = self::TYPE_EMPLOYEE; |
|
136
|
1 |
|
$this->_organization = $org; |
|
137
|
|
|
|
|
138
|
1 |
|
return; |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
// It seems the user is not associated with an organization. |
|
142
|
23 |
|
$this->_type = self::TYPE_NONE; |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
|
|
146
|
|
|
/** |
|
147
|
|
|
* Executes a proxy call to the associated organization entity. |
|
148
|
|
|
* |
|
149
|
|
|
* Does nothing, if no organization is available. |
|
150
|
|
|
* |
|
151
|
|
|
* Call it like: |
|
152
|
|
|
* <pre> |
|
153
|
|
|
* $this->proxy($method[, $arg1[, $arg2[, ...]]]); |
|
154
|
|
|
* </pre> |
|
155
|
|
|
* |
|
156
|
|
|
* @param $method |
|
157
|
|
|
* |
|
158
|
|
|
* @return self|mixed |
|
159
|
|
|
*/ |
|
160
|
44 |
|
protected function proxy($method) |
|
161
|
|
|
{ |
|
162
|
44 |
|
if (!$this->hasAssociation()) { |
|
163
|
22 |
|
return $this; |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
22 |
|
$args = array_slice(func_get_args(), 1); |
|
167
|
|
|
|
|
168
|
22 |
|
$return = call_user_func_array(array($this->_organization, $method), $args); |
|
169
|
|
|
|
|
170
|
22 |
|
return ($return === $this->_organization) ? $this : $return; |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
/* |
|
174
|
|
|
* We need to implement each method of OrganizationInterface because we want to proxy |
|
175
|
|
|
* to a concrete instance of Organization and therefor cannot simply extend. |
|
176
|
|
|
*/ |
|
177
|
|
|
|
|
178
|
|
|
/**#@+ |
|
179
|
|
|
* Proxies to the concrete Organization instance. |
|
180
|
|
|
* |
|
181
|
|
|
* {@inheritDoc} |
|
182
|
|
|
*/ |
|
183
|
|
|
|
|
184
|
|
|
|
|
185
|
|
|
public function __get($property) |
|
186
|
|
|
{ |
|
187
|
|
|
return $this->proxy('__get', $property); |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
|
|
public function __set($property, $value) |
|
191
|
|
|
{ |
|
192
|
|
|
return $this->proxy('__set', $property, $value); |
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
|
|
public function __isset($property) |
|
196
|
|
|
{ |
|
197
|
|
|
return $this->proxy('__isset', $property); |
|
198
|
|
|
} |
|
199
|
|
|
|
|
200
|
|
|
public function notEmpty($property, array $args=[]) |
|
201
|
|
|
{ |
|
202
|
|
|
return $this->proxy('notEmpty', $args); |
|
|
|
|
|
|
203
|
|
|
} |
|
204
|
|
|
|
|
205
|
|
|
public function hasProperty($property, $mode = self::PROPERTY_STRICT) |
|
206
|
|
|
{ |
|
207
|
|
|
return $this->proxy('hasProperty', $mode); |
|
|
|
|
|
|
208
|
|
|
} |
|
209
|
|
|
|
|
210
|
2 |
|
public function setHydrator(HydratorInterface $hydrator): void |
|
211
|
|
|
{ |
|
212
|
2 |
|
$this->proxy('setHydrator', $hydrator); |
|
213
|
|
|
} |
|
214
|
|
|
|
|
215
|
2 |
|
public function getHydrator(): ?HydratorInterface |
|
216
|
|
|
{ |
|
217
|
2 |
|
return $this->proxy('getHydrator'); |
|
|
|
|
|
|
218
|
|
|
} |
|
219
|
|
|
|
|
220
|
2 |
|
public function setId($id) |
|
221
|
|
|
{ |
|
222
|
2 |
|
return $this->proxy('setId', $id); |
|
223
|
|
|
} |
|
224
|
|
|
|
|
225
|
2 |
|
public function getId() |
|
226
|
|
|
{ |
|
227
|
2 |
|
return $this->proxy('getId'); |
|
228
|
|
|
} |
|
229
|
|
|
|
|
230
|
2 |
|
public function setDateCreated($date) |
|
231
|
|
|
{ |
|
232
|
2 |
|
return $this->proxy('setDateCreated', $date); |
|
233
|
|
|
} |
|
234
|
|
|
|
|
235
|
2 |
|
public function getDateCreated() |
|
236
|
|
|
{ |
|
237
|
2 |
|
return $this->proxy('getDateCreated'); |
|
|
|
|
|
|
238
|
|
|
} |
|
239
|
|
|
|
|
240
|
2 |
|
public function setDateModified($date) |
|
241
|
|
|
{ |
|
242
|
2 |
|
return $this->proxy('setDateModified', $date); |
|
243
|
|
|
} |
|
244
|
|
|
|
|
245
|
2 |
|
public function getDateModified() |
|
246
|
|
|
{ |
|
247
|
2 |
|
return $this->proxy('getDateModified'); |
|
|
|
|
|
|
248
|
|
|
} |
|
249
|
|
|
|
|
250
|
2 |
|
public function setParent(OrganizationInterface $parent) |
|
251
|
|
|
{ |
|
252
|
2 |
|
return $this->proxy('setParent', $parent); |
|
253
|
|
|
} |
|
254
|
|
|
|
|
255
|
2 |
|
public function getParent($returnSelf = false) |
|
256
|
|
|
{ |
|
257
|
2 |
|
return $this->proxy('getParent', $returnSelf); |
|
258
|
|
|
} |
|
259
|
|
|
|
|
260
|
2 |
|
public function setContact(EntityInterface $contact = null) |
|
261
|
|
|
{ |
|
262
|
2 |
|
return $this->proxy('setContact', $contact); |
|
263
|
|
|
} |
|
264
|
|
|
|
|
265
|
2 |
|
public function getContact() |
|
266
|
|
|
{ |
|
267
|
2 |
|
return $this->proxy('getContact'); |
|
|
|
|
|
|
268
|
|
|
} |
|
269
|
|
|
|
|
270
|
2 |
|
public function isHiringOrganization() |
|
271
|
|
|
{ |
|
272
|
2 |
|
return $this->proxy('isHiringOrganization'); |
|
|
|
|
|
|
273
|
|
|
} |
|
274
|
|
|
|
|
275
|
2 |
|
public function getHiringOrganizations() |
|
276
|
|
|
{ |
|
277
|
2 |
|
return $this->proxy('getHiringOrganizations'); |
|
|
|
|
|
|
278
|
|
|
} |
|
279
|
|
|
|
|
280
|
2 |
|
public function setImage(OrganizationImage $image) |
|
281
|
|
|
{ |
|
282
|
2 |
|
return $this->proxy('setImage', $image); |
|
283
|
|
|
} |
|
284
|
|
|
|
|
285
|
2 |
|
public function getImage() |
|
286
|
|
|
{ |
|
287
|
2 |
|
return $this->proxy('getImage'); |
|
288
|
|
|
} |
|
289
|
|
|
|
|
290
|
|
|
public function getImages() |
|
291
|
|
|
{ |
|
292
|
|
|
return $this->proxy('getImages'); |
|
|
|
|
|
|
293
|
|
|
} |
|
294
|
|
|
|
|
295
|
|
|
public function setImages(\Core\Entity\ImageSet $images) |
|
296
|
|
|
{ |
|
297
|
|
|
return $this->proxy('setImages', $images); |
|
298
|
|
|
} |
|
299
|
|
|
|
|
300
|
2 |
|
public function setOrganizationName(OrganizationName $organizationNames) |
|
301
|
|
|
{ |
|
302
|
2 |
|
return $this->proxy('setOrganizationName', $organizationNames); |
|
303
|
|
|
} |
|
304
|
|
|
|
|
305
|
2 |
|
public function getOrganizationName() |
|
306
|
|
|
{ |
|
307
|
2 |
|
return $this->proxy('getOrganizationName'); |
|
|
|
|
|
|
308
|
|
|
} |
|
309
|
|
|
|
|
310
|
2 |
|
public function getDescription() |
|
311
|
|
|
{ |
|
312
|
2 |
|
return $this->proxy('getDescription'); |
|
|
|
|
|
|
313
|
|
|
} |
|
314
|
|
|
|
|
315
|
2 |
|
public function setDescription($description) |
|
316
|
|
|
{ |
|
317
|
2 |
|
return $this->proxy('setDescription', $description); |
|
318
|
|
|
} |
|
319
|
|
|
|
|
320
|
2 |
|
public function setEmployees(Collection $employees) |
|
321
|
|
|
{ |
|
322
|
2 |
|
return $this->proxy('setEmployees', $employees); |
|
323
|
|
|
} |
|
324
|
|
|
|
|
325
|
2 |
|
public function getEmployees() |
|
326
|
|
|
{ |
|
327
|
2 |
|
return $this->proxy('getEmployees'); |
|
|
|
|
|
|
328
|
|
|
} |
|
329
|
|
|
|
|
330
|
|
|
public function getEmployeesByRole($role) |
|
331
|
|
|
{ |
|
332
|
|
|
return $this->proxy('getEmployeesByRole', $role); |
|
|
|
|
|
|
333
|
|
|
} |
|
334
|
|
|
|
|
335
|
2 |
|
public function getEmployee($userOrId) |
|
336
|
|
|
{ |
|
337
|
2 |
|
return $this->proxy('getEmployee', $userOrId); |
|
|
|
|
|
|
338
|
|
|
} |
|
339
|
|
|
|
|
340
|
2 |
|
public function setExternalId($externalId) |
|
341
|
|
|
{ |
|
342
|
2 |
|
return $this->proxy('setExternalId', $externalId); |
|
343
|
|
|
} |
|
344
|
|
|
|
|
345
|
2 |
|
public function getExternalId() |
|
346
|
|
|
{ |
|
347
|
2 |
|
return $this->proxy('getExternalId'); |
|
|
|
|
|
|
348
|
|
|
} |
|
349
|
|
|
|
|
350
|
2 |
|
public function getUser() |
|
351
|
|
|
{ |
|
352
|
2 |
|
return $this->proxy('getUser'); |
|
|
|
|
|
|
353
|
|
|
} |
|
354
|
|
|
|
|
355
|
2 |
|
public function setUser(UserInterface $user) |
|
356
|
|
|
{ |
|
357
|
2 |
|
$this->_type = null; // force reload of references! |
|
358
|
2 |
|
return $this->proxy('setUser', $user); |
|
359
|
|
|
} |
|
360
|
|
|
|
|
361
|
2 |
|
public function getJobs() |
|
362
|
|
|
{ |
|
363
|
2 |
|
return $this->proxy('getJobs'); |
|
|
|
|
|
|
364
|
|
|
} |
|
365
|
|
|
|
|
366
|
2 |
|
public function getPermissions() |
|
367
|
|
|
{ |
|
368
|
2 |
|
return $this->proxy('getPermissions'); |
|
|
|
|
|
|
369
|
|
|
} |
|
370
|
|
|
|
|
371
|
2 |
|
public function setPermissions(PermissionsInterface $permissions) |
|
372
|
|
|
{ |
|
373
|
2 |
|
return $this->proxy('setPermissions', $permissions); |
|
374
|
|
|
} |
|
375
|
|
|
|
|
376
|
2 |
|
public function getPermissionsResourceId() |
|
377
|
|
|
{ |
|
378
|
2 |
|
return $this->proxy('getPermissionsResourceId'); |
|
379
|
|
|
} |
|
380
|
|
|
|
|
381
|
2 |
|
public function getPermissionsUserIds($type = null) |
|
382
|
|
|
{ |
|
383
|
2 |
|
return $this->proxy('getPermissionsUSerIds', $type); |
|
384
|
|
|
} |
|
385
|
|
|
|
|
386
|
2 |
|
public function getSearchableProperties() |
|
387
|
|
|
{ |
|
388
|
2 |
|
return $this->proxy('getSearchableProperties'); |
|
389
|
|
|
} |
|
390
|
|
|
|
|
391
|
|
|
public function setKeywords(array $keywords) |
|
392
|
|
|
{ |
|
393
|
|
|
return $this->proxy('setKeywords', $keywords); |
|
394
|
|
|
} |
|
395
|
|
|
|
|
396
|
|
|
public function clearKeywords() |
|
397
|
|
|
{ |
|
398
|
|
|
return $this->proxy('clearKeywords'); |
|
399
|
|
|
} |
|
400
|
|
|
|
|
401
|
2 |
|
public function getTemplate() |
|
402
|
|
|
{ |
|
403
|
2 |
|
return $this->proxy('getTemplate'); |
|
|
|
|
|
|
404
|
|
|
} |
|
405
|
|
|
|
|
406
|
2 |
|
public function setTemplate(TemplateInterface $template) |
|
407
|
|
|
{ |
|
408
|
2 |
|
return $this->proxy('setTemplate', $template); |
|
409
|
|
|
} |
|
410
|
|
|
|
|
411
|
2 |
|
public function getWorkflowSettings() |
|
412
|
|
|
{ |
|
413
|
2 |
|
return $this->proxy('getWorkflowSettings'); |
|
|
|
|
|
|
414
|
|
|
} |
|
415
|
|
|
|
|
416
|
2 |
|
public function setWorkflowSettings($workflowSettings) |
|
417
|
|
|
{ |
|
418
|
2 |
|
return $this->proxy('setWorkflowSettings', $workflowSettings); |
|
419
|
|
|
} |
|
420
|
|
|
|
|
421
|
|
|
/**#@-*/ |
|
422
|
|
|
} |
|
423
|
|
|
|