Completed
Push — develop ( f8baa2...4ed862 )
by
unknown
19:01
created

Job::isDeleted()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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 JobInterface,
0 ignored issues
show
Coding Style introduced by
The first item in a multi-line implements list must be on the line following the implements keyword
Loading history...
41
                                        DraftableEntityInterface,
0 ignored issues
show
Coding Style introduced by
Expected 4 spaces before interface name; 40 found
Loading history...
42
                                        SnapshotGeneratorProviderInterface
0 ignored issues
show
Coding Style introduced by
Expected 4 spaces before interface name; 40 found
Loading history...
43
44
{
0 ignored issues
show
Coding Style introduced by
Opening brace of a class must be on the line following the class declaration; found 1 line(s)
Loading history...
45
    use AttachableEntityTrait, MetaDataProviderTrait, ClonePropertiesTrait;
46
47
48
    private $cloneProperties = [
0 ignored issues
show
Unused Code introduced by
The property $cloneProperties is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
49
        'classifications', 'atsMode',
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", simple=true, 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", simple=true)
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", simple=true, 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\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\Boolean
260
     */
261
    protected $atsEnabled;
262
    
263
    /**
264
     * Permissions
265
     *
266
     * @var PermissionsInterface
267
     * @ODM\EmbedOne(targetDocument="\Core\Entity\Permissions")
268
     */
269
    protected $permissions;
270
271
    /**
272
     * The actual name of the organization.
273
     *
274
     * @var TemplateValues
275
     * @ODM\EmbedOne(targetDocument="\Jobs\Entity\TemplateValues")
276
     */
277
    protected $templateValues;
278
279
280
    /**
281
     * Can contain various Portals
282
     *
283
     * @var array
284
     * @ODM\Collection*/
285
    protected $portals = array();
286
287
    /**
288
     * Flag indicating draft state of this job.
289
     *
290
     * @var bool
291
     * @ODM\Boolean
292
     */
293
    protected $isDraft = false;
294
295
    /**
296
     * Classifications
297
     *
298
     * @ODM\EmbedOne(targetDocument="\Jobs\Entity\Classifications")
299
     * @var Classifications
300
     * @since 0.29
301
     */
302
    protected $classifications;
303
304
    /**
305
     * Delete flag.
306
     *
307
     * @internal
308
     *      This is meant as a temporary flag, until
309
     *      SoftDelete is implemented.
310
     *
311
     * @ODM\Field(type="boolean")
312
     * @var bool
313
     * @since 0.29
314
     */
315
    protected $isDeleted = false;
316
317
    /**
318
     * @return string
319
     */
320
    public function getResourceId()
321
    {
322
        return 'Entity/Jobs/Job';
323
    }
324
325
    /**
326
     * @see \Jobs\Entity\JobInterface::setApplyId()
327
     * @param String $applyId
328
     * @return \Jobs\Entity\JobInterface
329
     */
330
    public function setApplyId($applyId)
331
    {
332
        $this->applyId = (string) $applyId;
333
        return $this;
334
    }
335
    /**
336
     * @see \Jobs\Entity\JobInterface::getApplyId()
337
     * @return String
338
     */
339
    public function getApplyId()
340
    {
341
        if (!isset($this->applyId)) {
342
            // take the entity-id as a default
343
            $this->applyId = $this->id;
344
        }
345
        return $this->applyId;
346
    }
347
348
    /**
349
     * Gets the title of a job posting
350
     *
351
     * @return string
352
     */
353
    public function getTitle()
354
    {
355
        return $this->title;
356
    }
357
358
    /**
359
     * Sets the title of a job posting
360
     *
361
     * @see \Jobs\Entity\JobInterface::setTitle()
362
     * @param String $title
363
     * @return \Jobs\Entity\JobInterface
364
     */
365
    public function setTitle($title)
366
    {
367
        $this->title = (string) $title;
368
        return $this;
369
    }
370
    
371
    /**
372
     * Gets the name oof the company. If there is an organization assigned to the
373
     * job posting. Take the name of the organization.
374
     *
375
     * (non-PHPdoc)
376
     * @see \Jobs\Entity\JobInterface::getCompany()
377
     */
378
    public function getCompany()
379
    {
380
        if ($this->organization) {
381
            return $this->organization->getOrganizationName()->getName();
382
        }
383
        return $this->company;
384
    }
385
386
    /**
387
     * (non-PHPdoc)
388
     * @see \Jobs\Entity\JobInterface::setCompany()
389
     */
390
    public function setCompany($company)
391
    {
392
        $this->company = $company;
393
        return $this;
394
    }
395
    
396
     /**
397
     * (non-PHPdoc)
398
     * @see \Jobs\Entity\JobInterface::getOrganization()
399
     */
400
    public function getOrganization()
401
    {
402
        return $this->organization;
403
    }
404
    
405
    /**
406
     * @inheritdoc
407
     */
408
    public function setOrganization(OrganizationInterface $organization = null)
409
    {
410
        $permissions = $this->getPermissions();
411
412
        if ($this->organization) {
413
            $permissions->revoke($this->organization, null, false);
0 ignored issues
show
Unused Code introduced by
The call to PermissionsInterface::revoke() has too many arguments starting with 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.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
414
        }
415
        $this->organization = $organization;
416
        $permissions->grant($organization);
0 ignored issues
show
Bug introduced by
It seems like $organization defined by parameter $organization on line 408 can be null; however, Core\Entity\PermissionsInterface::grant() does not accept null, maybe add an additional type check?

It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.

We recommend to add an additional type check (or disallow null for the parameter):

function notNullable(stdClass $x) { }

// Unsafe
function withoutCheck(stdClass $x = null) {
    notNullable($x);
}

// Safe - Alternative 1: Adding Additional Type-Check
function withCheck(stdClass $x = null) {
    if ($x instanceof stdClass) {
        notNullable($x);
    }
}

// Safe - Alternative 2: Changing Parameter
function withNonNullableParam(stdClass $x) {
    notNullable($x);
}
Loading history...
417
418
        return $this;
419
    }
420
421
    /**
422
     * (non-PHPdoc)
423
     * @see \Jobs\Entity\JobInterface::getContactEmail()
424
     */
425
    public function getContactEmail()
426
    {
427
        if (false !== $this->contactEmail && !$this->contactEmail) {
428
            $user = $this->getUser();
429
            $email = false;
430
            if (isset($user)) {
431
                $email = $user->getInfo()->getEmail();
432
            }
433
            $this->setContactEmail($email);
0 ignored issues
show
Security Bug introduced by
It seems like $email defined by false on line 429 can also be of type false; however, Jobs\Entity\Job::setContactEmail() does only seem to accept string, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
434
        }
435
        return $this->contactEmail;
436
    }
437
438
    /**
439
     * (non-PHPdoc)
440
     * @see \Jobs\Entity\JobInterface::setContactEmail()
441
     */
442
    public function setContactEmail($email)
443
    {
444
        $this->contactEmail = (string) $email;
445
        return $this;
446
    }
447
448
    /**
449
     * (non-PHPdoc)
450
     * @see \Jobs\Entity\JobInterface::setLanguage()
451
     */
452
    public function setLanguage($language)
453
    {
454
        $this->language = $language;
455
        return $this;
456
    }
457
    /**
458
     * (non-PHPdoc)
459
     * @see \Jobs\Entity\JobInterface::getLanguage()
460
     */
461
    public function getLanguage()
462
    {
463
        return $this->language;
464
    }
465
    /**
466
     * (non-PHPdoc)
467
     * @see \Jobs\Entity\JobInterface::setLocation()
468
     */
469
    public function setLocation($location)
470
    {
471
        $this->location = $location;
472
        return $this;
473
    }
474
    /**
475
     * (non-PHPdoc)
476
     * @see \Jobs\Entity\JobInterface::getLocation()
477
     */
478
    public function getLocation()
479
    {
480
        if (null === $this->location) {
481
            $array=[];
482
            if(null != $this->locations){
483
                foreach ($this->locations as $location) { /* @var \Core\Entity\LocationInterface $location */
484
                    $array[]=$location->getCity();
485
                }
486
                return implode(', ', $array);
487
            }
488
        }
489
        return $this->location;
490
    }
491
    /**
492
     * (non-PHPdoc)
493
     * @see \Jobs\Entity\JobInterface::setLocations()
494
     */
495
    public function setLocations($locations)
496
    {
497
        $this->locations = $locations;
0 ignored issues
show
Documentation Bug introduced by
It seems like $locations of type string is incompatible with the declared type object<Doctrine\Common\Collections\Collection> of property $locations.

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...
498
        return $this;
499
    }
500
    /**
501
     * (non-PHPdoc)
502
     * @see \Jobs\Entity\JobInterface::getLocations()
503
     */
504
    public function getLocations()
505
    {
506
        if (!$this->locations) {
507
            $this->setLocations(new ArrayCollection());
508
        }
509
        return $this->locations;
510
    }
511
    /**
512
     * (non-PHPdoc)
513
     * @see \Jobs\Entity\JobInterface::setUser()
514
     */
515 View Code Duplication
    public function setUser(UserInterface $user)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
516
    {
517
        if ($this->user) {
518
            $this->getPermissions()->revoke($this->user, Permissions::PERMISSION_ALL, false);
0 ignored issues
show
Unused Code introduced by
The call to PermissionsInterface::revoke() has too many arguments starting with 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.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
519
        }
520
        $this->user = $user;
521
        $this->getPermissions()->grant($user, Permissions::PERMISSION_ALL);
522
        return $this;
523
    }
524
    /**
525
     * (non-PHPdoc)
526
     * @see \Jobs\Entity\JobInterface::getUser()
527
     */
528
    public function getUser()
529
    {
530
        return $this->user;
531
    }
532
533
    public function unsetUser($removePermissions = true)
534
    {
535
        if ($this->user) {
536
            if ($removePermissions) {
537
                $this->getPermissions()->revoke($this->user, Permissions::PERMISSION_ALL);
538
            }
539
            $this->user=null;
540
        }
541
542
        return $this;
543
    }
544
545
    /**
546
     * (non-PHPdoc)
547
     * @see \Jobs\Entity\JobInterface::setApplications()
548
     */
549
    public function setApplications(Collection $applications)
550
    {
551
        $this->applications = $applications;
552
        return $this;
553
    }
554
555
    /**
556
     * (non-PHPdoc)
557
     * @see \Jobs\Entity\JobInterface::getApplications()
558
     */
559
    public function getApplications()
560
    {
561
        return $this->applications;
562
    }
563
564
    /**
565
     * Gets the number of unread applications
566
     * @return Collection
0 ignored issues
show
Documentation introduced by
Should the return type not be integer?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
567
     */
568
    public function getUnreadApplications()
569
    {
570
        return $this->unreadApplications;
571
    }
572
    /**
573
     * (non-PHPdoc)
574
     * @see \Jobs\Entity\JobInterface::getLink()
575
     */
576
    public function getLink()
577
    {
578
        return $this->link;
579
    }
580
    /**
581
     * (non-PHPdoc)
582
     * @see \Jobs\Entity\JobInterface::setLink()
583
     */
584
    public function setLink($link)
585
    {
586
        $this->link = $link;
587
        return $this;
588
    }
589
    /**
590
     * (non-PHPdoc)
591
     * @see \Jobs\Entity\JobInterface::getDatePublishStart()
592
     */
593
    public function getDatePublishStart()
594
    {
595
        return $this->datePublishStart;
596
    }
597
    /**
598
     * (non-PHPdoc)
599
     * @param string $datePublishStart
0 ignored issues
show
Documentation introduced by
Should the type for parameter $datePublishStart not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
600
     * @see \Jobs\Entity\JobInterface::setDatePublishStart()
601
     * @return $this
602
     */
603 View Code Duplication
    public function setDatePublishStart($datePublishStart = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
604
    {
605
        if (!isset($datePublishStart) || is_string($datePublishStart)) {
606
            $datePublishStart = new \DateTime($datePublishStart);
607
        } else if (!$datePublishStart instanceOf \DateTime) {
608
            throw new \InvalidArgumentException('Expected object of type \DateTime');
609
        }
610
611
        $this->datePublishStart = $datePublishStart;
0 ignored issues
show
Documentation Bug introduced by
It seems like $datePublishStart of type object<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...
612
        return $this;
613
    }
614
615
    /**
616
     * (non-PHPdoc)
617
     * @see \Jobs\Entity\JobInterface::getDatePublishStart()
618
     */
619
    public function getDatePublishEnd()
620
    {
621
        return $this->datePublishEnd;
622
    }
623
    /**
624
     * (non-PHPdoc)
625
     * @param string $datePublishEnd
0 ignored issues
show
Documentation introduced by
Should the type for parameter $datePublishEnd not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
626
     * @see \Jobs\Entity\JobInterface::setDatePublishEnd()
627
     * @return $this
628
     */
629 View Code Duplication
    public function setDatePublishEnd($datePublishEnd = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
630
    {
631
        if (is_string($datePublishEnd)) {
632
            $datePublishEnd = new \DateTime($datePublishEnd);
633
        } else if (!$datePublishEnd instanceOf \DateTime) {
634
            throw new \InvalidArgumentException('Expected object of type \DateTime');
635
        }
636
637
        $this->datePublishEnd = $datePublishEnd;
0 ignored issues
show
Documentation Bug introduced by
It seems like $datePublishEnd of type object<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...
638
        return $this;
639
    }
640
641
    /**
642
     * Modifies the state of an application.
643
     *
644
     * Creates a history entry.
645
     *
646
     * @param StatusInterface|string $status
647
     * @param string $message
648
     * @return Job
649
     */
650 View Code Duplication
    public function changeStatus($status, $message = '[System]')
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
651
    {
652
        $this->setStatus($status);
0 ignored issues
show
Bug introduced by
It seems like $status defined by parameter $status on line 650 can also be of type object<Jobs\Entity\StatusInterface>; however, Jobs\Entity\Job::setStatus() does only seem to accept string, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
653
        $status = $this->getStatus(); // ensure StatusEntity
654
655
        $history = new History($status, $message);
656
657
        $this->getHistory()->add($history);
658
        return $this;
659
    }
660
661
    /**
662
     * (non-PHPdoc)
663
     * @see \Jobs\Entity\JobInterface::getStatus()
664
     */
665
    public function getStatus()
666
    {
667
        return $this->status;
668
    }
669
    /**
670
     * (non-PHPdoc)
671
     * @see \Jobs\Entity\JobInterface::setStatus()
672
     */
673
    public function setStatus($status)
674
    {
675
        if (!$status instanceof Status) {
676
            $status = new Status($status);
677
        }
678
        $this->status = $status;
679
    }
680
681
    /**
682
     * {@inheritDoc}
683
     * @see JobInterface::setHistory()
684
     * @return Job
685
     */
686
    public function setHistory(Collection $history)
687
    {
688
        $this->history = $history;
689
        return $this;
690
    }
691
692
    /**
693
     * {@inheritDoc}
694
     * @see JobInterface::getHistory()
695
     */
696
    public function getHistory()
697
    {
698
        if (null == $this->history) {
699
            $this->setHistory(new ArrayCollection());
700
        }
701
        return $this->history;
702
    }
703
704
    /**
705
     * {@inheritDoc}
706
     * @see JobInterface::setTermsAccepted()
707
     * @return self
708
     */
709
    public function setTermsAccepted($termsAccepted)
710
    {
711
        $this->termsAccepted = $termsAccepted;
712
        return $this;
713
    }
714
715
    /**
716
     * {qinheritDoc}
717
     * @see JobInterface::getTermsAccepted()
718
     */
719
    public function getTermsAccepted()
720
    {
721
        return $this->termsAccepted;
722
    }
723
724
    /**
725
     * (non-PHPdoc)
726
     * @see JobInterface::getReference()
727
     */
728
    public function getReference()
729
    {
730
        return $this->reference;
731
    }
732
    /**
733
     * (non-PHPdoc)
734
     * @see JobInterface::setReference()
735
     */
736
    public function setReference($reference)
737
    {
738
        $this->reference = $reference;
739
        return $this;
740
    }
741
742
    public function setAtsMode(AtsMode $mode)
743
    {
744
        $this->atsMode = $mode;
745
746
        return $this;
747
    }
748
749
    public function getAtsMode()
750
    {
751
        if (!$this->atsMode) {
752
            $this->setAtsMode(new AtsMode(AtsMode::MODE_INTERN));
753
        }
754
755
        return $this->atsMode;
756
    }
757
758
759
    /**
760
     * checks, weather a job is enabled for getting applications
761
     * @return boolean
762
     */
763
    public function getAtsEnabled()
764
    {
765
        return $this->atsEnabled;
766
    }
767
    /**
768
     * enables a job add to receive applications
769
     *
770
     * @param boolean $atsEnabled
771
     * @return \Jobs\Entity\Job
772
     */
773
    public function setAtsEnabled($atsEnabled)
774
    {
775
        $this->atsEnabled = $atsEnabled;
776
        return $this;
777
    }
778
    /**
779
     * returns an uri to the organization logo.
780
     *
781
     * @return string
782
     */
783
    public function getLogoRef()
784
    {
785
        /** @var $organization \Organizations\Entity\Organization */
786
        $organization = $this->organization;
787
        if (is_object($organization) && $organization->getImage()) {
0 ignored issues
show
Deprecated Code introduced by
The method Organizations\Entity\Organization::getImage() has been deprecated with message: since 0.29; use $this->getImages()->get()

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

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

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

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

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

Loading history...
789
            return "/file/Organizations.OrganizationImage/" . $organizationImage->getId();
790
        }
791
        return $this->logoRef;
792
    }
793
    /**
794
     * Set the uri to the organisations logo
795
     *
796
     * @param string $logoRef
797
     * @return \Jobs\Entity\Job
798
     */
799
    public function setLogoRef($logoRef)
800
    {
801
        $this->logoRef = $logoRef;
802
        return $this;
803
    }
804
805
    /**
806
     *
807
     *
808
     * @return string
809
     */
810
    public function getTemplate()
811
    {
812
        $template = $this->template;
813
        if (empty($template)) {
814
            $template = 'default';
815
        }
816
        return $template;
817
    }
818
    /**
819
     *
820
     *
821
     * @param string $template name of the Template
822
     * @return \Jobs\Entity\Job
823
     */
824
    public function setTemplate($template)
825
    {
826
        $this->template = $template;
827
        return $this;
828
    }
829
830
831
832
    /**
833
     * Gets the uri of an application link
834
     *
835
     * @return String
836
     */
837
    public function getUriApply()
838
    {
839
        return $this->uriApply;
840
    }
841
842
    /**
843
     * Sets the uri of an application link
844
     *
845
     * @param String $uriApply
846
     * @return \Jobs\Entity\Job
847
     */
848
    public function setUriApply($uriApply)
849
    {
850
        $this->uriApply = $uriApply;
851
        return $this;
852
    }
853
854
    /**
855
     * Gets the uri of a publisher
856
     *
857
     * @return String
858
     */
859
    public function getUriPublisher()
860
    {
861
        return $this->uriPublisher;
862
    }
863
    /**
864
     *
865
     * @param String $uriPublisher
866
     * @return \Jobs\Entity\Job
867
     */
868
    public function setUriPublisher($uriPublisher)
869
    {
870
        $this->uriPublisher = $uriPublisher;
871
        return $this;
872
    }
873
874
    /**
875
     * @param $key
876
     * @return mixed
877
     */
878
    public function getPublisher($key)
879
    {
880
        $result = null;
881
        foreach ($this->publisher as $publisher) {
882
            if ($publisher->host == $key) {
883
                $result = $publisher;
884
            }
885
        }
886
        if (!isset($result)) {
887
            $result = new Publisher();
888
            $result->host = $key;
0 ignored issues
show
Documentation introduced by
The property $host is declared protected in Jobs\Entity\Publisher. Since you implemented __set(), maybe consider adding a @property or @property-write annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
889
            $this->publisher[] = $result;
890
        }
891
        return $result;
892
    }
893
894
    public function setPublisherReference($key, $reference)
895
    {
896
        $publisher = $this->getPublisher($key);
897
        $publisher->reference;
898
        return $this;
899
    }
900
901
    
902
    /**
903
     * (non-PHPdoc)
904
     * @see \Core\Entity\PermissionsAwareInterface::getPermissions()
905
     */
906
    public function getPermissions()
907
    {
908
        if (!$this->permissions) {
909
            $permissions = new Permissions('Job/Permissions');
910
            if ($this->user) {
911
                $permissions->grant($this->user, Permissions::PERMISSION_ALL);
912
            }
913
            $this->setPermissions($permissions);
914
        }
915
916
        return $this->permissions;
917
    }
918
    
919
    /**
920
     * (non-PHPdoc)
921
     * @see \Core\Entity\PermissionsAwareInterface::setPermissions()
922
     */
923
    public function setPermissions(PermissionsInterface $permissions)
924
    {
925
        $this->permissions = $permissions;
926
        return $this;
927
    }
928
929
    /**
930
     * Gets the Values of a job template
931
     *
932
     * @return TemplateValues
933
     */
934
    public function getTemplateValues()
935
    {
936
        if (!$this->templateValues instanceof TemplateValues) {
937
            $this->templateValues = new TemplateValues();
938
        }
939
        return $this->templateValues;
940
    }
941
942
    /**
943
     * @param EntityInterface $templateValues
0 ignored issues
show
Documentation introduced by
Should the type for parameter $templateValues not be null|EntityInterface?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
944
     *
945
     * @return $this
946
     */
947
    public function setTemplateValues(EntityInterface $templateValues = null)
948
    {
949
        if (!$templateValues instanceof TemplateValues) {
950
            $templateValues = new TemplateValues($templateValues);
0 ignored issues
show
Unused Code introduced by
The call to TemplateValues::__construct() has too many arguments starting with $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.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
951
        }
952
        $this->templateValues = $templateValues;
953
        return $this;
954
    }
955
956
    /**
957
     * Sets the list of channels where a job opening should be published
958
     *
959
     * @param Array
960
     * {@inheritdoc}
961
     */
962
    public function setPortals(array $portals)
963
    {
964
        $this->portals = $portals;
965
        return $this;
966
    }
967
968
    /**
969
     * Gets the list of channels where the job opening should be published
970
     *
971
     * {@inheritdoc}
972
     * @return Array
973
     */
974
    public function getPortals()
975
    {
976
        return $this->portals;
977
    }
978
979
    /**
980
     * Gets the flag indicating the draft state.
981
     *
982
     * @return bool
983
     */
984
    public function isDraft()
985
    {
986
        return $this->isDraft;
987
    }
988
989
    /**
990
     * Sets the flag indicating the draft state.
991
     *
992
     * @param boolean $flag
993
     * @return DraftableEntityInterface
994
     */
995
    public function setIsDraft($flag)
996
    {
997
        $this->isDraft = (bool) $flag;
998
        return $this;
999
    }
1000
1001
    /**
1002
     * Gets the status and checks it against 'active'
1003
     *
1004
     * @return bool
1005
     */
1006
    public function isActive()
1007
    {
1008
        return !$this->isDraft && is_object($this->status) && $this->status->getName() == 'active';
0 ignored issues
show
Deprecated Code introduced by
The method Jobs\Entity\Status::getName() has been deprecated with message: since 0,29, use __toString()

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

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

Loading history...
1009
    }
1010
1011
    /**
1012
     * @return Job
1013
     */
1014
    public function makeSnapshot()
1015
    {
1016
        $snapshot = new JobSnapshot($this);
1017
        return $snapshot;
1018
    }
1019
1020
    /**
1021
     * @return array|mixed
1022
     */
1023
    public function getSnapshotGenerator()
1024
    {
1025
        $generator = array(
1026
            'hydrator' => '',
1027
            'target' => 'Jobs\Entity\JobSnapshot',
1028
            'exclude' => array('permissions', 'history')
1029
        );
1030
        return $generator;
1031
    }
1032
1033
    /**
1034
     * @param \Jobs\Entity\Classifications $classifications
1035
     *
1036
     * @return self
1037
     */
1038
    public function setClassifications($classifications)
1039
    {
1040
        $this->classifications = $classifications;
1041
1042
        return $this;
1043
    }
1044
1045
    /**
1046
     * @return \Jobs\Entity\Classifications
1047
     */
1048
    public function getClassifications()
1049
    {
1050
        if (!$this->classifications) {
1051
            $this->setClassifications(new Classifications());
1052
        }
1053
1054
        return $this->classifications;
1055
    }
1056
1057
    /**
1058
     * Mark this job as deleted.
1059
     *
1060
     * @internal
1061
     *      This is meant as temporary solution, until
1062
     *      SoftDelete is implemented.
1063
     *
1064
     * @return self
1065
     * @since 0.29
1066
     */
1067
    public function delete()
1068
    {
1069
        $this->isDeleted = true;
1070
1071
        return $this;
1072
    }
1073
1074
    public function isDeleted()
1075
    {
1076
        return $this->isDeleted;
1077
    }
1078
1079
1080
}
1081