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