Completed
Push — master ( 2febf5...1f191a )
by Mathias
15:59
created

Job::getLocations()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 10
cc 2
nc 2
nop 0
crap 2
1
<?php
2
/**
3
 * YAWIK
4
 *
5
 * @copyright https://yawik.org/COPYRIGHT.php
6
 * @license   MIT
7
 */
8
9
namespace Jobs\Entity;
10
11
use Core\Entity\AbstractIdentifiableModificationDateAwareEntity as BaseEntity;
12
use Core\Entity\ClonePropertiesTrait;
13
use Core\Entity\AttachableEntityTrait;
14
use Core\Entity\EntityInterface;
15
use Core\Entity\MetaDataProviderTrait;
16
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
17
use Doctrine\Common\Collections\Collection;
18
use Auth\Entity\UserInterface;
19
use Core\Entity\Permissions;
20
use Core\Entity\PermissionsInterface;
21
use Organizations\Entity\OrganizationInterface;
22
use Core\Entity\DraftableEntityInterface;
23
use Core\Entity\Collection\ArrayCollection;
24
use Core\Entity\SnapshotGeneratorProviderInterface;
25
use Laminas\I18n\Validator\DateTime;
26
27
/**
28
 * The job model
29
 *
30
 * @ODM\Document(collection="jobs", repositoryClass="Jobs\Repository\Job")
31
 * @ODM\Indexes({
32
 *     @ODM\Index(keys={"datePublishStart.date"="asc"})
33
 * })
34
 *
35
 * @author Mathias Gelhausen <[email protected]>
36
 * @author Mathias Weitz <[email protected]>
37
 * @author Carsten Bleek <[email protected]>
38
 * @since 0.29 add temporary isDeleted flag and corresponding delete() method.
39
 */
40
class Job extends BaseEntity implements
41
    JobInterface,
42
                                        DraftableEntityInterface,
43
                                        SnapshotGeneratorProviderInterface
