| Total Complexity | 112 |
| Total Lines | 1117 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like Job often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Job, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 40 | class Job extends BaseEntity implements |
||
| 41 | JobInterface, |
||
| 42 | DraftableEntityInterface, |
||
| 43 | SnapshotGeneratorProviderInterface |
||
| 44 | { |
||
| 45 | use AttachableEntityTrait, MetaDataProviderTrait, ClonePropertiesTrait; |
||
| 46 | |||
| 47 | |||
| 48 | private $cloneProperties = [ |
||
|
|
|||
| 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 | public function getResourceId() |
||
| 361 | { |
||
| 362 | return 'Entity/Jobs/Job'; |
||
| 363 | } |
||
| 364 | |||
| 365 | /** |
||
| 366 | * @see \Jobs\Entity\JobInterface::setApplyId() |
||
| 367 | * @param String $applyId |
||
| 368 | * @return \Jobs\Entity\JobInterface |
||
| 369 | */ |
||
| 370 | public function setApplyId($applyId) |
||
| 371 | { |
||
| 372 | $this->applyId = (string) $applyId; |
||
| 373 | return $this; |
||
| 374 | } |
||
| 375 | /** |
||
| 376 | * @see \Jobs\Entity\JobInterface::getApplyId() |
||
| 377 | * @return String |
||
| 378 | */ |
||
| 379 | public function getApplyId() |
||
| 380 | { |
||
| 381 | if (!isset($this->applyId)) { |
||
| 382 | // take the entity-id as a default |
||
| 383 | $this->applyId = $this->id; |
||
| 384 | } |
||
| 385 | return $this->applyId; |
||
| 386 | } |
||
| 387 | |||
| 388 | /** |
||
| 389 | * Gets the title of a job posting |
||
| 390 | * |
||
| 391 | * @return string |
||
| 392 | */ |
||
| 393 | public function getTitle() |
||
| 394 | { |
||
| 395 | 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 | public function setTitle($title) |
||
| 406 | { |
||
| 407 | $this->title = (string) $title; |
||
| 408 | 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 | public function getCompany($useOrganizationEntity = true) |
||
| 420 | { |
||
| 421 | if ($this->organization && $useOrganizationEntity) { |
||
| 422 | return $this->organization->getOrganizationName()->getName(); |
||
| 423 | } |
||
| 424 | |||
| 425 | return $this->company; |
||
| 426 | } |
||
| 427 | |||
| 428 | /** |
||
| 429 | * (non-PHPdoc) |
||
| 430 | * @see \Jobs\Entity\JobInterface::setCompany() |
||
| 431 | */ |
||
| 432 | public function setCompany($company) |
||
| 433 | { |
||
| 434 | $this->company = $company; |
||
| 435 | return $this; |
||
| 436 | } |
||
| 437 | |||
| 438 | /** |
||
| 439 | * (non-PHPdoc) |
||
| 440 | * @see \Jobs\Entity\JobInterface::getOrganization() |
||
| 441 | */ |
||
| 442 | public function getOrganization() |
||
| 443 | { |
||
| 444 | return $this->organization; |
||
| 445 | } |
||
| 446 | |||
| 447 | /** |
||
| 448 | * @inheritdoc |
||
| 449 | */ |
||
| 450 | public function setOrganization(OrganizationInterface $organization = null) |
||
| 451 | { |
||
| 452 | $permissions = $this->getPermissions(); |
||
| 453 | |||
| 454 | if ($this->organization) { |
||
| 455 | $permissions->revoke($this->organization, null, false); |
||
| 456 | } |
||
| 457 | $this->organization = $organization; |
||
| 458 | $permissions->grant($organization); |
||
| 459 | |||
| 460 | return $this; |
||
| 461 | } |
||
| 462 | |||
| 463 | |||
| 464 | |||
| 465 | /** |
||
| 466 | * (non-PHPdoc) |
||
| 467 | * @see \Jobs\Entity\JobInterface::getContactEmail() |
||
| 468 | */ |
||
| 469 | public function getContactEmail() |
||
| 470 | { |
||
| 471 | if (false !== $this->contactEmail && !$this->contactEmail) { |
||
| 472 | $user = $this->getUser(); |
||
| 473 | $email = false; |
||
| 474 | if (isset($user)) { |
||
| 475 | $email = $user->getInfo()->getEmail(); |
||
| 476 | } |
||
| 477 | $this->setContactEmail($email); |
||
| 478 | } |
||
| 479 | return $this->contactEmail; |
||
| 480 | } |
||
| 481 | |||
| 482 | /** |
||
| 483 | * (non-PHPdoc) |
||
| 484 | * @see \Jobs\Entity\JobInterface::setContactEmail() |
||
| 485 | */ |
||
| 486 | public function setContactEmail($email) |
||
| 490 | } |
||
| 491 | |||
| 492 | /** |
||
| 493 | * (non-PHPdoc) |
||
| 494 | * @see \Jobs\Entity\JobInterface::setLanguage() |
||
| 495 | */ |
||
| 496 | public function setLanguage($language) |
||
| 497 | { |
||
| 498 | $this->language = $language; |
||
| 499 | return $this; |
||
| 500 | } |
||
| 501 | /** |
||
| 502 | * (non-PHPdoc) |
||
| 503 | * @see \Jobs\Entity\JobInterface::getLanguage() |
||
| 504 | */ |
||
| 505 | public function getLanguage() |
||
| 506 | { |
||
| 507 | return $this->language; |
||
| 508 | } |
||
| 509 | /** |
||
| 510 | * (non-PHPdoc) |
||
| 511 | * @see \Jobs\Entity\JobInterface::setLocation() |
||
| 512 | */ |
||
| 513 | public function setLocation($location) |
||
| 514 | { |
||
| 515 | $this->location = $location; |
||
| 516 | return $this; |
||
| 517 | } |
||
| 518 | /** |
||
| 519 | * (non-PHPdoc) |
||
| 520 | * @see \Jobs\Entity\JobInterface::getLocation() |
||
| 521 | */ |
||
| 522 | public function getLocation() |
||
| 523 | { |
||
| 524 | if (null === $this->location) { |
||
| 525 | $array=[]; |
||
| 526 | 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 | return $this->location; |
||
| 534 | } |
||
| 535 | /** |
||
| 536 | * (non-PHPdoc) |
||
| 537 | * @see \Jobs\Entity\JobInterface::setLocations() |
||
| 538 | */ |
||
| 539 | public function setLocations($locations) |
||
| 540 | { |
||
| 541 | $this->locations = $locations; |
||
| 542 | return $this; |
||
| 543 | } |
||
| 544 | /** |
||
| 545 | * (non-PHPdoc) |
||
| 546 | * @see \Jobs\Entity\JobInterface::getLocations() |
||
| 547 | */ |
||
| 548 | public function getLocations() |
||
| 549 | { |
||
| 550 | if (!$this->locations) { |
||
| 551 | $this->setLocations(new ArrayCollection()); |
||
| 552 | } |
||
| 553 | return $this->locations; |
||
| 554 | } |
||
| 555 | /** |
||
| 556 | * (non-PHPdoc) |
||
| 557 | * @see \Jobs\Entity\JobInterface::setUser() |
||
| 558 | */ |
||
| 559 | public function setUser(UserInterface $user) |
||
| 560 | { |
||
| 561 | if ($this->user) { |
||
| 562 | $this->getPermissions()->revoke($this->user, Permissions::PERMISSION_ALL, false); |
||
| 563 | } |
||
| 564 | $this->user = $user; |
||
| 565 | $this->getPermissions()->grant($user, Permissions::PERMISSION_ALL); |
||
| 566 | return $this; |
||
| 567 | } |
||
| 568 | /** |
||
| 569 | * (non-PHPdoc) |
||
| 570 | * @see \Jobs\Entity\JobInterface::getUser() |
||
| 571 | */ |
||
| 572 | public function getUser() |
||
| 573 | { |
||
| 574 | return $this->user; |
||
| 575 | } |
||
| 576 | |||
| 577 | public function unsetUser($removePermissions = true) |
||
| 578 | { |
||
| 579 | if ($this->user) { |
||
| 580 | if ($removePermissions) { |
||
| 581 | $this->getPermissions()->revoke($this->user, Permissions::PERMISSION_ALL); |
||
| 582 | } |
||
| 583 | $this->user=null; |
||
| 584 | } |
||
| 585 | |||
| 586 | return $this; |
||
| 587 | } |
||
| 588 | |||
| 589 | public function unsetOrganization($removePermissions = true) |
||
| 590 | { |
||
| 591 | if ($this->organization && $removePermissions) { |
||
| 592 | $this->getPermissions()->revoke($this->organization, Permissions::PERMISSION_ALL); |
||
| 593 | } |
||
| 594 | |||
| 595 | $this->organization = null; |
||
| 596 | |||
| 597 | return $this; |
||
| 598 | } |
||
| 599 | |||
| 600 | /** |
||
| 601 | * (non-PHPdoc) |
||
| 602 | * @see \Jobs\Entity\JobInterface::setApplications() |
||
| 603 | */ |
||
| 604 | public function setApplications(Collection $applications) |
||
| 605 | { |
||
| 606 | $this->applications = $applications; |
||
| 607 | return $this; |
||
| 608 | } |
||
| 609 | |||
| 610 | /** |
||
| 611 | * (non-PHPdoc) |
||
| 612 | * @see \Jobs\Entity\JobInterface::getApplications() |
||
| 613 | */ |
||
| 614 | public function getApplications() |
||
| 615 | { |
||
| 616 | 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; |
||
| 626 | } |
||
| 627 | /** |
||
| 628 | * (non-PHPdoc) |
||
| 629 | * @see \Jobs\Entity\JobInterface::getLink() |
||
| 630 | */ |
||
| 631 | public function getLink() |
||
| 632 | { |
||
| 633 | return $this->link; |
||
| 634 | } |
||
| 635 | /** |
||
| 636 | * (non-PHPdoc) |
||
| 637 | * @see \Jobs\Entity\JobInterface::setLink() |
||
| 638 | */ |
||
| 639 | public function setLink($link) |
||
| 640 | { |
||
| 641 | $this->link = $link; |
||
| 642 | return $this; |
||
| 643 | } |
||
| 644 | /** |
||
| 645 | * (non-PHPdoc) |
||
| 646 | * @see \Jobs\Entity\JobInterface::getDatePublishStart() |
||
| 647 | */ |
||
| 648 | public function getDatePublishStart() |
||
| 649 | { |
||
| 650 | return $this->datePublishStart; |
||
| 651 | } |
||
| 652 | /** |
||
| 653 | * (non-PHPdoc) |
||
| 654 | * @param string $datePublishStart |
||
| 655 | * @see \Jobs\Entity\JobInterface::setDatePublishStart() |
||
| 656 | * @return $this |
||
| 657 | */ |
||
| 658 | public function setDatePublishStart($datePublishStart = null) |
||
| 659 | { |
||
| 660 | if (!isset($datePublishStart) || is_string($datePublishStart)) { |
||
| 661 | $datePublishStart = new \DateTime($datePublishStart); |
||
| 662 | } elseif (!$datePublishStart instanceof \DateTime) { |
||
| 663 | throw new \InvalidArgumentException('Expected object of type \DateTime'); |
||
| 664 | } |
||
| 665 | |||
| 666 | $this->datePublishStart = $datePublishStart; |
||
| 667 | return $this; |
||
| 668 | } |
||
| 669 | |||
| 670 | /** |
||
| 671 | * (non-PHPdoc) |
||
| 672 | * @see \Jobs\Entity\JobInterface::getDatePublishStart() |
||
| 673 | */ |
||
| 674 | public function getDatePublishEnd() |
||
| 675 | { |
||
| 676 | return $this->datePublishEnd; |
||
| 677 | } |
||
| 678 | /** |
||
| 679 | * (non-PHPdoc) |
||
| 680 | * @param string $datePublishEnd |
||
| 681 | * @see \Jobs\Entity\JobInterface::setDatePublishEnd() |
||
| 682 | * @return $this |
||
| 683 | */ |
||
| 684 | public function setDatePublishEnd($datePublishEnd = null) |
||
| 685 | { |
||
| 686 | if (is_string($datePublishEnd)) { |
||
| 687 | $datePublishEnd = new \DateTime($datePublishEnd); |
||
| 688 | } elseif (!$datePublishEnd instanceof \DateTime) { |
||
| 689 | throw new \InvalidArgumentException('Expected object of type \DateTime'); |
||
| 690 | } |
||
| 691 | |||
| 692 | $this->datePublishEnd = $datePublishEnd; |
||
| 693 | 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 | public function changeStatus($status, $message = '[System]') |
||
| 706 | { |
||
| 707 | $this->setStatus($status); |
||
| 708 | $status = $this->getStatus(); // ensure StatusEntity |
||
| 709 | |||
| 710 | $history = new History($status, $message); |
||
| 711 | |||
| 712 | $this->getHistory()->add($history); |
||
| 713 | return $this; |
||
| 714 | } |
||
| 715 | |||
| 716 | /** |
||
| 717 | * (non-PHPdoc) |
||
| 718 | * @see \Jobs\Entity\JobInterface::getStatus() |
||
| 719 | */ |
||
| 720 | public function getStatus() |
||
| 721 | { |
||
| 722 | return $this->status; |
||
| 723 | } |
||
| 724 | /** |
||
| 725 | * (non-PHPdoc) |
||
| 726 | * @see \Jobs\Entity\JobInterface::setStatus() |
||
| 727 | */ |
||
| 728 | public function setStatus($status) |
||
| 729 | { |
||
| 730 | if (!$status instanceof Status) { |
||
| 731 | $status = new Status($status); |
||
| 732 | } |
||
| 733 | $this->status = $status; |
||
| 734 | } |
||
| 735 | |||
| 736 | /** |
||
| 737 | * {@inheritDoc} |
||
| 738 | * @see JobInterface::setHistory() |
||
| 739 | * @return Job |
||
| 740 | */ |
||
| 741 | public function setHistory(Collection $history) |
||
| 742 | { |
||
| 743 | $this->history = $history; |
||
| 744 | return $this; |
||
| 745 | } |
||
| 746 | |||
| 747 | /** |
||
| 748 | * {@inheritDoc} |
||
| 749 | * @see JobInterface::getHistory() |
||
| 750 | */ |
||
| 751 | public function getHistory() |
||
| 752 | { |
||
| 753 | if (null == $this->history) { |
||
| 754 | $this->setHistory(new ArrayCollection()); |
||
| 755 | } |
||
| 756 | return $this->history; |
||
| 757 | } |
||
| 758 | |||
| 759 | /** |
||
| 760 | * {@inheritDoc} |
||
| 761 | * @see JobInterface::setTermsAccepted() |
||
| 762 | * @return self |
||
| 763 | */ |
||
| 764 | public function setTermsAccepted($termsAccepted) |
||
| 765 | { |
||
| 766 | $this->termsAccepted = $termsAccepted; |
||
| 767 | return $this; |
||
| 768 | } |
||
| 769 | |||
| 770 | /** |
||
| 771 | * {qinheritDoc} |
||
| 772 | * @see JobInterface::getTermsAccepted() |
||
| 773 | */ |
||
| 774 | public function getTermsAccepted() |
||
| 775 | { |
||
| 776 | return $this->termsAccepted; |
||
| 777 | } |
||
| 778 | |||
| 779 | /** |
||
| 780 | * (non-PHPdoc) |
||
| 781 | * @see JobInterface::getReference() |
||
| 782 | */ |
||
| 783 | public function getReference() |
||
| 784 | { |
||
| 785 | return $this->reference; |
||
| 786 | } |
||
| 787 | /** |
||
| 788 | * (non-PHPdoc) |
||
| 789 | * @see JobInterface::setReference() |
||
| 790 | */ |
||
| 791 | public function setReference($reference) |
||
| 792 | { |
||
| 793 | $this->reference = $reference; |
||
| 794 | return $this; |
||
| 795 | } |
||
| 796 | |||
| 797 | public function setAtsMode(AtsMode $mode) |
||
| 798 | { |
||
| 799 | $this->atsMode = $mode; |
||
| 800 | |||
| 801 | return $this; |
||
| 802 | } |
||
| 803 | |||
| 804 | public function getAtsMode() |
||
| 805 | { |
||
| 806 | if (!$this->atsMode) { |
||
| 807 | $this->setAtsMode(new AtsMode(AtsMode::MODE_INTERN)); |
||
| 808 | } |
||
| 809 | |||
| 810 | return $this->atsMode; |
||
| 811 | } |
||
| 812 | |||
| 813 | |||
| 814 | /** |
||
| 815 | * checks, weather a job is enabled for getting applications |
||
| 816 | * @return boolean |
||
| 817 | */ |
||
| 818 | public function getAtsEnabled() |
||
| 819 | { |
||
| 820 | 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 | public function setAtsEnabled($atsEnabled) |
||
| 829 | { |
||
| 830 | $this->atsEnabled = $atsEnabled; |
||
| 831 | return $this; |
||
| 832 | } |
||
| 833 | |||
| 834 | /** |
||
| 835 | * @param \Jobs\Entity\Salary $salary |
||
| 836 | * |
||
| 837 | * @return self |
||
| 838 | */ |
||
| 839 | public function setSalary(Salary $salary) |
||
| 840 | { |
||
| 841 | $this->salary = $salary; |
||
| 842 | |||
| 843 | return $this; |
||
| 844 | } |
||
| 845 | |||
| 846 | /** |
||
| 847 | * @return \Jobs\Entity\Salary |
||
| 848 | */ |
||
| 849 | public function getSalary() |
||
| 850 | { |
||
| 851 | if (!$this->salary) { |
||
| 852 | $this->setSalary(new Salary()); |
||
| 853 | } |
||
| 854 | |||
| 855 | return $this->salary; |
||
| 856 | } |
||
| 857 | |||
| 858 | /** |
||
| 859 | * returns an uri to the organization logo. |
||
| 860 | * |
||
| 861 | * @return string |
||
| 862 | */ |
||
| 863 | public function getLogoRef() |
||
| 864 | { |
||
| 865 | /** @var $organization \Organizations\Entity\Organization */ |
||
| 866 | $organization = $this->organization; |
||
| 867 | if (is_object($organization) && $organization->getImage()) { |
||
| 868 | $organizationImage = $organization->getImage(); |
||
| 869 | return "/file/Organizations.OrganizationImage/" . $organizationImage->getId(); |
||
| 870 | } |
||
| 871 | 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 | public function setLogoRef($logoRef) |
||
| 880 | { |
||
| 881 | $this->logoRef = $logoRef; |
||
| 882 | return $this; |
||
| 883 | } |
||
| 884 | |||
| 885 | /** |
||
| 886 | * |
||
| 887 | * |
||
| 888 | * @return string |
||
| 889 | */ |
||
| 890 | public function getTemplate() |
||
| 891 | { |
||
| 892 | $template = $this->template; |
||
| 893 | if (empty($template)) { |
||
| 894 | $template = 'default'; |
||
| 895 | } |
||
| 896 | return $template; |
||
| 897 | } |
||
| 898 | /** |
||
| 899 | * |
||
| 900 | * |
||
| 901 | * @param string $template name of the Template |
||
| 902 | * @return \Jobs\Entity\Job |
||
| 903 | */ |
||
| 904 | public function setTemplate($template) |
||
| 905 | { |
||
| 906 | $this->template = $template; |
||
| 907 | return $this; |
||
| 908 | } |
||
| 909 | |||
| 910 | |||
| 911 | |||
| 912 | /** |
||
| 913 | * Gets the uri of an application link |
||
| 914 | * |
||
| 915 | * @return String |
||
| 916 | */ |
||
| 917 | public function getUriApply() |
||
| 918 | { |
||
| 919 | 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 | public function setUriApply($uriApply) |
||
| 929 | { |
||
| 930 | $this->uriApply = $uriApply; |
||
| 931 | return $this; |
||
| 932 | } |
||
| 933 | |||
| 934 | /** |
||
| 935 | * Gets the uri of a publisher |
||
| 936 | * |
||
| 937 | * @return String |
||
| 938 | */ |
||
| 939 | public function getUriPublisher() |
||
| 940 | { |
||
| 941 | return $this->uriPublisher; |
||
| 942 | } |
||
| 943 | /** |
||
| 944 | * |
||
| 945 | * @param String $uriPublisher |
||
| 946 | * @return \Jobs\Entity\Job |
||
| 947 | */ |
||
| 948 | public function setUriPublisher($uriPublisher) |
||
| 949 | { |
||
| 950 | $this->uriPublisher = $uriPublisher; |
||
| 951 | 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; |
||
| 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 | public function getPermissions() |
||
| 987 | { |
||
| 988 | if (!$this->permissions) { |
||
| 989 | $permissions = new Permissions('Job/Permissions'); |
||
| 990 | if ($this->user) { |
||
| 991 | $permissions->grant($this->user, Permissions::PERMISSION_ALL); |
||
| 992 | } |
||
| 993 | $this->setPermissions($permissions); |
||
| 994 | } |
||
| 995 | |||
| 996 | return $this->permissions; |
||
| 997 | } |
||
| 998 | |||
| 999 | /** |
||
| 1000 | * (non-PHPdoc) |
||
| 1001 | * @see \Core\Entity\PermissionsAwareInterface::setPermissions() |
||
| 1002 | */ |
||
| 1003 | public function setPermissions(PermissionsInterface $permissions) |
||
| 1004 | { |
||
| 1005 | $this->permissions = $permissions; |
||
| 1006 | return $this; |
||
| 1007 | } |
||
| 1008 | |||
| 1009 | /** |
||
| 1010 | * Gets the Values of a job template |
||
| 1011 | * |
||
| 1012 | * @return TemplateValues |
||
| 1013 | */ |
||
| 1014 | public function getTemplateValues() |
||
| 1015 | { |
||
| 1016 | if (!$this->templateValues instanceof TemplateValues) { |
||
| 1017 | $this->templateValues = new TemplateValues(); |
||
| 1018 | } |
||
| 1019 | return $this->templateValues; |
||
| 1020 | } |
||
| 1021 | |||
| 1022 | /** |
||
| 1023 | * @param EntityInterface $templateValues |
||
| 1024 | * |
||
| 1025 | * @return $this |
||
| 1026 | */ |
||
| 1027 | public function setTemplateValues(EntityInterface $templateValues = null) |
||
| 1028 | { |
||
| 1029 | if (!$templateValues instanceof TemplateValues) { |
||
| 1030 | $templateValues = new TemplateValues($templateValues); |
||
| 1031 | } |
||
| 1032 | $this->templateValues = $templateValues; |
||
| 1033 | 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 | public function setPortals(array $portals) |
||
| 1043 | { |
||
| 1044 | $this->portals = $portals; |
||
| 1045 | 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 | public function getPortals() |
||
| 1055 | { |
||
| 1056 | return $this->portals; |
||
| 1057 | } |
||
| 1058 | |||
| 1059 | /** |
||
| 1060 | * Gets the flag indicating the draft state. |
||
| 1061 | * |
||
| 1062 | * @return bool |
||
| 1063 | */ |
||
| 1064 | public function isDraft() |
||
| 1065 | { |
||
| 1066 | return $this->isDraft; |
||
| 1067 | } |
||
| 1068 | |||
| 1069 | /** |
||
| 1070 | * Sets the flag indicating the draft state. |
||
| 1071 | * |
||
| 1072 | * @param boolean $flag |
||
| 1073 | * @return DraftableEntityInterface |
||
| 1074 | */ |
||
| 1075 | public function setIsDraft($flag) |
||
| 1076 | { |
||
| 1077 | $this->isDraft = (bool) $flag; |
||
| 1078 | return $this; |
||
| 1079 | } |
||
| 1080 | |||
| 1081 | /** |
||
| 1082 | * Gets the status and checks it against 'active' |
||
| 1083 | * |
||
| 1084 | * @return bool |
||
| 1085 | */ |
||
| 1086 | public function isActive() |
||
| 1087 | { |
||
| 1088 | return !$this->isDraft && is_object($this->status) && $this->status->getName() == 'active'; |
||
| 1089 | } |
||
| 1090 | |||
| 1091 | /** |
||
| 1092 | * @return Job |
||
| 1093 | */ |
||
| 1094 | public function makeSnapshot() |
||
| 1098 | } |
||
| 1099 | |||
| 1100 | /** |
||
| 1101 | * @return array|mixed |
||
| 1102 | */ |
||
| 1103 | public function getSnapshotGenerator() |
||
| 1111 | } |
||
| 1112 | |||
| 1113 | /** |
||
| 1114 | * @param \Jobs\Entity\Classifications $classifications |
||
| 1115 | * |
||
| 1116 | * @return self |
||
| 1117 | */ |
||
| 1118 | public function setClassifications($classifications) |
||
| 1119 | { |
||
| 1120 | $this->classifications = $classifications; |
||
| 1121 | |||
| 1122 | return $this; |
||
| 1123 | } |
||
| 1124 | |||
| 1125 | /** |
||
| 1126 | * @return \Jobs\Entity\Classifications |
||
| 1127 | */ |
||
| 1128 | public function getClassifications() |
||
| 1129 | { |
||
| 1130 | if (!$this->classifications) { |
||
| 1131 | $this->setClassifications(new Classifications()); |
||
| 1132 | } |
||
| 1133 | |||
| 1134 | 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() |
||
| 1152 | } |
||
| 1153 | |||
| 1154 | public function isDeleted() |
||
| 1155 | { |
||
| 1156 | return $this->isDeleted; |
||
| 1157 | } |
||
| 1158 | } |
||
| 1159 |