Completed
Push — develop ( dfe314...df0194 )
by
unknown
07:26
created

Job::delete()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
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\ClonableEntityInterface;
13
use Core\Entity\ClonePropertiesTrait;
14
use Core\Entity\AttachableEntityTrait;
15
use Core\Entity\EntityInterface;
16
use Core\Entity\Hydrator\EntityHydrator;
17
use Core\Entity\MetaDataProviderTrait;
18
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
19
use Core\Repository\DoctrineMongoODM\Annotation as Cam;
20
use Doctrine\Common\Collections\Collection;
21
use Auth\Entity\UserInterface;
22
use Core\Entity\Permissions;
23
use Core\Entity\PermissionsInterface;
24
use Organizations\Entity\OrganizationInterface;
25
use Core\Entity\DraftableEntityInterface;
26
use Core\Entity\Collection\ArrayCollection;
27
use Core\Entity\SnapshotGeneratorProviderInterface;
28
use Zend\I18n\Validator\DateTime;
29
30
/**
31
 * The job model
32
 *
33
 * @ODM\Document(collection="jobs", repositoryClass="Jobs\Repository\Job")
34
 * @author Mathias Gelhausen <[email protected]>
35
 * @author Mathias Weitz <[email protected]>
36
 * @author Carsten Bleek <[email protected]>
37
 * @since 0.29 add temporary isDeleted flag and corresponding delete() method.
38
 */
39
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...
40
                                        DraftableEntityInterface,
0 ignored issues
show
Coding Style introduced by
Expected 4 spaces before interface name; 40 found
Loading history...
41
                                        SnapshotGeneratorProviderInterface
0 ignored issues
show
Coding Style introduced by
Expected 4 spaces before interface name; 40 found
Loading history...
42
43
{
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...
44
    use AttachableEntityTrait, MetaDataProviderTrait, ClonePropertiesTrait;
45
46
47
    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...
48
        'classifications', 'atsMode',
49
    ];
50
51
    /**
52
     * unique ID of a job posting used by applications to reference
53
     * a job
54
     *
55
     * @var String
56
     * @ODM\Field(type="string") @ODM\Index
57
     **/
58
    protected $applyId;
59
    
60
    /**
61
     * title of a job posting
62
     *
63
     * @var String
64
     * @ODM\Field(type="string")
65
     */
66
    protected $title;
67
    
68
69
    /**
70
     * name of the publishing company
71
     *
72
     * @var String
73
     * @ODM\Field(type="string")
74
     */
75
    protected $company;
76
    
77
    /**
78
     * publishing company
79
     *
80
     * @var OrganizationInterface
81
     * @ODM\ReferenceOne (targetDocument="\Organizations\Entity\Organization", simple=true, inversedBy="jobs")
82
     * @ODM\Index
83
     */
84
    protected $organization;
85
    
86
    
87
    /**
88
     * Email Address, which is used to send notifications about e.g. new applications.
89
     *
90
     * @var String
91
     * @ODM\Field(type="string")
92
     **/
93
    protected $contactEmail;
94
    
95
    /**
96
     * the owner of a Job Posting
97
     *
98
     * @var UserInterface $user
99
     * @ODM\ReferenceOne(targetDocument="\Auth\Entity\User", simple=true)
100
     * @ODM\Index
101
     */
102
    protected $user;
103
    
104
    /**
105
     * all applications of a certain jobad
106
     *
107
     * @var Collection
108
     * @ODM\ReferenceMany(targetDocument="Applications\Entity\Application", simple=true, mappedBy="job",
109
     *                    repositoryMethod="loadApplicationsForJob")
110
     */
111
    protected $applications;
112
    
113
    /**
114
     * new applications
115
     *
116
     * @ODM\ReferenceMany(targetDocument="Applications\Entity\Application",
117
     *                    repositoryMethod="loadUnreadApplicationsForJob", mappedBy="job")
118
     * @var Int
119
     */
120
    protected $unreadApplications;
121
    
122
    /**
123
     * language of the job posting. Languages are ISO 639-1 coded
124
     *
125
     * @var String
126
     * @ODM\Field(type="string")
127
     */
