src/App/Entity/ProfileFavorization.php line 23

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Profile\JoboffererProfile;
  4. use App\Entity\Profile\JobseekerProfile;
  5. use DateTime;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8. * @ORM\Entity
  9. *
  10. * @ORM\Table(
  11. * name="profile_favorizations",
  12. * uniqueConstraints={
  13. *
  14. * @ORM\UniqueConstraint(name="jobseeker_profiles_id_jobofferer_profiles_id_favorer_unique_idx", columns={"jobseeker_profiles_id", "jobofferer_profiles_id", "favorer"})
  15. * }
  16. * )
  17. *
  18. * The unique constraint ensures only one favorization from a jobseeker to a jobofferer or vice versa.
  19. */
  20. class ProfileFavorization
  21. {
  22. public const FAVORER_JOBSEEKER = 0;
  23. public const FAVORER_JOBOFFERER = 1;
  24. /**
  25. * @var string
  26. *
  27. * @ORM\GeneratedValue(strategy="CUSTOM")
  28. *
  29. * @ORM\CustomIdGenerator(class="App\Utility\DatabaseIdGenerator")
  30. *
  31. * @ORM\Column(name="id", type="guid")
  32. *
  33. * @ORM\Id
  34. */
  35. protected $id;
  36. /**
  37. * @var JobseekerProfile
  38. *
  39. * @ORM\ManyToOne(targetEntity="App\Entity\Profile\JobseekerProfile", inversedBy="profileFavorizations", cascade={"persist"})
  40. *
  41. * @ORM\JoinColumn(name="jobseeker_profiles_id", referencedColumnName="id", nullable=false, onDelete="CASCADE")
  42. */
  43. protected $jobseekerProfile;
  44. /**
  45. * @var JoboffererProfile
  46. *
  47. * @ORM\ManyToOne(targetEntity="App\Entity\Profile\JoboffererProfile", inversedBy="profileFavorizations", cascade={"persist"})
  48. *
  49. * @ORM\JoinColumn(name="jobofferer_profiles_id", referencedColumnName="id", nullable=false, onDelete="CASCADE")
  50. */
  51. protected $joboffererProfile;
  52. /**
  53. * @var int
  54. *
  55. * @ORM\Column(name="favorer", type="smallint", nullable=false)
  56. */
  57. protected $favorer;
  58. /**
  59. * @var DateTime
  60. *
  61. * @ORM\Column(name="created_at", type="datetime", nullable=false)
  62. */
  63. protected $createdAt;
  64. public function isFavorer(Profile $profile)
  65. {
  66. if (($this->favorer === self::FAVORER_JOBSEEKER
  67. && $profile instanceof JobseekerProfile
  68. && $profile->getId() === $this->getJobseekerProfile()->getId())
  69. || ($this->favorer === self::FAVORER_JOBOFFERER
  70. && $profile instanceof JoboffererProfile
  71. && $profile->getId() === $this->getJoboffererProfile()->getId())
  72. ) {
  73. return true;
  74. } else {
  75. return false;
  76. }
  77. }
  78. public function setId(string $id)
  79. {
  80. $this->id = $id;
  81. }
  82. public function getId()
  83. {
  84. return $this->id;
  85. }
  86. /**
  87. * @return JobseekerProfile
  88. */
  89. public function getJobseekerProfile()
  90. {
  91. return $this->jobseekerProfile;
  92. }
  93. public function setJobseekerProfile(JobseekerProfile $jobseekerProfile)
  94. {
  95. $this->jobseekerProfile = $jobseekerProfile;
  96. }
  97. /**
  98. * @return JoboffererProfile
  99. */
  100. public function getJoboffererProfile()
  101. {
  102. return $this->joboffererProfile;
  103. }
  104. public function setJoboffererProfile(JoboffererProfile $joboffererProfile)
  105. {
  106. $this->joboffererProfile = $joboffererProfile;
  107. }
  108. /**
  109. * @return int
  110. */
  111. public function getFavorer()
  112. {
  113. return $this->favorer;
  114. }
  115. public function setFavorer(int $favorer)
  116. {
  117. $this->favorer = $favorer;
  118. }
  119. /**
  120. * @return DateTime
  121. */
  122. public function getCreatedAt()
  123. {
  124. return $this->createdAt;
  125. }
  126. public function setCreatedAt(DateTime $createdAt)
  127. {
  128. $this->createdAt = $createdAt;
  129. }
  130. public function __toString()
  131. {
  132. return $this->getId();
  133. }
  134. }