1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* YAWIK |
4
|
|
|
* |
5
|
|
|
* @copyright (c) 2013 - 2016 Cross Solution (http://cross-solution.de) |
6
|
|
|
* @license MIT |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Organizations\Entity; |
10
|
|
|
|
11
|
|
|
use Auth\Entity\UserInterface; |
12
|
|
|
use Core\Entity\AbstractIdentifiableModificationDateAwareEntity as BaseEntity; |
13
|
|
|
use Core\Entity\Collection\ArrayCollection; |
14
|
|
|
use Core\Entity\DraftableEntityInterface; |
15
|
|
|
use Core\Entity\EntityInterface; |
16
|
|
|
use Core\Entity\Hydrator\EntityHydrator; |
17
|
|
|
use Core\Entity\ImageSet; |
18
|
|
|
use Core\Entity\Permissions; |
19
|
|
|
use Core\Entity\PermissionsInterface; |
20
|
|
|
use Doctrine\Common\Collections\Collection; |
21
|
|
|
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; |
22
|
|
|
use Zend\Hydrator\HydratorInterface; |
23
|
|
|
use Zend\Permissions\Acl\Resource\ResourceInterface; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* The organization. |
27
|
|
|
* |
28
|
|
|
* @ODM\Document(collection="organizations", repositoryClass="Organizations\Repository\Organization") |
29
|
|
|
* @ODM\HasLifecycleCallbacks |
30
|
|
|
* @ODM\Indexes({ |
31
|
|
|
* @ODM\Index(keys={ |
32
|
|
|
* "_organizationName"="text" |
33
|
|
|
* }, name="fulltext") |
34
|
|
|
* }) |
35
|
|
|
* |
36
|
|
|
* @todo write test |
37
|
|
|
* @author Mathias Weitz <[email protected]> |
38
|
|
|
* @author Mathias Gelhausen <[email protected]> |
39
|
|
|
* @author Anthonius Munthi <[email protected]> |
40
|
|
|
*/ |
41
|
|
|
class Organization extends BaseEntity implements |
|
|
|
|
42
|
|
|
OrganizationInterface, |
43
|
|
|
DraftableEntityInterface, |
44
|
|
|
ResourceInterface |
45
|
|
|
{ |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Always enabled even if there are no active jobs |
49
|
|
|
*/ |
50
|
|
|
const PROFILE_ALWAYS_ENABLE = 'always'; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Hide if there are no jobs available |
54
|
|
|
*/ |
55
|
|
|
const PROFILE_ACTIVE_JOBS = 'active-jobs'; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Always disabled profile |
59
|
|
|
*/ |
60
|
|
|
const PROFILE_DISABLED = 'disabled'; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Event name of post construct event. |
64
|
|
|
* |
65
|
|
|
* @var string |
66
|
|
|
*/ |
67
|
|
|
const postConstruct = 'postRepositoryConstruct'; |
|
|
|
|
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* externalId. Allows external applications to reference their primary key. |
71
|
|
|
* |
72
|
|
|
* @var string |
73
|
|
|
* @ODM\Field(type="string") |
74
|
|
|
* @ODM\Index |
75
|
|
|
*/ |
76
|
|
|
protected $externalId; |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* The actual name of the organization. |
80
|
|
|
* |
81
|
|
|
* @var \Organizations\Entity\OrganizationName |
82
|
|
|
* @ODM\ReferenceOne(targetDocument="\Organizations\Entity\OrganizationName", simple=true, cascade="persist") |
83
|
|
|
*/ |
84
|
|
|
protected $organizationName; |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Only for sorting/searching purposes |
88
|
|
|
* |
89
|
|
|
* @var string |
90
|
|
|
* @ODM\Field(type="string") |
91
|
|
|
*/ |
92
|
|
|
protected $_organizationName; |
|
|
|
|
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Assigned permissions. |
96
|
|
|
* |
97
|
|
|
* @var PermissionsInterface |
98
|
|
|
* @ODM\EmbedOne(targetDocument="\Core\Entity\Permissions") |
99
|
|
|
*/ |
100
|
|
|
protected $permissions; |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* primary logo of an organization |
104
|
|
|
* |
105
|
|
|
* @var \Organizations\Entity\OrganizationImage |
106
|
|
|
* @ODM\ReferenceOne(targetDocument="\Organizations\Entity\OrganizationImage", inversedBy="organization", simple=true, nullable="true", cascade={"all"}) |
107
|
|
|
*/ |
108
|
|
|
protected $image; |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* |
112
|
|
|
* |
113
|
|
|
* @ODM\EmbedOne(targetDocument="\Core\Entity\ImageSet") |
114
|
|
|
* @var ImageSet |
115
|
|
|
*/ |
116
|
|
|
protected $images; |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Flag indicating draft state of this job. |
120
|
|
|
* |
121
|
|
|
* @var bool |
122
|
|
|
* @ODM\Boolean |
123
|
|
|
*/ |
124
|
|
|
protected $isDraft = false; |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Organization contact data. |
128
|
|
|
* |
129
|
|
|
* @ODM\EmbedOne(targetDocument="\Organizations\Entity\OrganizationContact") |
130
|
|
|
*/ |
131
|
|
|
protected $contact; |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* The organizations' description. |
135
|
|
|
* |
136
|
|
|
* @var string |
137
|
|
|
* @ODM\Field(type="string") |
138
|
|
|
*/ |
139
|
|
|
protected $description; |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* The parent of this organization. |
143
|
|
|
* |
144
|
|
|
* @see setParent() |
145
|
|
|
* @var OrganizationInterface | null |
146
|
|
|
* @ODM\ReferenceOne(targetDocument="\Organizations\Entity\Organization", simple=true, nullable=true) |
147
|
|
|
* @since 0.18 |
148
|
|
|
*/ |
149
|
|
|
protected $parent; |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* The hiring organizations of this organization. |
153
|
|
|
* |
154
|
|
|
* @var Collection |
155
|
|
|
* @ODM\ReferenceMany( |
156
|
|
|
* targetDocument="Organizations\Entity\Organization", |
157
|
|
|
* repositoryMethod="getHiringOrganizationsCursor" |
158
|
|
|
* ) |
159
|
|
|
* @since 0.18 |
160
|
|
|
*/ |
161
|
|
|
protected $hiringOrganizations; |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* The associated employees (users) |
165
|
|
|
* |
166
|
|
|
* @ODM\EmbedMany(targetDocument="\Organizations\Entity\Employee") |
167
|
|
|
* @var Collection |
168
|
|
|
*/ |
169
|
|
|
protected $employees; |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* Jobs of this organization. |
173
|
|
|
* |
174
|
|
|
* @var Collection |
175
|
|
|
* @ODM\ReferenceMany(targetDocument="\Jobs\Entity\Job", simple=true, mappedBy="organization") |
176
|
|
|
* @since 0.18 |
177
|
|
|
*/ |
178
|
|
|
protected $jobs; |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* the owner of a Organization |
182
|
|
|
* |
183
|
|
|
* @var UserInterface $user |
184
|
|
|
* @ODM\ReferenceOne(targetDocument="\Auth\Entity\User", simple=true) |
185
|
|
|
* @ODM\Index |
186
|
|
|
*/ |
187
|
|
|
protected $user; |
188
|
|
|
|
189
|
|
|
/** |
190
|
|
|
* Default values of an organizations job template |
191
|
|
|
* |
192
|
|
|
* @var TemplateInterface; |
193
|
|
|
* @ODM\EmbedOne(targetDocument="\Organizations\Entity\Template") |
194
|
|
|
*/ |
195
|
|
|
protected $template; |
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* Default values Workflow |
199
|
|
|
* |
200
|
|
|
* @var WorkflowSettingsInterface $workflowSettings ; |
201
|
|
|
* @ODM\EmbedOne(targetDocument="\Organizations\Entity\WorkflowSettings") |
202
|
|
|
*/ |
203
|
|
|
protected $workflowSettings; |
204
|
|
|
|
205
|
|
|
/** |
206
|
|
|
* Profile Setting |
207
|
|
|
* @var string |
208
|
|
|
* @ODM\Field(type="string", nullable=true) |
209
|
|
|
*/ |
210
|
|
|
protected $profileSetting; |
211
|
|
|
|
212
|
|
|
/** |
213
|
|
|
* @return string |
214
|
|
|
*/ |
215
|
|
|
public function getProfileSetting() |
216
|
|
|
{ |
217
|
|
|
return $this->profileSetting; |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
/** |
221
|
|
|
* @param string $profileSetting |
222
|
|
|
* |
223
|
|
|
* @return $this |
224
|
|
|
*/ |
225
|
|
|
public function setProfileSetting($profileSetting) |
226
|
|
|
{ |
227
|
|
|
$this->profileSetting = $profileSetting; |
228
|
|
|
|
229
|
|
|
return $this; |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
/** |
233
|
|
|
* Returns the string identifier of the Resource |
234
|
|
|
* |
235
|
|
|
* @return string |
236
|
|
|
*/ |
237
|
|
|
public function getResourceId() |
238
|
|
|
{ |
239
|
|
|
return 'Entity/Organization'; |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
/** |
243
|
|
|
* Gets the organization name |
244
|
|
|
* |
245
|
|
|
* @return string |
246
|
|
|
*/ |
247
|
|
|
public function getName() |
248
|
|
|
{ |
249
|
|
|
if (empty($this->organizationName)) { |
250
|
|
|
return ''; |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
return $this->organizationName->getName(); |
254
|
|
|
} |
255
|
|
|
|
256
|
|
|
/** |
257
|
|
|
* Sets the parent of an organization |
258
|
|
|
* |
259
|
|
|
* @param OrganizationInterface $parent |
260
|
|
|
* |
261
|
|
|
* @return $this |
262
|
|
|
*/ |
263
|
|
|
public function setParent(OrganizationInterface $parent) |
264
|
|
|
{ |
265
|
|
|
$this->parent = $parent; |
266
|
|
|
|
267
|
|
|
return $this; |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
/** |
271
|
|
|
* @deprecated |
272
|
|
|
* @return array |
273
|
|
|
*/ |
274
|
|
|
public function getSearchableProperties() |
275
|
|
|
{ |
276
|
|
|
return array(); |
277
|
|
|
} |
278
|
|
|
|
279
|
|
|
/** |
280
|
|
|
* Gets the parent of an organization |
281
|
|
|
* |
282
|
|
|
* @param bool $returnSelf returns itself, if this organization does not have a parent? |
283
|
|
|
* |
284
|
|
|
* @return null|OrganizationInterface |
285
|
|
|
*/ |
286
|
|
|
public function getParent($returnSelf = false) |
287
|
|
|
{ |
288
|
|
|
return $this->parent ? : ($returnSelf ? $this : null); |
289
|
|
|
} |
290
|
|
|
|
291
|
|
|
/** |
292
|
|
|
* Gets the Draft flag |
293
|
|
|
* |
294
|
|
|
* @return bool |
295
|
|
|
*/ |
296
|
|
|
public function isDraft() |
297
|
|
|
{ |
298
|
|
|
return $this->isDraft; |
299
|
|
|
} |
300
|
|
|
|
301
|
|
|
/** |
302
|
|
|
* Gets linked organizations |
303
|
|
|
* |
304
|
|
|
* @return Collection |
305
|
|
|
*/ |
306
|
|
|
public function getHiringOrganizations() |
307
|
|
|
{ |
308
|
|
|
return $this->hiringOrganizations; |
309
|
|
|
} |
310
|
|
|
|
311
|
|
|
/** |
312
|
|
|
* Sets the draft flag |
313
|
|
|
* |
314
|
|
|
* @param bool $flag |
315
|
|
|
* |
316
|
|
|
* @return $this |
317
|
|
|
*/ |
318
|
|
|
public function setIsDraft($flag) |
319
|
|
|
{ |
320
|
|
|
$this->isDraft = (bool) $flag; |
321
|
|
|
|
322
|
|
|
return $this; |
323
|
|
|
} |
324
|
|
|
|
325
|
|
|
/** |
326
|
|
|
* @return bool |
327
|
|
|
*/ |
328
|
|
|
public function isHiringOrganization() |
329
|
|
|
{ |
330
|
|
|
return null !== $this->parent; |
331
|
|
|
} |
332
|
|
|
|
333
|
|
|
/** |
334
|
|
|
* Returns true, if the user belongs to the organization. |
335
|
|
|
* |
336
|
|
|
* @param UserInterface $user |
337
|
|
|
* |
338
|
|
|
* @return bool |
339
|
|
|
*/ |
340
|
|
|
public function isAssociated(UserInterface $user) |
341
|
|
|
{ |
342
|
|
|
return $this->isOwner($user) || $this->isEmployee($user); |
343
|
|
|
} |
344
|
|
|
|
345
|
|
|
/** |
346
|
|
|
* Sets the external id. |
347
|
|
|
* |
348
|
|
|
* @param $externalId |
349
|
|
|
* |
350
|
|
|
* @return self |
351
|
|
|
*/ |
352
|
|
|
public function setExternalId($externalId) |
353
|
|
|
{ |
354
|
|
|
$this->externalId = $externalId; |
355
|
|
|
|
356
|
|
|
return $this; |
357
|
|
|
} |
358
|
|
|
|
359
|
|
|
/** |
360
|
|
|
* Checks, if a User is the owner of an organization |
361
|
|
|
* |
362
|
|
|
* @param UserInterface $user |
363
|
|
|
* |
364
|
|
|
* @return bool |
365
|
|
|
*/ |
366
|
|
|
public function isOwner(UserInterface $user) |
367
|
|
|
{ |
368
|
|
|
return $this->getUser()->getId() == $user->getId(); |
369
|
|
|
} |
370
|
|
|
|
371
|
|
|
/** |
372
|
|
|
* Gets the internal id. |
373
|
|
|
* |
374
|
|
|
* @return string |
375
|
|
|
*/ |
376
|
|
|
public function getExternalId() |
377
|
|
|
{ |
378
|
|
|
return $this->externalId; |
379
|
|
|
} |
380
|
|
|
|
381
|
|
|
/** |
382
|
|
|
* Returns true, if a User is an employee of the organization |
383
|
|
|
* |
384
|
|
|
* @param UserInterface $user |
385
|
|
|
* |
386
|
|
|
* @return bool |
387
|
|
|
*/ |
388
|
|
|
public function isEmployee(UserInterface $user) |
389
|
|
|
{ |
390
|
|
|
return $this->refs && in_array($user->getId(), $this->refs->getEmployeeIds()); |
|
|
|
|
391
|
|
|
} |
392
|
|
|
|
393
|
|
|
/** |
394
|
|
|
* @todo review this |
395
|
|
|
* |
396
|
|
|
* @param HydratorInterface $hydrator |
397
|
|
|
* |
398
|
|
|
* @return $this |
399
|
|
|
*/ |
400
|
|
|
public function setHydrator(HydratorInterface $hydrator) |
401
|
|
|
{ |
402
|
|
|
return $this; |
403
|
|
|
} |
404
|
|
|
|
405
|
|
|
/** |
406
|
|
|
* Updates the organizationsPermissions to allow all employees to view this organization. |
407
|
|
|
* |
408
|
|
|
* In case of a HiringOrganization Permissions are granted to all employees of the parent |
409
|
|
|
* organization. |
410
|
|
|
* |
411
|
|
|
* @ODM\PreUpdate |
412
|
|
|
* @ODM\PrePersist |
413
|
|
|
* @since 0.18 |
414
|
|
|
*/ |
415
|
|
|
public function updatePermissions() |
416
|
|
|
{ |
417
|
|
|
if ($this->isHiringOrganization()) { |
418
|
|
|
$organization = $this->getParent(); |
419
|
|
|
$owner = $organization->getUser(); |
420
|
|
|
|
421
|
|
|
$this->setUser($owner); |
422
|
|
|
} else { |
423
|
|
|
$organization = $this; |
424
|
|
|
} |
425
|
|
|
|
426
|
|
|
/* @var $employees null | ArrayCollection | \Doctrine\ODM\MongoDB\PersistentCollection */ |
427
|
|
|
$employees = $organization->getEmployees(); |
428
|
|
|
|
429
|
|
|
$perms = $this->getPermissions(); |
430
|
|
|
|
431
|
|
|
foreach ($employees as $emp) { |
|
|
|
|
432
|
|
|
/* @var $emp \Organizations\Entity\Employee */ |
433
|
|
|
$perms->grant($emp->getUser(), PermissionsInterface::PERMISSION_CHANGE, false); |
|
|
|
|
434
|
|
|
} |
435
|
|
|
$perms->build(); |
436
|
|
|
} |
437
|
|
|
|
438
|
|
|
/** |
439
|
|
|
* * @todo review this |
440
|
|
|
* @return EntityHydrator |
441
|
|
|
*/ |
442
|
|
|
public function getHydrator() |
443
|
|
|
{ |
444
|
|
|
return new EntityHydrator(); |
445
|
|
|
} |
446
|
|
|
|
447
|
|
|
/** |
448
|
|
|
* Sets the name of an organization |
449
|
|
|
* |
450
|
|
|
* @param OrganizationName $organizationName |
451
|
|
|
* |
452
|
|
|
* @return $this |
453
|
|
|
*/ |
454
|
|
|
public function setOrganizationName(OrganizationName $organizationName) |
455
|
|
|
{ |
456
|
|
|
if (isset($this->organizationName)) { |
457
|
|
|
$this->organizationName->refCounterDec()->refCompanyCounterDec(); |
458
|
|
|
} |
459
|
|
|
$this->organizationName = $organizationName; |
460
|
|
|
$this->organizationName->refCounterInc()->refCompanyCounterInc(); |
461
|
|
|
$this->_organizationName = $organizationName->getName(); |
462
|
|
|
|
463
|
|
|
return $this; |
464
|
|
|
} |
465
|
|
|
|
466
|
|
|
/** |
467
|
|
|
* Gets the organization name entity of an organisation |
468
|
|
|
* |
469
|
|
|
* @return OrganizationName |
470
|
|
|
*/ |
471
|
|
|
public function getOrganizationName() |
472
|
|
|
{ |
473
|
|
|
return $this->organizationName; |
474
|
|
|
} |
475
|
|
|
|
476
|
|
|
/** |
477
|
|
|
* Gets the Permissions of an organization |
478
|
|
|
* |
479
|
|
|
* @return PermissionsInterface |
480
|
|
|
*/ |
481
|
|
|
public function getPermissions() |
482
|
|
|
{ |
483
|
|
|
if (!$this->permissions) { |
484
|
|
|
$permissions = new Permissions(); |
485
|
|
|
if ($this->user) { |
486
|
|
|
$permissions->grant($this->user, Permissions::PERMISSION_ALL); |
487
|
|
|
} |
488
|
|
|
$this->setPermissions($permissions); |
489
|
|
|
} |
490
|
|
|
|
491
|
|
|
return $this->permissions; |
492
|
|
|
} |
493
|
|
|
|
494
|
|
|
/** |
495
|
|
|
* Sets the Permissions of an Organization |
496
|
|
|
* |
497
|
|
|
* @param PermissionsInterface $permissions |
498
|
|
|
* |
499
|
|
|
* @return $this |
500
|
|
|
*/ |
501
|
|
View Code Duplication |
public function setPermissions(PermissionsInterface $permissions) |
|
|
|
|
502
|
|
|
{ |
503
|
|
|
// Assure the user has always all rights. |
504
|
|
|
if ($this->user) { |
505
|
|
|
$permissions->grant($this->user, Permissions::PERMISSION_ALL); |
506
|
|
|
} |
507
|
|
|
$this->permissions = $permissions; |
508
|
|
|
|
509
|
|
|
return $this; |
510
|
|
|
} |
511
|
|
|
|
512
|
|
|
/** |
513
|
|
|
* Gets the Permissions Resource ID |
514
|
|
|
* |
515
|
|
|
* @return string |
516
|
|
|
*/ |
517
|
|
|
public function getPermissionsResourceId() |
518
|
|
|
{ |
519
|
|
|
return 'organization:' . $this->getId(); |
520
|
|
|
} |
521
|
|
|
|
522
|
|
|
/** |
523
|
|
|
* @param null $type |
524
|
|
|
* |
525
|
|
|
* @return array |
526
|
|
|
*/ |
527
|
|
|
public function getPermissionsUserIds($type = null) |
528
|
|
|
{ |
529
|
|
|
// if we have a user, grant him full access to all associated permissions. |
530
|
|
|
$user = $this->getUser(); |
531
|
|
|
$spec = $user |
532
|
|
|
? $spec = array(PermissionsInterface::PERMISSION_ALL => array($this->getUser()->getId())) |
533
|
|
|
: array(); |
534
|
|
|
|
535
|
|
|
if (null === $type || ('Job/Permissions' != $type && 'Application' != $type)) { |
536
|
|
|
return $spec; |
537
|
|
|
} |
538
|
|
|
|
539
|
|
|
if ('Job/Permissions' == $type) { |
540
|
|
|
$change = EmployeePermissionsInterface::JOBS_CHANGE; |
541
|
|
|
$view = EmployeePermissionsInterface::JOBS_VIEW; |
542
|
|
|
} else { |
543
|
|
|
$change = EmployeePermissionsInterface::APPLICATIONS_CHANGE; |
544
|
|
|
$view = EmployeePermissionsInterface::APPLICATIONS_VIEW; |
545
|
|
|
} |
546
|
|
|
|
547
|
|
|
$employees = $this->isHiringOrganization() |
548
|
|
|
? $this->getParent()->getEmployees() |
549
|
|
|
: $this->getEmployees(); |
550
|
|
|
|
551
|
|
|
foreach ($employees as $emp) { |
552
|
|
|
/* @var $emp EmployeeInterface */ |
553
|
|
|
if ($emp->isUnassigned()) { |
554
|
|
|
continue; |
555
|
|
|
} |
556
|
|
|
|
557
|
|
|
$perm = $emp->getPermissions(); |
558
|
|
|
if ($perm->isAllowed($change)) { |
559
|
|
|
$spec[PermissionsInterface::PERMISSION_CHANGE][] = $emp->getUser()->getId(); |
560
|
|
|
} elseif ($perm->isAllowed($view)) { |
561
|
|
|
$spec[PermissionsInterface::PERMISSION_VIEW][] = $emp->getUser()->getId(); |
562
|
|
|
} |
563
|
|
|
} |
564
|
|
|
|
565
|
|
|
return $spec; |
566
|
|
|
} |
567
|
|
|
|
568
|
|
|
/** |
569
|
|
|
* Sets the logo of an organization |
570
|
|
|
* |
571
|
|
|
* @param OrganizationImage $image |
|
|
|
|
572
|
|
|
* |
573
|
|
|
* @return self |
574
|
|
|
* @deprecated since 0.29; use $this->getImages()->set() |
575
|
|
|
*/ |
576
|
|
|
public function setImage(OrganizationImage $image = null) |
577
|
|
|
{ |
578
|
|
|
$this->image = $image; |
579
|
|
|
|
580
|
|
|
return $this; |
581
|
|
|
} |
582
|
|
|
|
583
|
|
|
/** |
584
|
|
|
* Gets the Logo of an organization |
585
|
|
|
* |
586
|
|
|
* @param string|bool $key Key of the image to get. |
587
|
|
|
* If true: get Thumbnail |
588
|
|
|
* If false: get Original |
589
|
|
|
* |
590
|
|
|
* @return OrganizationImage |
591
|
|
|
* @deprecated since 0.29; use $this->getImages()->get() |
592
|
|
|
* @since 0.29 modified to return images from the image set for compatibility reasons |
593
|
|
|
*/ |
594
|
|
|
public function getImage($key = ImageSet::ORIGINAL) |
595
|
|
|
{ |
596
|
|
|
if (is_bool($key)) { |
597
|
|
|
$key = $key ? ImageSet::THUMBNAIL : ImageSet::ORIGINAL; |
598
|
|
|
} |
599
|
|
|
|
600
|
|
|
return $this->getImages()->get($key, false) ?: $this->image; |
601
|
|
|
} |
602
|
|
|
|
603
|
|
|
/** |
604
|
|
|
* @param ImageSet $images |
605
|
|
|
* |
606
|
|
|
* @return self |
607
|
|
|
*/ |
608
|
|
|
public function setImages(ImageSet $images) |
609
|
|
|
{ |
610
|
|
|
$this->images = $images; |
611
|
|
|
|
612
|
|
|
return $this; |
613
|
|
|
} |
614
|
|
|
|
615
|
|
|
/** |
616
|
|
|
* @return ImageSet |
617
|
|
|
*/ |
618
|
|
|
public function getImages() |
619
|
|
|
{ |
620
|
|
|
if (!$this->images) { |
621
|
|
|
$this->images = new ImageSet(); |
622
|
|
|
} |
623
|
|
|
|
624
|
|
|
return $this->images; |
625
|
|
|
} |
626
|
|
|
|
627
|
|
|
/** |
628
|
|
|
* |
629
|
|
|
* |
630
|
|
|
* @return self |
631
|
|
|
*/ |
632
|
|
|
public function removeImages() |
633
|
|
|
{ |
634
|
|
|
$this->images = null; |
635
|
|
|
|
636
|
|
|
return $this; |
637
|
|
|
} |
638
|
|
|
|
639
|
|
|
/** |
640
|
|
|
* Sets the Contact Data of an organization |
641
|
|
|
* |
642
|
|
|
* @param EntityInterface $contact |
|
|
|
|
643
|
|
|
* |
644
|
|
|
* @return $this |
645
|
|
|
*/ |
646
|
|
|
public function setContact(EntityInterface $contact = null) |
647
|
|
|
{ |
648
|
|
|
if (!$contact instanceof OrganizationContact) { |
649
|
|
|
$contact = new OrganizationContact($contact); |
|
|
|
|
650
|
|
|
} |
651
|
|
|
$this->contact = $contact; |
652
|
|
|
|
653
|
|
|
return $this; |
654
|
|
|
} |
655
|
|
|
|
656
|
|
|
/** |
657
|
|
|
* Gets the contact Data of an organization |
658
|
|
|
* |
659
|
|
|
* @return OrganizationContact |
660
|
|
|
*/ |
661
|
|
|
public function getContact() |
662
|
|
|
{ |
663
|
|
|
if (!$this->contact instanceof OrganizationContact) { |
664
|
|
|
$this->contact = new OrganizationContact(); |
665
|
|
|
} |
666
|
|
|
|
667
|
|
|
return $this->contact; |
668
|
|
|
} |
669
|
|
|
|
670
|
|
|
/** |
671
|
|
|
* Gets the default description of an organization. |
672
|
|
|
* |
673
|
|
|
* This description is used as the default of the company_description |
674
|
|
|
* used in a job template |
675
|
|
|
* |
676
|
|
|
* @return string |
677
|
|
|
*/ |
678
|
|
|
public function getDescription() |
679
|
|
|
{ |
680
|
|
|
return $this->description; |
681
|
|
|
} |
682
|
|
|
|
683
|
|
|
/** |
684
|
|
|
* Set the default description af an organization |
685
|
|
|
* |
686
|
|
|
* @param string $description |
687
|
|
|
* |
688
|
|
|
* @return $this |
689
|
|
|
*/ |
690
|
|
|
public function setDescription($description) |
691
|
|
|
{ |
692
|
|
|
$this->description = $description; |
693
|
|
|
|
694
|
|
|
return $this; |
695
|
|
|
} |
696
|
|
|
|
697
|
|
|
/** |
698
|
|
|
* Sets the the list of employees |
699
|
|
|
* |
700
|
|
|
* @param Collection $employees |
701
|
|
|
* |
702
|
|
|
* @return $this |
703
|
|
|
*/ |
704
|
|
|
public function setEmployees(Collection $employees) |
705
|
|
|
{ |
706
|
|
|
/* todo: Throw exception or at least log incidents, where employees are added to "hiring orgs" */ |
707
|
|
|
if (!$this->isHiringOrganization()) { |
708
|
|
|
$this->employees = $employees; |
709
|
|
|
} |
710
|
|
|
|
711
|
|
|
return $this; |
712
|
|
|
} |
713
|
|
|
|
714
|
|
|
/** |
715
|
|
|
* Gets the list of employees |
716
|
|
|
* |
717
|
|
|
* @return ArrayCollection|Collection |
718
|
|
|
*/ |
719
|
|
|
public function getEmployees() |
720
|
|
|
{ |
721
|
|
|
if ($this->isHiringOrganization()) { |
722
|
|
|
// Always return empty list, as we never have employees in this case. |
723
|
|
|
return new ArrayCollection(); |
724
|
|
|
} |
725
|
|
|
|
726
|
|
|
if (!$this->employees) { |
727
|
|
|
$this->setEmployees(new ArrayCollection()); |
728
|
|
|
} |
729
|
|
|
|
730
|
|
|
return $this->employees; |
731
|
|
|
} |
732
|
|
|
|
733
|
|
|
/** |
734
|
|
|
* Gets an employee by User or ID. |
735
|
|
|
* |
736
|
|
|
* @param UserInterface|string $userOrId |
737
|
|
|
* |
738
|
|
|
* @return mixed|null |
739
|
|
|
*/ |
740
|
|
|
public function getEmployee($userOrId) |
741
|
|
|
{ |
742
|
|
|
$employees = $this->getEmployees(); |
743
|
|
|
$userId = $userOrId instanceof \Auth\Entity\UserInterface ? $userOrId->getId() : $userOrId; |
744
|
|
|
|
745
|
|
|
foreach ($employees as $employee) { |
746
|
|
|
if ($employee->getUser()->getId() == $userId) { |
747
|
|
|
return $employee; |
748
|
|
|
} |
749
|
|
|
} |
750
|
|
|
|
751
|
|
|
return null; |
752
|
|
|
} |
753
|
|
|
|
754
|
|
|
/** |
755
|
|
|
* Gets a list of Employees by a user role |
756
|
|
|
* |
757
|
|
|
* @param string $role |
758
|
|
|
* |
759
|
|
|
* @return ArrayCollection |
760
|
|
|
*/ |
761
|
|
|
public function getEmployeesByRole($role) |
762
|
|
|
{ |
763
|
|
|
$employees = new ArrayCollection(); |
764
|
|
|
|
765
|
|
|
/* @var \Organizations\Entity\Employee $employee */ |
766
|
|
|
foreach ($this->getEmployees() as $employee) { |
767
|
|
|
if ($role === $employee->getRole()) { |
768
|
|
|
$employees->add($employee); |
769
|
|
|
} |
770
|
|
|
} |
771
|
|
|
|
772
|
|
|
return $employees; |
773
|
|
|
} |
774
|
|
|
|
775
|
|
View Code Duplication |
public function setUser(UserInterface $user) |
|
|
|
|
776
|
|
|
{ |
777
|
|
|
if ($this->user) { |
778
|
|
|
$this->getPermissions()->revoke($this->user, Permissions::PERMISSION_ALL, false); |
|
|
|
|
779
|
|
|
} |
780
|
|
|
$this->user = $user; |
781
|
|
|
$this->getPermissions()->grant($user, Permissions::PERMISSION_ALL); |
782
|
|
|
|
783
|
|
|
return $this; |
784
|
|
|
} |
785
|
|
|
|
786
|
|
|
/** |
787
|
|
|
* Gets the owner of the organization |
788
|
|
|
* |
789
|
|
|
* @return UserInterface |
790
|
|
|
*/ |
791
|
|
|
public function getUser() |
792
|
|
|
{ |
793
|
|
|
return $this->user; |
794
|
|
|
} |
795
|
|
|
|
796
|
|
|
/** |
797
|
|
|
* Gets the Jobs of an organization |
798
|
|
|
* |
799
|
|
|
* @return Collection |
800
|
|
|
*/ |
801
|
|
|
public function getJobs() |
802
|
|
|
{ |
803
|
|
|
return $this->jobs; |
804
|
|
|
} |
805
|
|
|
|
806
|
|
|
/** |
807
|
|
|
* Gets default values of an organizations job template |
808
|
|
|
* |
809
|
|
|
* @return TemplateInterface |
810
|
|
|
*/ |
811
|
|
|
public function getTemplate() |
812
|
|
|
{ |
813
|
|
|
if (null === $this->template) { |
814
|
|
|
$this->template = new Template(); |
815
|
|
|
} |
816
|
|
|
|
817
|
|
|
return $this->template; |
818
|
|
|
} |
819
|
|
|
|
820
|
|
|
/** |
821
|
|
|
* Sets default values of an organizations job template |
822
|
|
|
* |
823
|
|
|
* @return self |
824
|
|
|
*/ |
825
|
|
|
public function setTemplate(TemplateInterface $template) |
826
|
|
|
{ |
827
|
|
|
$this->template = $template; |
828
|
|
|
|
829
|
|
|
return $this; |
830
|
|
|
} |
831
|
|
|
|
832
|
|
|
/** |
833
|
|
|
* Gets Workflow Settings |
834
|
|
|
* |
835
|
|
|
* @return WorkflowSettings|WorkflowSettingsInterface |
836
|
|
|
*/ |
837
|
|
|
public function getWorkflowSettings() |
838
|
|
|
{ |
839
|
|
|
if (null == $this->workflowSettings) { |
840
|
|
|
$this->workflowSettings = new WorkflowSettings(); |
841
|
|
|
} |
842
|
|
|
|
843
|
|
|
return $this->workflowSettings; |
844
|
|
|
} |
845
|
|
|
|
846
|
|
|
/** |
847
|
|
|
* Sets Workflow Settings |
848
|
|
|
* |
849
|
|
|
* @param $workflowSettings |
850
|
|
|
* |
851
|
|
|
* @return self |
852
|
|
|
*/ |
853
|
|
|
public function setWorkflowSettings($workflowSettings) |
854
|
|
|
{ |
855
|
|
|
$this->workflowSettings = $workflowSettings; |
856
|
|
|
|
857
|
|
|
return $this; |
858
|
|
|
} |
859
|
|
|
} |
860
|
|
|
|
This check marks property names that have not been written in camelCase.
In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes
databaseConnectionString
.