128
    protected $language;
129
    
130
    /**
131
     * location of the job posting. This is a plain text, which describes the location in
132
     * search e.g. results.
133
     *
134
     * @var String
135
     * @ODM\Field(type="string")
136
     */
137
    protected $location;
138
139
    /**
140
     * locations of the job posting. This collection contains structured coordinates,
141
     * postal codes, city, region, and country names
142
     *
143
     * @var Collection
144
     * @ODM\EmbedMany(targetDocument="Location")
145
     */
146
    protected $locations;
147
    
148
    /**
149
     * Link which points to the job posting
150
     *
151
     * @var String
152
     * @ODM\Field(type="string")
153
     **/
154
    protected $link;
155
    
156
    /**
157
     * publishing date of a job posting
158
     *
159
     * @var String
160
     * @ODM\Field(type="tz_date")
161
     */
162
    protected $datePublishStart;
163
164
    /**
165
     * end date of a job posting
166
     *
167
     * @var String
168
     * @ODM\Field(type="tz_date")
169
     */
170
    protected $datePublishEnd;
171
    
172
    /**
173
     * Status of the job posting
174
     *
175
     * @var Status
176
     * @ODM\EmbedOne(targetDocument="Status")
177
     * @ODM\Index
178
     */
179
    protected $status;
180
181
    /**
182
     * History on an job posting
183
     *
184
     * @var Collection
185
     * @ODM\EmbedMany(targetDocument="History")
186
     */
187
    protected $history;
188
189
    /**
190
     * Flag, privacy policy is accepted or not.
191
     *
192
     * @var bool
193
     * @ODM\Boolean
194
     */
195
    protected $termsAccepted;
196
    
197
    /**
198
     * Reference of a job opening, on which an applicant can refer to.
199
     *
200
     * @var String
201
     * @ODM\Field(type="string")
202
     */
203
    protected $reference;
204
    
205
    /**
206
     * Unified Resource Locator to the company-Logo
207
     *
208
     * @var String
209
     * @ODM\Field(type="string")
210
     */
211
    protected $logoRef;
212
213
    /**
214
     * Template-Name
215
     *
216
     * @var String
217
     * @ODM\Field(type="string")
218
     */
219
    protected $template;
220
221
    /**
222
     * Application link.
223
     *
224
     * @var String
225
     * @ODM\Field(type="string")
226
     */
227
    protected $uriApply;
228
229
    /**
230
     * Unified Resource Locator the Yawik, which handled this job first - so
231
     * does know who is the one who has commited this job.
232
     *
233
     * @var String
234
     * @ODM\Field(type="string")
235
     */
236
    protected $uriPublisher;
237
238
    /**
239
     * @var
240
     * @ODM\EmbedMany(targetDocument="Publisher")
241
     */
242
    protected $publisher;
243
244
    /**
245
     * The ATS mode entity.
246
     *
247
     * @var AtsMode
248
     * @ODM\EmbedOne(targetDocument="AtsMode")
249
     */
250
    protected $atsMode;
251
252
    /**
253
     * this must be enabled to use applications forms etc. for this job or
254
     * to see number of applications in the list of applications
255
     *
256
     * @var Boolean
257
     *
258
     * @ODM\Boolean
259
     */
260
    protected $atsEnabled;
261
    
262
    /**
263
     * Permissions
264
     *
265
     * @var PermissionsInterface
266
     * @ODM\EmbedOne(targetDocument="\Core\Entity\Permissions")
267
     */
268
    protected $permissions;
269
270
    /**
271
     * The actual name of the organization.
272
     *
273
     * @var TemplateValues
274
     * @ODM\EmbedOne(targetDocument="\Jobs\Entity\TemplateValues")
275
     */
276
    protected $templateValues;
277
278
279
    /**
280
     * Can contain various Portals
281
     *
282
     * @var array
283
     * @ODM\Collection*/
284
    protected $portals = array();
285
286
    /**
287
     * Flag indicating draft state of this job.
288
     *
289
     * @var bool
290
     * @ODM\Boolean
291
     */
292
    protected $isDraft = false;
