Passed
Push — develop ( 28c299...928e2a )
by Mathias
12:40
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 0
Metric Value
eloc 3
dl 0
loc 6
c 0
b 0
f 0
ccs 4
cts 4
cp 1
rs 10
cc 2
nc 2
nop 0
crap 2
1
<?php
2
/**
3
 * YAWIK
4
 *
5
 * @copyright (c) 2013 - 2016 Cross Solution (http://cross-solution.de)
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 Zend\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 2
    public function getTitle()
394
    {
395 2
        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 3
    public function setTitle($title)
406
    {
407 3
        $this->title = (string) $title;
408 3
        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 3
    public function getCompany($useOrganizationEntity = true)
420
    {
421 3
        if ($this->organization && $useOrganizationEntity) {
422 1
            return $this->organization->getOrganizationName()->getName();
423
        }
424
425 2
        return $this->company;
426
    }
427
428
    /**
429
     * (non-PHPdoc)
430
     * @see \Jobs\Entity\JobInterface::setCompany()
431
     */
432 2
    public function setCompany($company)
433
    {
434 2
        $this->company = $company;
435 2
        return $this;
436
    }
437
    
438
    /**
439
    * (non-PHPdoc)
440
    * @see \Jobs\Entity\JobInterface::getOrganization()
441
    */
442 3
    public function getOrganization()
443
    {
444 3
        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 3
    public function getDatePublishStart()
649
    {
650 3
        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 3
    public function getDatePublishEnd()
675
    {
676 3
        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
        return $this->status;
723
    }
724
    /**
725
     * (non-PHPdoc)
726
     * @see \Jobs\Entity\JobInterface::setStatus()
727
     */
728 16
    public function setStatus($status)
729
    {
730 16
        if (!$status instanceof Status) {
731 10
            $status = new Status($status);
732
        }
733 16
        $this->status = $status;
734 16
    }
735
736
    /**
737
     * {@inheritDoc}
738
     * @see JobInterface::setHistory()
739
     * @return Job
740
     */
741 8
    public function setHistory(Collection $history)
742
    {
743 8
        $this->history = $history;
744 8
        return $this;
745
    }
746
747
    /**
748
     * {@inheritDoc}
749
     * @see JobInterface::getHistory()
750
     */
751 8
    public function getHistory()
752
    {
753 8
        if (null == $this->history) {
754 7
            $this->setHistory(new ArrayCollection());
755
        }
756 8
        return $this->history;
757
    }
758
759
    /**
760
     * {@inheritDoc}
761
     * @see JobInterface::setTermsAccepted()
762
     * @return self
763
     */
764 3
    public function setTermsAccepted($termsAccepted)
765
    {
766 3
        $this->termsAccepted = $termsAccepted;
767 3
        return $this;
768
    }
769
770
    /**
771
     * {qinheritDoc}
772
     * @see JobInterface::getTermsAccepted()
773
     */
774 4
    public function getTermsAccepted()
775
    {
776 4
        return $this->termsAccepted;
777
    }
778
779
    /**
780
     * (non-PHPdoc)
781
     * @see JobInterface::getReference()
782
     */
783 2
    public function getReference()
784
    {
785 2
        return $this->reference;
786
    }
787
    /**
788
     * (non-PHPdoc)
789
     * @see JobInterface::setReference()
790
     */
791 1
    public function setReference($reference)
792
    {
793 1
        $this->reference = $reference;
794 1
        return $this;
795
    }
796
797 6
    public function setAtsMode(AtsMode $mode)
798
    {
799 6
        $this->atsMode = $mode;
800
801 6
        return $this;
802
    }
803
804 6
    public function getAtsMode()
805
    {
806 6
        if (!$this->atsMode) {
807 2
            $this->setAtsMode(new AtsMode(AtsMode::MODE_INTERN));
808
        }
809
810 6
        return $this->atsMode;
811
    }
812
813
814
    /**
815
     * checks, weather a job is enabled for getting applications
816
     * @return boolean
817
     */
818 3
    public function getAtsEnabled()
819
    {
820 3
        return $this->atsEnabled;
821
    }
822
    /**
823
     * enables a job add to receive applications
824
     *
825
     * @param boolean $atsEnabled
826
     * @return \Jobs\Entity\Job
827
     */
828 2
    public function setAtsEnabled($atsEnabled)
829
    {
830 2
        $this->atsEnabled = $atsEnabled;
831 2
        return $this;
832
    }
833
834
    /**
835
     * @param \Jobs\Entity\Salary $salary
836
     *
837
     * @return self
838
     */
839 1
    public function setSalary(Salary $salary)
840
    {
841 1
        $this->salary = $salary;
842
843 1
        return $this;
844
    }
845
846
    /**
847
     * @return \Jobs\Entity\Salary
848
     */
849 1
    public function getSalary()
850
    {
851 1
        if (!$this->salary) {
852 1
            $this->setSalary(new Salary());
853
        }
854
855 1
        return $this->salary;
856
    }
857
858
    /**
859
     * returns an uri to the organization logo.
860
     *
861
     * @return string
862
     */
863 2
    public function getLogoRef()
864
    {
865
        /** @var $organization \Organizations\Entity\Organization */
866 2
        $organization = $this->organization;
867 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

867
        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...
868
            $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

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

1030
            $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...
1031
        }
1032 5
        $this->templateValues = $templateValues;
1033 5
        return $this;
1034
    }
1035
1036
    /**
1037
     * Sets the list of channels where a job opening should be published
1038
     *
1039
     * @param Array
1040
     * {@inheritdoc}
1041
     */
1042 1
    public function setPortals(array $portals)
1043
    {
1044 1
        $this->portals = $portals;
1045 1
        return $this;
1046
    }
1047
1048
    /**
1049
     * Gets the list of channels where the job opening should be published
1050
     *
1051
     * {@inheritdoc}
1052
     * @return array
1053
     */
1054 2
    public function getPortals()
1055
    {
1056 2
        return $this->portals;
1057
    }
1058
1059
    /**
1060
     * Gets the flag indicating the draft state.
1061
     *
1062
     * @return bool
1063
     */
1064 2
    public function isDraft()
1065
    {
1066 2
        return $this->isDraft;
1067
    }
1068
1069
    /**
1070
     * Sets the flag indicating the draft state.
1071
     *
1072
     * @param boolean $flag
1073
     * @return DraftableEntityInterface
1074
     */
1075 6
    public function setIsDraft($flag)
1076
    {
1077 6
        $this->isDraft = (bool) $flag;
1078 6
        return $this;
1079
    }
1080
1081
    /**
1082
     * Gets the status and checks it against 'active'
1083
     *
1084
     * @return bool
1085
     */
1086 4
    public function isActive()
1087
    {
1088 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

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