44
{
45
    use AttachableEntityTrait, MetaDataProviderTrait, ClonePropertiesTrait;
46
47
48
    private $cloneProperties = [
0 ignored issues
show
introduced by
The private property $cloneProperties is not used, and could be removed.
Loading history...
49
        'classifications', 'atsMode', 'salary',
50
    ];
51
52
    /**
53
     * unique ID of a job posting used by applications to reference
54
     * a job
55
     *
56
     * @var String
57
     * @ODM\Field(type="string") @ODM\Index
58
     **/
59
    protected $applyId;
60
61
    /**
62
     * title of a job posting
63
     *
64
     * @var String
65
     * @ODM\Field(type="string")
66
     */
67
    protected $title;
68
69
70
    /**
71
     * name of the publishing company
72
     *
73
     * @var String
74
     * @ODM\Field(type="string")
75
     */
76
    protected $company;
77
78
    /**
79
     * publishing company
80
     *
81
     * @var OrganizationInterface
82
     * @ODM\ReferenceOne (targetDocument="\Organizations\Entity\Organization", storeAs="id", inversedBy="jobs")
83
     * @ODM\Index
84
     */
85
    protected $organization;
86
87
88
    /**
89
     * Email Address, which is used to send notifications about e.g. new applications.
90
     *
91
     * @var String
92
     * @ODM\Field(type="string")
93
     **/
94
    protected $contactEmail;
95
96
    /**
97
     * the owner of a Job Posting
98
     *
99
     * @var UserInterface $user
100
     * @ODM\ReferenceOne(targetDocument="\Auth\Entity\User", storeAs="id")
101
     * @ODM\Index
102
     */
103
    protected $user;
104
105
    /**
106
     * all applications of a certain jobad
107
     *
108
     * @var Collection
109
     * @ODM\ReferenceMany(targetDocument="Applications\Entity\Application", storeAs="id", mappedBy="job",
110
     *                    repositoryMethod="loadApplicationsForJob")
111
     */
112
    protected $applications;
113
114
    /**
115
     * new applications
116
     *
117
     * @ODM\ReferenceMany(targetDocument="Applications\Entity\Application",
118
     *                    repositoryMethod="loadUnreadApplicationsForJob", mappedBy="job")
119
     * @var Int
120
     */
121
    protected $unreadApplications;
122
123
    /**
124
     * language of the job posting. Languages are ISO 639-1 coded
125
     *
126
     * @var String
127
     * @ODM\Field(type="string")
128
     */
129
    protected $language;
130
131
    /**
132
     * location of the job posting. This is a plain text, which describes the location in
133
     * search e.g. results.
134
     *
135
     * @var String
136
     * @ODM\Field(type="string")
137
     */
138
    protected $location;
139
140
    /**
141
     * locations of the job posting. This collection contains structured coordinates,
142
     * postal codes, city, region, and country names
143
     *
144
     * @var Collection
145
     * @ODM\EmbedMany(targetDocument="Location")
146
     */
147
    protected $locations;
148
149
    /**
150
     * Link which points to the job posting
151
     *
152
     * @var String
153
     * @ODM\Field(type="string")
154
     **/
155
    protected $link;
156
157
    /**
158
     * publishing date of a job posting
159
     *
160
     * @var String
161
     * @ODM\Field(type="tz_date")
162
     */
163
    protected $datePublishStart;
164
165
    /**
166
     * end date of a job posting
167
     *
168
     * @var String
169
     * @ODM\Field(type="tz_date")
170
     */
171
    protected $datePublishEnd;
172
173
    /**
174
     * Status of the job posting
175
     *
176
     * @var Status
177
     * @ODM\EmbedOne(targetDocument="Status")
178
     * @ODM\Index
179
     */
180
    protected $status;
181
182
    /**
183
     * History on an job posting
184
     *
185
     * @var Collection
186
     * @ODM\EmbedMany(targetDocument="History")
187
     */
188
    protected $history;
189
190
    /**
191
     * Flag, privacy policy is accepted or not.
192
     *
193
     * @var bool
194
     * @ODM\Field(type="boolean")
195
     */
196
    protected $termsAccepted;
197
198
    /**
199
     * Reference of a job opening, on which an applicant can refer to.
200
     *
201
     * @var String
202
     * @ODM\Field(type="string")
203
     */
204
    protected $reference;
205
206
    /**
207
     * Unified Resource Locator to the company-Logo
208
     *
209
     * @var String
210
     * @ODM\Field(type="string")
211
     */
212
    protected $logoRef;
213
214
    /**
215
     * Template-Name
216
     *
217
     * @var String
218
     * @ODM\Field(type="string")
219
     */
220
    protected $template;
221
222
    /**
223
     * Application link.
224
     *
225
     * @var String
226
     * @ODM\Field(type="string")
227
     */
228
    protected $uriApply;
229
230
    /**
231
     * Unified Resource Locator the Yawik, which handled this job first - so
232
     * does know who is the one who has commited this job.
233
     *
234
     * @var String
235
     * @ODM\Field(type="string")
236
     */
237
    protected $uriPublisher;
238
239
    /**
240
     * @var
241
     * @ODM\EmbedMany(targetDocument="Publisher")
242
     */
243
    protected $publisher;
244
245
    /**
246
     * The ATS mode entity.
247
     *
248
     * @var AtsMode
249
     * @ODM\EmbedOne(targetDocument="AtsMode")
250
     */
251
    protected $atsMode;
252
253
    /**
254
     * this must be enabled to use applications forms etc. for this job or
255
     * to see number of applications in the list of applications
256
     *
257
     * @var Boolean
258
     *
259
     * @ODM\Field(type="boolean")
260
     */
261
    protected $atsEnabled;
262
263
    /**
264
     * The Salary entity.
265
     *
266
     * @var Salary
267
     * @ODM\EmbedOne(targetDocument="\Jobs\Entity\Salary")
268
     */
269
    protected $salary;
270
271
    /**
272
     * Permissions
273
     *
274
     * @var PermissionsInterface
275
     * @ODM\EmbedOne(targetDocument="\Core\Entity\Permissions")
276
     */
277
    protected $permissions;
278
279
    /**
280
     * The actual name of the organization.
281
     *
282
     * @var TemplateValues
283
     * @ODM\EmbedOne(targetDocument="\Jobs\Entity\TemplateValues")
284
     */
285
    protected $templateValues;
286
287
288
    /**
289
     * Can contain various Portals
290
     *
291
     * @var array
292
     * @ODM\Field(type="collection")
293
     */
294
    protected $portals = array();
295
296
    /**
297
     * Flag indicating draft state of this job.
298
     *
299
     * @var bool
300
     * @ODM\Field(type="boolean")
301
     */
302
    protected $isDraft = false;
303
304
    /**
305
     * Classifications
306
     *
307
     * @ODM\EmbedOne(targetDocument="\Jobs\Entity\Classifications")
308
     * @var Classifications
309
     * @since 0.29
310
     */
311
    protected $classifications;
312
313
    /**
314
     * Delete flag.
315
     *
316
     * @internal
317
     *      This is meant as a temporary flag, until
318
     *      SoftDelete is implemented.
319
     *
320
     * @ODM\Field(type="boolean")
321
     * @var bool
322
     * @since 0.29
323
     */
324
    protected $isDeleted = false;
325
326
    /**
327
     *
328
     * @ODM\ReferenceMany(targetDocument="\Jobs\Entity\JobSnapshot", mappedBy="snapshotEntity", sort={"snapshotMeta.dateCreated"="desc"})
329
     * @var JobSnapshot[]
330
     */
331
    protected $snapshots;
332
333
    /**
334
     * @ODM\ReferenceOne(targetDocument="\Jobs\Entity\JobSnapshot", mappedBy="snapshotEntity", sort={"snapshotMeta.dateCreated"="desc"})
335
     *
336
     * @var JobSnapshot
337
     */
338
    protected $latestSnapshot;
339
340
341
    public function getSnapshots()
342
    {
343
        return $this->snapshots;
344
    }
345
346
    public function getLatestSnapshot()
347
    {
348
        return $this->latestSnapshot;
349
    }
350
351
    public function hasSnapshotDraft()
352
    {
353
        $snapshot = $this->getLatestSnapshot();
354
        return $snapshot && $snapshot->getSnapshotMeta()->hasStatus(JobSnapshotStatus::ACTIVE);
355
    }
356
357
    /**
358
     * @return string
359
     */
360 1
    public function getResourceId()
361
    {
362 1
        return 'Entity/Jobs/Job';
363
    }
364
365
    /**
366
     * @see \Jobs\Entity\JobInterface::setApplyId()
367
     * @param String $applyId
368
     * @return \Jobs\Entity\JobInterface
369
     */
370 1
    public function setApplyId($applyId)
371
    {
372 1
        $this->applyId = (string) $applyId;
373 1
        return $this;
374
    }
375
    /**
376
     * @see \Jobs\Entity\JobInterface::getApplyId()
377
     * @return String
378
     */
379 3
    public function getApplyId()
380
    {
381 3
        if (!isset($this->applyId)) {
382
            // take the entity-id as a default
383 2
            $this->applyId = $this->id;
384
        }
385 3
        return $this->applyId;
386
    }
387
388
    /**
389
     * Gets the title of a job posting
390
     *
391
     * @return string
392
     */
393 4
    public function getTitle()
394
    {
395 4
        return $this->title;
396
    }
397
398
    /**
399
     * Sets the title of a job posting
400
     *
401
     * @see \Jobs\Entity\JobInterface::setTitle()
402
     * @param String $title
403
     * @return \Jobs\Entity\JobInterface
404
     */
405 4
    public function setTitle($title)
406
    {
407 4
        $this->title = (string) $title;
408 4
        return $this;
409
    }
410
411
    /**
412
     * Gets the name oof the company. If there is an organization assigned to the
413
     * job posting. Take the name of the organization.
414
     *
415
     * @param bool $useOrganizationEntity Get the name from the organization entity, if it is available.
416
     * @see \Jobs\Entity\JobInterface::getCompany()
417
     * @return string
418
     */
419 4
    public function getCompany($useOrganizationEntity = true)
420
    {
421 4
        if ($this->organization && $useOrganizationEntity) {
422 1
            return $this->organization->getOrganizationName()->getName();
423
        }
424
425 3
        return $this->company;
426
    }
427
428
    /**
429
     * (non-PHPdoc)
430
     * @see \Jobs\Entity\JobInterface::setCompany()
431
     */
432 3
    public function setCompany($company)
433
    {
434 3
        $this->company = $company;
435 3
        return $this;
436
    }
437
438
    /**
439
    * (non-PHPdoc)
440
    * @see \Jobs\Entity\JobInterface::getOrganization()
441
    */
442 4
    public function getOrganization()
443
    {
444 4
        return $this->organization;
445
    }
446
447
    /**
448
     * @inheritdoc
449
     */
450 3
    public function setOrganization(OrganizationInterface $organization = null)
451
    {
452 3
        $permissions = $this->getPermissions();
453
454 3
        if ($this->organization) {
455
            $permissions->revoke($this->organization, null, false);
0 ignored issues
show
Unused Code introduced by
The call to Core\Entity\PermissionsInterface::revoke() has too many arguments starting with false. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

455
            $permissions->/** @scrutinizer ignore-call */ 
456
                          revoke($this->organization, null, false);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
456
        }
457 3
        $this->organization = $organization;
458 3
        $permissions->grant($organization);
459
460 3
        return $this;
461
    }
462
463
464
465
    /**
466
     * (non-PHPdoc)
467
     * @see \Jobs\Entity\JobInterface::getContactEmail()
468
     */
469 3
    public function getContactEmail()
470
    {
471 3
        if (false !== $this->contactEmail && !$this->contactEmail) {
472 2
            $user = $this->getUser();
473 2
            $email = false;
474 2
            if (isset($user)) {
475 1
                $email = $user->getInfo()->getEmail();
476
            }
477 2
            $this->setContactEmail($email);
478
        }
479 3
        return $this->contactEmail;
480
    }
481
482
    /**
483
     * (non-PHPdoc)
484
     * @see \Jobs\Entity\JobInterface::setContactEmail()
485
     */
486 3
    public function setContactEmail($email)
487
    {
488 3
        $this->contactEmail = (string) $email;
489 3
        return $this;
490
    }
491
492
    /**
493
     * (non-PHPdoc)
494
     * @see \Jobs\Entity\JobInterface::setLanguage()
495
     */
496 1
    public function setLanguage($language)
497
    {
498 1
        $this->language = $language;
499 1
        return $this;
500
    }
501
    /**
502
     * (non-PHPdoc)
503
     * @see \Jobs\Entity\JobInterface::getLanguage()
504
     */
505 2
    public function getLanguage()
506
    {
507 2
        return $this->language;
508
    }
509
    /**
510
     * (non-PHPdoc)
511
     * @see \Jobs\Entity\JobInterface::setLocation()
512
     */
513 1
    public function setLocation($location)
514
    {
515 1
        $this->location = $location;
516 1
        return $this;
517
    }
518
    /**
519
     * (non-PHPdoc)
520
     * @see \Jobs\Entity\JobInterface::getLocation()
521
     */
522 2
    public function getLocation()
523
    {
524 2
        if (null === $this->location) {
525 1
            $array=[];
526 1
            if (null != $this->locations) {
527
                foreach ($this->locations as $location) { /* @var \Core\Entity\LocationInterface $location */
528
                    $array[]=(string) $location;
529
                }
530
                return implode(', ', $array);
531
            }
532
        }
533 2
        return $this->location;
534
    }
535
    /**
536
     * (non-PHPdoc)
537
     * @see \Jobs\Entity\JobInterface::setLocations()
538
     */
539 3
    public function setLocations($locations)
540
    {
541 3
        $this->locations = $locations;
542 3
        return $this;
543
    }
544
    /**
545
     * (non-PHPdoc)
546
     * @see \Jobs\Entity\JobInterface::getLocations()
547
     */
548 3
    public function getLocations()
549
    {
550 3
        if (!$this->locations) {
551 2
            $this->setLocations(new ArrayCollection());
552
        }
553 3
        return $this->locations;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->locations returns the type Doctrine\Common\Collections\Collection which is incompatible with the return type mandated by Jobs\Entity\JobInterface::getLocations() of string.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
554
    }
555
    /**
556
     * (non-PHPdoc)
557
     * @see \Jobs\Entity\JobInterface::setUser()
558
     */
559 6
    public function setUser(UserInterface $user)
560
    {
561 6
        if ($this->user) {
562 1
            $this->getPermissions()->revoke($this->user, Permissions::PERMISSION_ALL, false);
0 ignored issues
show
Unused Code introduced by
The call to Core\Entity\PermissionsInterface::revoke() has too many arguments starting with false. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

562
            $this->getPermissions()->/** @scrutinizer ignore-call */ revoke($this->user, Permissions::PERMISSION_ALL, false);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
563
        }
564 6
        $this->user = $user;
565 6
        $this->getPermissions()->grant($user, Permissions::PERMISSION_ALL);
566 6
        return $this;
567
    }
568
    /**
569
     * (non-PHPdoc)
570
     * @see \Jobs\Entity\JobInterface::getUser()
571
     */
572 7
    public function getUser()
573
    {
574 7
        return $this->user;
575
    }
576
577 1
    public function unsetUser($removePermissions = true)
578
    {
579 1
        if ($this->user) {
580 1
            if ($removePermissions) {
581 1
                $this->getPermissions()->revoke($this->user, Permissions::PERMISSION_ALL);
582
            }
583 1
            $this->user=null;
584
        }
585
586 1
        return $this;
587
    }
588
589 1
    public function unsetOrganization($removePermissions = true)
590
    {
591 1
        if ($this->organization && $removePermissions) {
592 1
            $this->getPermissions()->revoke($this->organization, Permissions::PERMISSION_ALL);
593
        }
594
595 1
        $this->organization = null;
596
597 1
        return $this;
598
    }
599
600
    /**
601
     * (non-PHPdoc)
602
     * @see \Jobs\Entity\JobInterface::setApplications()
603
     */
604 1
    public function setApplications(Collection $applications)
605
    {
606 1
        $this->applications = $applications;
607 1
        return $this;
608
    }
609
610
    /**
611
     * (non-PHPdoc)
612
     * @see \Jobs\Entity\JobInterface::getApplications()
613
     */
614 2
    public function getApplications()
615
    {
616 2
        return $this->applications;
617
    }
618
619
    /**
620
     * Gets the number of unread applications
621
     * @return Collection
622
     */
623
    public function getUnreadApplications()
624
    {
625
        return $this->unreadApplications;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->unreadApplications returns the type integer which is incompatible with the documented return type Doctrine\Common\Collections\Collection.
Loading history...
626
    }
627
    /**
628
     * (non-PHPdoc)
629
     * @see \Jobs\Entity\JobInterface::getLink()
630
     */
631 2
    public function getLink()
632
    {
633 2
        return $this->link;
634
    }
635
    /**
636
     * (non-PHPdoc)
637
     * @see \Jobs\Entity\JobInterface::setLink()
638
     */
639 1
    public function setLink($link)
640
    {
641 1
        $this->link = $link;
642 1
        return $this;
643
    }
644
    /**
645
     * (non-PHPdoc)
646
     * @see \Jobs\Entity\JobInterface::getDatePublishStart()
647
     */
648 4
    public function getDatePublishStart()
649
    {
650 4
        return $this->datePublishStart;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->datePublishStart returns the type string which is incompatible with the return type mandated by Jobs\Entity\JobInterface::getDatePublishStart() of DateTime.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
651
    }
652
    /**
653
     * (non-PHPdoc)
654
     * @param string $datePublishStart
655
     * @see \Jobs\Entity\JobInterface::setDatePublishStart()
656
     * @return $this
657
     */
658 2
    public function setDatePublishStart($datePublishStart = null)
659
    {
660 2
        if (!isset($datePublishStart) || is_string($datePublishStart)) {
0 ignored issues
show
introduced by
The condition is_string($datePublishStart) is always true.
Loading history...
661 1
            $datePublishStart = new \DateTime($datePublishStart);
662 1
        } elseif (!$datePublishStart instanceof \DateTime) {
663
            throw new \InvalidArgumentException('Expected object of type \DateTime');
664
        }
665
666 2
        $this->datePublishStart = $datePublishStart;
0 ignored issues
show
Documentation Bug introduced by
It seems like $datePublishStart of type DateTime is incompatible with the declared type string of property $datePublishStart.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
667 2
        return $this;
668
    }
669
670
    /**
671
     * (non-PHPdoc)
672
     * @see \Jobs\Entity\JobInterface::getDatePublishStart()
673
     */
674 4
    public function getDatePublishEnd()
675
    {
676 4
        return $this->datePublishEnd;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->datePublishEnd returns the type string which is incompatible with the return type mandated by Jobs\Entity\JobInterface::getDatePublishEnd() of DateTime.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
677
    }
678
    /**
679
     * (non-PHPdoc)
680
     * @param string $datePublishEnd
681
     * @see \Jobs\Entity\JobInterface::setDatePublishEnd()
682
     * @return $this
683
     */
684 2
    public function setDatePublishEnd($datePublishEnd = null)
685
    {
686 2
        if (is_string($datePublishEnd)) {
687 1
            $datePublishEnd = new \DateTime($datePublishEnd);
688 1
        } elseif (!$datePublishEnd instanceof \DateTime) {
689
            throw new \InvalidArgumentException('Expected object of type \DateTime');
690
        }
691
692 2
        $this->datePublishEnd = $datePublishEnd;
0 ignored issues
show
Documentation Bug introduced by
It seems like $datePublishEnd of type DateTime is incompatible with the declared type string of property $datePublishEnd.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
693 2
        return $this;
694
    }
695
696
    /**
697
     * Modifies the state of an application.
698
     *
699
     * Creates a history entry.
700
     *
701
     * @param StatusInterface|string $status
702
     * @param string $message
703
     * @return Job
704
     */
705 6
    public function changeStatus($status, $message = '[System]')
706
    {
707 6
        $this->setStatus($status);
708 6
        $status = $this->getStatus(); // ensure StatusEntity
709
710 6
        $history = new History($status, $message);
711
712 6
        $this->getHistory()->add($history);
713 6
        return $this;
714
    }
715
716
    /**
717
     * (non-PHPdoc)
718
     * @see \Jobs\Entity\JobInterface::getStatus()
719
     */
720 13
    public function getStatus()
721
    {
722 13
        if (!$this->status) {
723 1
            $this->setStatus(StatusInterface::CREATED);
724
        }
725
726 13
        return $this->status;
727
    }
728
    /**
729
     * (non-PHPdoc)
730
     * @see \Jobs\Entity\JobInterface::setStatus()
731
     */
732 17
    public function setStatus($status)
733
    {
734 17
        if (!$status instanceof Status) {
735 11
            $status = new Status($status);
736
        }
737 17
        $this->status = $status;
738
    }
739
740
    /**
741
     * {@inheritDoc}
742
     * @see JobInterface::setHistory()
743
     * @return Job
744
     */
745 8
    public function setHistory(Collection $history)
746
    {
747 8
        $this->history = $history;
748 8
        return $this;
749
    }
750
751
    /**
752
     * {@inheritDoc}
753
     * @see JobInterface::getHistory()
754
     */
755 8
    public function getHistory()
756
    {
757 8
        if (null == $this->history) {
758 7
            $this->setHistory(new ArrayCollection());
759
        }
760 8
        return $this->history;
761
    }
762
763
    /**
764
     * {@inheritDoc}
765
     * @see JobInterface::setTermsAccepted()
766
     * @return self
767
     */
768 3
    public function setTermsAccepted($termsAccepted)
769
    {
770 3
        $this->termsAccepted = $termsAccepted;
771 3
        return $this;
772
    }
773
774
    /**
775
     * {qinheritDoc}
776
     * @see JobInterface::getTermsAccepted()
777
     */
778 4
    public function getTermsAccepted()
779
    {
780 4
        return $this->termsAccepted;
781
    }
782
783
    /**
784
     * (non-PHPdoc)
785
     * @see JobInterface::getReference()
786
     */
787 2
    public function getReference()
788
    {
789 2
        return $this->reference;
790
    }
791
    /**
792
     * (non-PHPdoc)
793
     * @see JobInterface::setReference()
794
     */
795 1
    public function setReference($reference)
796
    {
797 1
        $this->reference = $reference;
798 1
        return $this;
799
    }
800
801 6
    public function setAtsMode(AtsMode $mode)
802
    {
803 6
        $this->atsMode = $mode;
804
805 6
        return $this;
806
    }
807
808 6
    public function getAtsMode()
809
    {
810 6
        if (!$this->atsMode) {
811 2
            $this->setAtsMode(new AtsMode(AtsMode::MODE_INTERN));
812
        }
813
814 6
        return $this->atsMode;
815
    }
816
817
818
    /**
819
     * checks, weather a job is enabled for getting applications
820
     * @return boolean
821
     */
822 3
    public function getAtsEnabled()
823
    {
824 3
        return $this->atsEnabled;
825
    }
826
    /**
827
     * enables a job add to receive applications
828
     *
829
     * @param boolean $atsEnabled
830
     * @return \Jobs\Entity\Job
831
     */
832 2
    public function setAtsEnabled($atsEnabled)
833
    {
834 2
        $this->atsEnabled = $atsEnabled;
835 2
        return $this;
836
    }
837
838
    /**
839
     * @param \Jobs\Entity\Salary $salary
840
     *
841
     * @return self
842
     */
843 1
    public function setSalary(Salary $salary)
844
    {
845 1
        $this->salary = $salary;
846
847 1
        return $this;
848
    }
849
850
    /**
851
     * @return \Jobs\Entity\Salary
852
     */
853 1
    public function getSalary()
854
    {
855 1
        if (!$this->salary) {
856 1
            $this->setSalary(new Salary());
857
        }
858
859 1
        return $this->salary;
860
    }
861
862
    /**
863
     * returns an uri to the organization logo.
864
     *
865
     * @return string
866
     */
867 2
    public function getLogoRef()
868
    {
869
        /** @var $organization \Organizations\Entity\Organization */
870 2
        $organization = $this->organization;
871 2
        if (is_object($organization) && $organization->getImage()) {
0 ignored issues
show
Deprecated Code introduced by
The function Organizations\Entity\Organization::getImage() has been deprecated: since 0.29; use $this->getImages()->get() ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

871
        if (is_object($organization) && /** @scrutinizer ignore-deprecated */ $organization->getImage()) {

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
872
            $organizationImage = $organization->getImage();
0 ignored issues
show
Deprecated Code introduced by
The function Organizations\Entity\Organization::getImage() has been deprecated: since 0.29; use $this->getImages()->get() ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

872
            $organizationImage = /** @scrutinizer ignore-deprecated */ $organization->getImage();

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
873
            return "/file/Organizations.OrganizationImage/" . $organizationImage->getId();
874
        }
875 2
        return $this->logoRef;
876
    }
877
    /**
878
     * Set the uri to the organisations logo
879
     *
880
     * @param string $logoRef
881
     * @return \Jobs\Entity\Job
882
     */
883 1
    public function setLogoRef($logoRef)
884
    {
885 1
        $this->logoRef = $logoRef;
886 1
        return $this;
887
    }
888
889
    /**
890
     *
891
     *
892
     * @return string
893
     */
894 3
    public function getTemplate()
895
    {
896 3
        $template = $this->template;
897 3
        if (empty($template)) {
898 2
            $template = 'default';
899
        }
900 3
        return $template;
901
    }
902
    /**
903
     *
904
     *
905
     * @param string $template name of the Template
906
     * @return \Jobs\Entity\Job
907
     */
908 3
    public function setTemplate($template)
909
    {
910 3
        $this->template = $template;
911 3
        return $this;
912
    }
913
914
915
916
    /**
917
     * Gets the uri of an application link
918
     *
919
     * @return String
920
     */
921 2
    public function getUriApply()
922
    {
923 2
        return $this->uriApply;
924
    }
925
926
    /**
927
     * Sets the uri of an application link
928
     *
929
     * @param String $uriApply
930
     * @return \Jobs\Entity\Job
931
     */
932 1
    public function setUriApply($uriApply)
933
    {
934 1
        $this->uriApply = $uriApply;
935 1
        return $this;
936
    }
937
938
    /**
939
     * Gets the uri of a publisher
940
     *
941
     * @return String
942
     */
943 2
    public function getUriPublisher()
944
    {
945 2
        return $this->uriPublisher;
946
    }
947
    /**
948
     *
949
     * @param String $uriPublisher
950
     * @return \Jobs\Entity\Job
951
     */
952 1
    public function setUriPublisher($uriPublisher)
953
    {
954 1
        $this->uriPublisher = $uriPublisher;
955 1
        return $this;
956
    }
957
958
    /**
959
     * @param $key
960
     * @return mixed
961
     */
962
    public function getPublisher($key)
963
    {
964
        $result = null;
965
        foreach ($this->publisher as $publisher) {
966
            if ($publisher->host == $key) {
967
                $result = $publisher;
968
            }
969
        }
970
        if (!isset($result)) {
971
            $result = new Publisher();
972
            $result->host = $key;
0 ignored issues
show
Bug Best Practice introduced by
The property $host is declared protected in Jobs\Entity\Publisher. Since you implement __set, consider adding a @property or @property-write.
Loading history...
973
            $this->publisher[] = $result;
974
        }
975
        return $result;
976
    }
977
978
    public function setPublisherReference($key, $reference)
979
    {
980
        $publisher = $this->getPublisher($key);
981
        $publisher->reference;
982
        return $this;
983
    }
984
985
986
    /**
987
     * (non-PHPdoc)
988
     * @see \Core\Entity\PermissionsAwareInterface::getPermissions()
989
     */
990 10
    public function getPermissions()
991
    {
992 10
        if (!$this->permissions) {
993 10
            $permissions = new Permissions('Job/Permissions');
994 10
            if ($this->user) {
995 6
                $permissions->grant($this->user, Permissions::PERMISSION_ALL);
996
            }
997 10
            $this->setPermissions($permissions);
998
        }
999
1000 10
        return $this->permissions;
1001
    }
1002
1003
    /**
1004
     * (non-PHPdoc)
1005
     * @see \Core\Entity\PermissionsAwareInterface::setPermissions()
1006
     */
1007 10
    public function setPermissions(PermissionsInterface $permissions)
1008
    {
1009 10
        $this->permissions = $permissions;
1010 10
        return $this;
1011
    }
1012
1013
    /**
1014
     * Gets the Values of a job template
1015
     *
1016
     * @return TemplateValues
1017
     */
1018 6
    public function getTemplateValues()
1019
    {
1020 6
        if (!$this->templateValues instanceof TemplateValues) {
0 ignored issues
show
introduced by
$this->templateValues is always a sub-type of Jobs\Entity\TemplateValues.
Loading history...
1021 2
            $this->templateValues = new TemplateValues();
1022
        }
1023 6
        return $this->templateValues;
1024
    }
1025
1026
    /**
1027
     * @param EntityInterface $templateValues
1028
     *
1029
     * @return $this
1030
     */
1031 5
    public function setTemplateValues(EntityInterface $templateValues = null)
1032
    {
1033 5
        if (!$templateValues instanceof TemplateValues) {
1034 2
            $templateValues = new TemplateValues($templateValues);
0 ignored issues
show
Unused Code introduced by
The call to Jobs\Entity\TemplateValues::__construct() has too many arguments starting with $templateValues. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1034
            $templateValues = /** @scrutinizer ignore-call */ new TemplateValues($templateValues);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
1035
        }
1036 5
        $this->templateValues = $templateValues;
1037 5
        return $this;
1038
    }
1039
1040
    /**
1041
     * Sets the list of channels where a job opening should be published
1042
     *
1043
     * @param Array
1044
     * {@inheritdoc}
1045
     */
1046 1
    public function setPortals(array $portals)
1047
    {
1048 1
        $this->portals = $portals;
1049 1
        return $this;
1050
    }
1051
1052
    /**
1053
     * Gets the list of channels where the job opening should be published
1054
     *
1055
     * {@inheritdoc}
1056
     * @return array
1057
     */
1058 2
    public function getPortals()
1059
    {
1060 2
        return $this->portals;
1061
    }
1062
1063
    /**
1064
     * Gets the flag indicating the draft state.
1065
     *
1066
     * @return bool
1067
     */
1068 2
    public function isDraft()
1069
    {
1070 2
        return $this->isDraft;
1071
    }
1072
1073
    /**
1074
     * Sets the flag indicating the draft state.
1075
     *
1076
     * @param boolean $flag
1077
     * @return DraftableEntityInterface
1078
     */
1079 6
    public function setIsDraft($flag)
1080
    {
1081 6
        $this->isDraft = (bool) $flag;
1082 6
        return $this;
1083
    }
1084
1085
    /**
1086
     * Gets the status and checks it against 'active'
1087
     *
1088
     * @return bool
1089
     */
1090 4
    public function isActive()
1091
    {
1092 4
        return !$this->isDraft && is_object($this->status) && $this->status->getName() == 'active';
0 ignored issues
show
Deprecated Code introduced by
The function Jobs\Entity\Status::getName() has been deprecated: since 0,29, use __toString() ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

1092
        return !$this->isDraft && is_object($this->status) && /** @scrutinizer ignore-deprecated */ $this->status->getName() == 'active';

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
1093
    }
1094
1095
    /**
1096
     * @return Job
1097
     */
1098 1
    public function makeSnapshot()
1099
    {
1100 1
        $snapshot = new JobSnapshot($this);
1101 1
        return $snapshot;
1102
    }
1103
1104
    /**
1105
     * @return array|mixed
1106
     */
1107 1
    public function getSnapshotGenerator()
1108
    {
1109
        $generator = array(
1110 1
            'hydrator' => '',
1111
            'target' => 'Jobs\Entity\JobSnapshot',
1112
            'exclude' => array('permissions', 'history')
1113
        );
1114 1
        return $generator;
1115
    }
1116
1117
    /**
1118
     * @param \Jobs\Entity\Classifications $classifications
1119
     *
1120
     * @return self
1121
     */
1122 2
    public function setClassifications($classifications)
1123
    {
1124 2
        $this->classifications = $classifications;
1125
1126 2
        return $this;
1127
    }
1128
1129
    /**
1130
     * @return \Jobs\Entity\Classifications
1131
     */
1132 2
    public function getClassifications()
1133
    {
1134 2
        if (!$this->classifications) {
1135 2
            $this->setClassifications(new Classifications());
1136
        }
1137
1138 2
        return $this->classifications;
1139
    }
1140
1141
    /**
1142
     * Mark this job as deleted.
1143
     *
1144
     * @internal
1145
     *      This is meant as temporary solution, until
1146
     *      SoftDelete is implemented.
1147
     *
1148
     * @return self
1149
     * @since 0.29
1150
     */
1151
    public function delete()
1152
    {
1153
        $this->isDeleted = true;
1154
1155
        return $this;
1156
    }
1157
1158
    public function isDeleted()
1159
    {
1160
        return $this->isDeleted;
1161
    }
1162
}
1163