293
294
    /**
295
     * Classifications
296
     *
297
     * @ODM\EmbedOne(targetDocument="\Jobs\Entity\Classifications")
298
     * @var Classifications
299
     * @since 0.29
300
     */
301
    protected $classifications;
302
303
    /**
304
     * Delete flag.
305
     *
306
     * @internal
307
     *      This is meant as a temporary flag, until
308
     *      SoftDelete is implemented.
309
     *
310
     * @ODM\Field(type="boolean")
311
     * @var bool
312
     * @since 0.29
313
     */
314
    protected $isDeleted = false;
315
316
    /**
317
     * @return string
318
     */
319
    public function getResourceId()
320
    {
321
        return 'Entity/Jobs/Job';
322
    }
323
324
    /**
325
     * @see \Jobs\Entity\JobInterface::setApplyId()
326
     * @param String $applyId
327
     * @return \Jobs\Entity\JobInterface
328
     */
329
    public function setApplyId($applyId)
330
    {
331
        $this->applyId = (string) $applyId;
332
        return $this;
333
    }
334
    /**
335
     * @see \Jobs\Entity\JobInterface::getApplyId()
336
     * @return String
337
     */
338
    public function getApplyId()
339
    {
340
        if (!isset($this->applyId)) {
341
            // take the entity-id as a default
342
            $this->applyId = $this->id;
343
        }
344
        return $this->applyId;
345
    }
346
347
    /**
348
     * Gets the title of a job posting
349
     *
350
     * @return string
351
     */
352
    public function getTitle()
353
    {
354
        return $this->title;
355
    }
356
357
    /**
358
     * Sets the title of a job posting
359
     *
360
     * @see \Jobs\Entity\JobInterface::setTitle()
361
     * @param String $title
362
     * @return \Jobs\Entity\JobInterface
363
     */
364
    public function setTitle($title)
365
    {
366
        $this->title = (string) $title;
367
        return $this;
368
    }
369
    
370
    /**
371
     * Gets the name oof the company. If there is an organization assigned to the
372
     * job posting. Take the name of the organization.
373
     *
374
     * (non-PHPdoc)
375
     * @see \Jobs\Entity\JobInterface::getCompany()
376
     */
377
    public function getCompany()
378
    {
379
        if ($this->organization) {
380
            return $this->organization->getOrganizationName()->getName();
381
        }
382
        return $this->company;
383
    }
384
385
    /**
386
     * (non-PHPdoc)
387
     * @see \Jobs\Entity\JobInterface::setCompany()
388
     */
389
    public function setCompany($company)
390
    {
391
        $this->company = $company;
392
        return $this;
393
    }
394
    
395
     /**
396
     * (non-PHPdoc)
397
     * @see \Jobs\Entity\JobInterface::getOrganization()
398
     */
399
    public function getOrganization()
400
    {
401
        return $this->organization;
402
    }
403
    
404
    /**
405
     * @inheritdoc
406
     */
407
    public function setOrganization(OrganizationInterface $organization = null)
408
    {
409
        $permissions = $this->getPermissions();
410
411
        if ($this->organization) {
412
            $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...
413
        }
414
        $this->organization = $organization;
415
        $permissions->grant($organization);
0 ignored issues
show
Bug introduced by
It seems like $organization defined by parameter $organization on line 407 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...
416
417
        return $this;
418
    }
419
420
    /**
421
     * (non-PHPdoc)
422
     * @see \Jobs\Entity\JobInterface::getContactEmail()
423
     */
424
    public function getContactEmail()
425
    {
426
        if (false !== $this->contactEmail && !$this->contactEmail) {
427
            $user = $this->getUser();
428
            $email = false;
429
            if (isset($user)) {
430
                $email = $user->getInfo()->getEmail();
431
            }
432
            $this->setContactEmail($email);
0 ignored issues
show
Security Bug introduced by
It seems like $email defined by false on line 428 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...
433
        }
434
        return $this->contactEmail;
435
    }
436
437
    /**
438
     * (non-PHPdoc)
439
     * @see \Jobs\Entity\JobInterface::setContactEmail()
440
     */
441
    public function setContactEmail($email)
