src/App/Entity/ImmediateApplication/ContactMessage.php line 28

Open in your IDE?
  1. <?php
  2. namespace App\Entity\ImmediateApplication;
  3. use App\Entity\RecurrentJob;
  4. use App\Entity\User;
  5. use App\Service\MailService;
  6. use App\Utility\DateTimeUtility;
  7. use App\Utility\ReflectionHelper;
  8. use DateTime;
  9. use Doctrine\Common\Collections\ArrayCollection;
  10. use Doctrine\Common\Collections\Collection;
  11. use Doctrine\ORM\Mapping as ORM;
  12. use InvalidArgumentException;
  13. use Symfony\Component\Validator\Constraints as Assert;
  14. /**
  15. * @ORM\Entity()
  16. *
  17. * @ORM\Table(
  18. * name="immediate_application_contact_messages",
  19. * indexes={
  20. *
  21. * @ORM\Index(name="email_idx", columns={"email"}),
  22. * }
  23. * )
  24. */
  25. class ContactMessage
  26. {
  27. public const CREATED_VIA_RECRUIT_DL = 0;
  28. public function __construct()
  29. {
  30. $this->firstname = '';
  31. $this->lastname = '';
  32. $this->email = '';
  33. $this->phone = '';
  34. $this->user = null;
  35. $this->contactMessageCvFiles = new ArrayCollection([]);
  36. $this->createdAt = DateTimeUtility::createDateTimeUtc();
  37. $this->createdVia = null;
  38. }
  39. /**
  40. * @var string
  41. *
  42. * @ORM\GeneratedValue(strategy="CUSTOM")
  43. *
  44. * @ORM\CustomIdGenerator(class="App\Utility\DatabaseIdGenerator")
  45. *
  46. * @ORM\Column(name="id", type="guid")
  47. *
  48. * @ORM\Id
  49. */
  50. private $id;
  51. public function getId(): string
  52. {
  53. return $this->id;
  54. }
  55. /**
  56. * @var User|null
  57. *
  58. * @ORM\ManyToOne(targetEntity="App\Entity\User", cascade={"persist"})
  59. *
  60. * @ORM\JoinColumn(name="users_id", referencedColumnName="id", nullable=false, onDelete="CASCADE")
  61. */
  62. private $user;
  63. public function setUser(User $user): void
  64. {
  65. $this->user = $user;
  66. }
  67. public function getUser(): ?User
  68. {
  69. return $this->user;
  70. }
  71. /**
  72. * @var RecurrentJob|null
  73. *
  74. * @ORM\ManyToOne(targetEntity="App\Entity\RecurrentJob", cascade={"persist"})
  75. *
  76. * @ORM\JoinColumn(name="recurrent_jobs_id", referencedColumnName="id", nullable=false, onDelete="SET NULL")
  77. */
  78. private $recurrentJob;
  79. public function setRecurrentJob(RecurrentJob $recurrentJob): void
  80. {
  81. $this->recurrentJob = $recurrentJob;
  82. }
  83. public function getRecurrentJob(): ?RecurrentJob
  84. {
  85. return $this->recurrentJob;
  86. }
  87. /**
  88. * @var string
  89. *
  90. * @ORM\Column(name="firstname", type="string", length=255, nullable=false)
  91. *
  92. * @Assert\NotBlank()
  93. *
  94. * @Assert\Length(
  95. * min = 2,
  96. * max = 50,
  97. * )
  98. */
  99. private $firstname;
  100. public function getFirstname(): string
  101. {
  102. return $this->firstname;
  103. }
  104. public function setFirstname(string $firstname): void
  105. {
  106. $this->firstname = $firstname;
  107. }
  108. /**
  109. * @var string
  110. *
  111. * @ORM\Column(name="lastname", type="string", length=255, nullable=false)
  112. *
  113. * @Assert\NotBlank()
  114. */
  115. private $lastname;
  116. public function getLastname(): string
  117. {
  118. return $this->lastname;
  119. }
  120. public function setLastname(string $lastname): void
  121. {
  122. $this->lastname = $lastname;
  123. }
  124. /**
  125. * @var string
  126. *
  127. * @ORM\Column(name="email", type="string", length=255, nullable=false)
  128. *
  129. * @Assert\Email(mode="strict")
  130. *
  131. * @Assert\NotBlank()
  132. */
  133. private $email;
  134. public function getEmail(): string
  135. {
  136. return $this->email;
  137. }
  138. public function setEmail(string $email): void
  139. {
  140. if (!MailService::emailAddressIsValidForMailer($email)) {
  141. throw new InvalidArgumentException("E-mail '$email' is not valid.");
  142. }
  143. $this->email = $email;
  144. }
  145. /**
  146. * @var string
  147. *
  148. * @ORM\Column(name="phone", type="string", length=255, nullable=false)
  149. *
  150. * @Assert\NotBlank()
  151. *
  152. * @Assert\Regex(pattern="/^[ +\-\/0-9]{6,30}$/")
  153. */
  154. private $phone;
  155. public function getPhone(): string
  156. {
  157. return $this->phone;
  158. }
  159. public function setPhone(string $phone): void
  160. {
  161. $this->phone = $phone;
  162. }
  163. /**
  164. * @var DateTime
  165. *
  166. * @ORM\Column(name="created_at", type="datetime", nullable=false)
  167. */
  168. private $createdAt;
  169. public function getCreatedAt(): DateTime
  170. {
  171. return $this->createdAt;
  172. }
  173. /**
  174. * @var ContactMessageCvFile[]|Collection
  175. *
  176. * @ORM\OneToMany(targetEntity="\App\Entity\ImmediateApplication\ContactMessageCvFile", mappedBy="contactMessage", cascade={"persist", "remove"})
  177. */
  178. private $contactMessageCvFiles;
  179. public function getPrimaryCvFile(): ?ContactMessageCvFile
  180. {
  181. return $this->contactMessageCvFiles->get(0);
  182. }
  183. public function setPrimaryCvFile(ContactMessageCvFile $file): void
  184. {
  185. $this->contactMessageCvFiles[0] = $file;
  186. }
  187. public function getSecondaryCvFile(): ?ContactMessageCvFile
  188. {
  189. return $this->contactMessageCvFiles->get(1);
  190. }
  191. public function setSecondaryCvFile(ContactMessageCvFile $file): void
  192. {
  193. $this->contactMessageCvFiles[1] = $file;
  194. }
  195. /**
  196. * @var ?int
  197. *
  198. * @ORM\Column(name="created_via", type="integer", nullable=true)
  199. */
  200. private $createdVia;
  201. public function getCreatedVia(): ?int
  202. {
  203. return $this->createdVia;
  204. }
  205. /**
  206. * @throws Exception
  207. */
  208. public function setCreatedVia(?int $createdVia): void
  209. {
  210. if (!is_null($createdVia) && !ReflectionHelper::hasConstWithValue(self::class, 'CREATED_VIA_', $createdVia)) {
  211. throw new Exception("Not a valid value for createdVia: '{$createdVia}'.");
  212. }
  213. $this->createdVia = $createdVia;
  214. }
  215. }