442
    {
443
        $this->contactEmail = (string) $email;
444
        return $this;
445
    }
446
447
    /**
448
     * (non-PHPdoc)
449
     * @see \Jobs\Entity\JobInterface::setLanguage()
450
     */
451
    public function setLanguage($language)
452
    {
453
        $this->language = $language;
454
        return $this;
455
    }
456
    /**
457
     * (non-PHPdoc)
458
     * @see \Jobs\Entity\JobInterface::getLanguage()
459
     */
460
    public function getLanguage()
461
    {
462
        return $this->language;
463
    }
464
    /**
465
     * (non-PHPdoc)
466
     * @see \Jobs\Entity\JobInterface::setLocation()
467
     */
468
    public function setLocation($location)
469
    {
470
        $this->location = $location;
471
        return $this;
472
    }
473
    /**
474
     * (non-PHPdoc)
475
     * @see \Jobs\Entity\JobInterface::getLocation()
476
     */
477
    public function getLocation()
478
    {
479
        if (null === $this->location) {
480
            $array=[];
481
            if(null != $this->locations){
482
                foreach ($this->locations as $location) { /* @var \Core\Entity\LocationInterface $location */
483
                    $array[]=$location->getCity();
484
                }
485
                return implode(', ', $array);
486
            }
487
        }
488
        return $this->location;
489
    }
490
    /**
491
     * (non-PHPdoc)
492
     * @see \Jobs\Entity\JobInterface::setLocations()
493
     */
494
    public function setLocations($locations)
495
    {
496
        $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...
497
        return $this;
498
    }
499
    /**
500
     * (non-PHPdoc)
501
     * @see \Jobs\Entity\JobInterface::getLocations()
502
     */
503
    public function getLocations()
504
    {
505
        if (!$this->locations) {
506
            $this->setLocations(new ArrayCollection());
507
        }
508
        return $this->locations;
509
    }
510
    /**
511
     * (non-PHPdoc)
512
     * @see \Jobs\Entity\JobInterface::setUser()
513
     */
514 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...
515
    {
516
        if ($this->user) {
517
            $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...
518
        }
519
        $this->user = $user;
520
        $this->getPermissions()->grant($user, Permissions::PERMISSION_ALL);
521
        return $this;
522
    }
523
    /**
524
     * (non-PHPdoc)
525
     * @see \Jobs\Entity\JobInterface::getUser()
526
     */
527
    public function getUser()
528
    {
529
        return $this->user;
530
    }
531
532
    public function unsetUser($removePermissions = true)
533
    {
534
        if ($this->user) {
535
            if ($removePermissions) {
536
                $this->getPermissions()->revoke($this->user, Permissions::PERMISSION_ALL);
537
            }
538
            $this->user=null;
539
        }
540
541
        return $this;
542
    }
543
544
    /**
545
     * (non-PHPdoc)
546
     * @see \Jobs\Entity\JobInterface::setApplications()
547
     */
548
    public function setApplications(Collection $applications)
549
    {
550
        $this->applications = $applications;
551
        return $this;
552
    }
553
554
    /**
555
     * (non-PHPdoc)
556
     * @see \Jobs\Entity\JobInterface::getApplications()
557
     */
558
    public function getApplications()
559
    {
560
        return $this->applications;
561
    }
562
563
    /**
564
     * Gets the number of unread applications
565
     * @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...
566
     */
567
    public function getUnreadApplications()
568
    {
569
        return $this->unreadApplications;
570
    }
571
    /**
572
     * (non-PHPdoc)
573
     * @see \Jobs\Entity\JobInterface::getLink()
574
     */
575
    public function getLink()
576
    {
577
        return $this->link;
578
    }
579
    /**
580
     * (non-PHPdoc)
581
     * @see \Jobs\Entity\JobInterface::setLink()
582
     */
583
    public function setLink($link)
584
    {
585
        $this->link = $link;
586
        return $this;
587
    }
588
    /**
589
     * (non-PHPdoc)
590
     * @see \Jobs\Entity\JobInterface::getDatePublishStart()
591
     */
592
    public function getDatePublishStart()
593
    {
594
        return $this->datePublishStart;
595
    }
596
    /**
597
     * (non-PHPdoc)
598
     * @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...
599
     * @see \Jobs\Entity\JobInterface::setDatePublishStart()
600
     * @return $this
601
     */
602 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...
603
    {
604
        if (!isset($datePublishStart) || is_string($datePublishStart)) {
605
            $datePublishStart = new \DateTime($datePublishStart);
606
        } else if (!$datePublishStart instanceOf \DateTime) {
607
            throw new \InvalidArgumentException('Expected object of type \DateTime');
608
        }
609
610
        $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...
611
        return $this;
612
    }
613
614
    /**
615
     * (non-PHPdoc)
616
     * @see \Jobs\Entity\JobInterface::getDatePublishStart()
617
     */
618
    public function getDatePublishEnd()
619
    {
620
        return $this->datePublishEnd;
621
    }
622
    /**
623
     * (non-PHPdoc)
624
     * @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...
625
     * @see \Jobs\Entity\JobInterface::setDatePublishEnd()
626
     * @return $this
627
     */
628 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...
629
    {
630
        if (is_string($datePublishEnd)) {
631
            $datePublishEnd = new \DateTime($datePublishEnd);
632
        } else if (!$datePublishEnd instanceOf \DateTime) {
633
            throw new \InvalidArgumentException('Expected object of type \DateTime');
634
        }
635
636
        $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...
637
        return $this;
638
    }
639
640
    /**
641
     * Modifies the state of an application.
642
     *
643
     * Creates a history entry.
644
     *
645
     * @param StatusInterface|string $status
646
     * @param string $message
647
     * @return Job
648
     */
649 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...
650
    {
651
        $this->setStatus($status);
0 ignored issues
show
Bug introduced by
It seems like $status defined by parameter $status on line 649 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...
652
        $status = $this->getStatus(); // ensure StatusEntity
653
654
        $history = new History($status, $message);
655
656
        $this->getHistory()->add($history);
657
        return $this;
658
    }
659
660
    /**
661
     * (non-PHPdoc)
662
     * @see \Jobs\Entity\JobInterface::getStatus()
663
     */
664
    public function getStatus()
665
    {
666
        return $this->status;
667
    }
668
    /**
669
     * (non-PHPdoc)
670
     * @see \Jobs\Entity\JobInterface::setStatus()
671
     */
672
    public function setStatus($status)
673
    {
674
        if (!$status instanceof Status) {
675
            $status = new Status($status);
676
        }
677
        $this->status = $status;
678
    }
679
680
    /**
681
     * {@inheritDoc}
682
     * @see JobInterface::setHistory()
683
     * @return Job
684
     */
685
    public function setHistory(Collection $history)
686
    {
687
        $this->history = $history;
688
        return $this;
689
    }
690
691
    /**
692
     * {@inheritDoc}
693
     * @see JobInterface::getHistory()
694
     */
695
    public function getHistory()
696
    {
697
        if (null == $this->history) {
698
            $this->setHistory(new ArrayCollection());
699
        }
700
        return $this->history;
701
    }
702
703
    /**
704
     * {@inheritDoc}
705
     * @see JobInterface::setTermsAccepted()
706
     * @return self
707
     */
708
    public function setTermsAccepted($termsAccepted)
709
    {
710
        $this->termsAccepted = $termsAccepted;
711
        return $this;
712
    }
713
714
    /**
715
     * {qinheritDoc}
716
     * @see JobInterface::getTermsAccepted()
717
     */
718
    public function getTermsAccepted()
719
    {
720
        return $this->termsAccepted;
721
    }
722
723
    /**
724
     * (non-PHPdoc)
725
     * @see JobInterface::getReference()
726
     */
727
    public function getReference()
728
    {
729
        return $this->reference;
730
    }
731
    /**
732
     * (non-PHPdoc)
733
     * @see JobInterface::setReference()
734
     */
735
    public function setReference($reference)
736
    {
737
        $this->reference = $reference;
738
        return $this;
739
    }
740
741
    public function setAtsMode(AtsMode $mode)
742
    {
743
        $this->atsMode = $mode;
744
745
        return $this;
746
    }
747
748
    public function getAtsMode()
749
    {
750
        if (!$this->atsMode) {
751
            $this->setAtsMode(new AtsMode(AtsMode::MODE_INTERN));
752
        }
753
754
        return $this->atsMode;
755
    }
756
757
758
    /**
759
     * checks, weather a job is enabled for getting applications
760
     * @return boolean
761
     */
762
    public function getAtsEnabled()
763
    {
764
        return $this->atsEnabled;
765
    }
766
    /**
767
     * enables a job add to receive applications
768
     *
769
     * @param boolean $atsEnabled
770
     * @return \Jobs\Entity\Job
771
     */
772
    public function setAtsEnabled($atsEnabled)
773
    {
774
        $this->atsEnabled = $atsEnabled;
775
        return $this;
776
    }
777
    /**
778
     * returns an uri to the organization logo.
779
     *
780
     * @return string
781
     */
782
    public function getLogoRef()
783
    {
784
        /** @var $organization \Organizations\Entity\Organization */
785
        $organization = $this->organization;
786
        if (is_object($organization) && $organization->getImage()) {
787
            $organizationImage = $organization->getImage();
788
            return "/file/Organizations.OrganizationImage/" . $organizationImage->getId();
789
        }
790
        return $this->logoRef;
791
    }
792
    /**
793
     * Set the uri to the organisations logo
794
     *
795
     * @param string $logoRef
796
     * @return \Jobs\Entity\Job
797
     */
798
    public function setLogoRef($logoRef)
799
    {
800
        $this->logoRef = $logoRef;
801
        return $this;
802
    }
803
804
    /**
805
     *
806
     *
807
     * @return string
808
     */
809
    public function getTemplate()
810
    {
811
        $template = $this->template;
812
        if (empty($template)) {
813
            $template = 'default';
814
        }
815
        return $template;
816
    }
817
    /**
818
     *
819
     *
820
     * @param string $template name of the Template
821
     * @return \Jobs\Entity\Job
822
     */
823
    public function setTemplate($template)
824
    {
825
        $this->template = $template;
826
        return $this;
827
    }
828
829
830
831
    /**
832
     * Gets the uri of an application link
833
     *
834
     * @return String
835
     */
836
    public function getUriApply()
837
    {
838
        return $this->uriApply;
839
    }
840
841
    /**
842
     * Sets the uri of an application link
843
     *
844
     * @param String $uriApply
845
     * @return \Jobs\Entity\Job
846
     */
847
    public function setUriApply($uriApply)
848
    {
849
        $this->uriApply = $uriApply;
850
        return $this;
851
    }
852
853
    /**
854
     * Gets the uri of a publisher
855
     *
856
     * @return String
857
     */
858
    public function getUriPublisher()
859
    {
860
        return $this->uriPublisher;
861
    }
862
    /**
863
     *
864
     * @param String $uriPublisher
865
     * @return \Jobs\Entity\Job
866
     */
867
    public function setUriPublisher($uriPublisher)
868
    {
869
        $this->uriPublisher = $uriPublisher;
870
        return $this;
871
    }
872
873
    /**
874
     * @param $key
875
     * @return mixed
876
     */
877
    public function getPublisher($key)
878
    {
879
        $result = null;
880
        foreach ($this->publisher as $publisher) {
881
            if ($publisher->host == $key) {
882
                $result = $publisher;
883
            }
884
        }
885
        if (!isset($result)) {
886
            $result = new Publisher();
887
            $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...
888
            $this->publisher[] = $result;
889
        }
890
        return $result;
891
    }
892
893
    public function setPublisherReference($key, $reference)
0 ignored issues
show
Unused Code introduced by
The parameter $reference is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
894
    {
895
        $publisher = $this->getPublisher($key);
896
        $publisher->reference;
897
        return $this;
898
    }
899
900
    
901
    /**
902
     * (non-PHPdoc)
903
     * @see \Core\Entity\PermissionsAwareInterface::getPermissions()
904
     */
905
    public function getPermissions()
906
    {
907
        if (!$this->permissions) {
908
            $permissions = new Permissions('Job/Permissions');
909
            if ($this->user) {
910
                $permissions->grant($this->user, Permissions::PERMISSION_ALL);
911
            }
912
            $this->setPermissions($permissions);
913
        }
914
915
        return $this->permissions;
916
    }
917
    
918
    /**
919
     * (non-PHPdoc)
920
     * @see \Core\Entity\PermissionsAwareInterface::setPermissions()
921
     */
922
    public function setPermissions(PermissionsInterface $permissions)
923
    {
924
        $this->permissions = $permissions;
925
        return $this;
926
    }
927
928
    /**
929
     * Gets the Values of a job template
930
     *
931
     * @return TemplateValues
932
     */
933
    public function getTemplateValues()
934
    {
935
        if (!$this->templateValues instanceof TemplateValues) {
936
            $this->templateValues = new TemplateValues();
937
        }
938
        return $this->templateValues;
939
    }
940
941
    /**
942
     * @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...
943
     *
944
     * @return $this
945
     */
946
    public function setTemplateValues(EntityInterface $templateValues = null)
947
    {
948
        if (!$templateValues instanceof TemplateValues) {
949
            $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...
950
        }
951
        $this->templateValues = $templateValues;
952
        return $this;
953
    }
954
955
    /**
956
     * Sets the list of channels where a job opening should be published
957
     *
958
     * @param Array
959
     * {@inheritdoc}
960
     */
961
    public function setPortals(array $portals)
962
    {
963
        $this->portals = $portals;
964
        return $this;
965
    }
966
967
    /**
968
     * Gets the list of channels where the job opening should be published
969
     *
970
     * {@inheritdoc}
971
     * @return Array
972
     */
973
    public function getPortals()
974
    {
975
        return $this->portals;
976
    }
977
978
    /**
979
     * Gets the flag indicating the draft state.
980
     *
981
     * @return bool
982
     */
983
    public function isDraft()
984
    {
985
        return $this->isDraft;
986
    }
987
988
    /**
989
     * Sets the flag indicating the draft state.
990
     *
991
     * @param boolean $flag
992
     * @return DraftableEntityInterface
993
     */
994
    public function setIsDraft($flag)
995
    {
996
        $this->isDraft = (bool) $flag;
997
        return $this;
998
    }
999
1000
    /**
1001
     * Gets the status and checks it against 'active'
1002
     *
1003
     * @return bool
1004
     */
1005
    public function isActive()
1006
    {
1007
        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...
1008
    }
1009
1010
    /**
1011
     * @return Job
1012
     */
1013
    public function makeSnapshot()
1014
    {
1015
        $snapshot = new JobSnapshot($this);
1016
        return $snapshot;
1017
    }
1018
1019
    /**
1020
     * @return array|mixed
1021
     */
1022
    public function getSnapshotGenerator()
1023
    {
1024
        $generator = array(
1025
            'hydrator' => '',
1026
            'target' => 'Jobs\Entity\JobSnapshot',
1027
            'exclude' => array('permissions', 'history')
1028
        );
1029
        return $generator;
1030
    }
1031
1032
    /**
1033
     * @param \Jobs\Entity\Classifications $classifications
1034
     *
1035
     * @return self
1036
     */
1037
    public function setClassifications($classifications)
1038
    {
1039
        $this->classifications = $classifications;
1040
1041
        return $this;
1042
    }
1043
1044
    /**
1045
     * @return \Jobs\Entity\Classifications
1046
     */
1047
    public function getClassifications()
1048
    {
1049
        if (!$this->classifications) {
1050
            $this->setClassifications(new Classifications());
1051
        }
1052
1053
        return $this->classifications;
1054
    }
1055
1056
    /**
1057
     * Mark this job as deleted.
1058
     *
1059
     * @internal
1060
     *      This is meant as temporary solution, until
1061
     *      SoftDelete is implemented.
1062
     *
1063
     * @return self
1064
     * @since 0.29
1065
     */
1066
    public function delete()
1067
    {
1068
        $this->isDeleted = true;
1069
1070
        return $this;
1071
    }
1072
1073
1074
}
1075