src/Entity/ApiMailRequest.php line 23

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ApiMailRequestRepository;
  4. use App\Traits\DateTrait;
  5. use DateTimeImmutable;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use JMS\Serializer\Annotation as Serializer;
  10. use JMS\Serializer\Annotation\Expose;
  11. use JMS\Serializer\Annotation\Groups;
  12. use Symfony\Component\Validator\Constraints as Assert;
  13. /**
  14. * Requete d'envoi de mail
  15. *
  16. * @ORM\Entity(repositoryClass=ApiMailRequestRepository::class)
  17. *
  18. * @Serializer\ExclusionPolicy("ALL")
  19. */
  20. class ApiMailRequest
  21. {
  22. use DateTrait;
  23. /**
  24. * @ORM\Id
  25. * @ORM\GeneratedValue
  26. * @ORM\Column(type="integer")
  27. *
  28. * @Expose
  29. * @Groups({"get"})
  30. *
  31. */
  32. private ?int $id = NULL;
  33. /**
  34. * Type du mail que l'on envoie
  35. *
  36. * @ORM\Column(type="string", length=255)
  37. *
  38. * @Assert\NotBlank
  39. *
  40. * @Expose
  41. * @Groups({"get","post"})
  42. */
  43. private string $mailType;
  44. /**
  45. * Le projet qui envoie le mail
  46. *
  47. * @ORM\Column(type="string", length=255)
  48. *
  49. * @Assert\NotBlank
  50. *
  51. * @Expose
  52. * @Groups({"get","post"})
  53. */
  54. private string $project;
  55. /**
  56. * Liste des destinataires
  57. *
  58. * @ORM\OneToMany(targetEntity=ApiMailRecipient::class, mappedBy="apiMailRequest", orphanRemoval=true, cascade={"persist"})
  59. *
  60. * @Expose
  61. * @Groups({"post"})
  62. */
  63. private Collection $recipients;
  64. /**
  65. * Date de l'envoi réel des mails
  66. *
  67. * @ORM\Column(type="datetime_immutable", nullable=true)
  68. */
  69. private ?DateTimeImmutable $sendAt;
  70. /**
  71. * @ORM\Column(type="boolean", options={"default":0})
  72. */
  73. private bool $error = FALSE;
  74. /**
  75. * @ORM\Column(type="text", nullable=true)
  76. */
  77. private ?string $errorMessage = NULL;
  78. public function __construct()
  79. {
  80. $this->recipients = new ArrayCollection();
  81. }
  82. public function getId(): ?int
  83. {
  84. return $this->id;
  85. }
  86. public function getMailType(): string
  87. {
  88. return $this->mailType;
  89. }
  90. public function setMailType(string $mailType): self
  91. {
  92. $this->mailType = $mailType;
  93. return $this;
  94. }
  95. public function getProject(): string
  96. {
  97. return $this->project;
  98. }
  99. public function setProject(string $project): self
  100. {
  101. $this->project = $project;
  102. return $this;
  103. }
  104. public function getSendAt(): ?DateTimeImmutable
  105. {
  106. return $this->sendAt;
  107. }
  108. public function setSendAt(?DateTimeImmutable $sendAt): self
  109. {
  110. $this->sendAt = $sendAt;
  111. return $this;
  112. }
  113. /**
  114. * @return Collection<int, ApiMailRecipient>
  115. */
  116. public function getRecipients(): Collection
  117. {
  118. return $this->recipients;
  119. }
  120. /**
  121. * @param iterable<ApiMailRecipient> $recipients
  122. *
  123. * @return $this
  124. */
  125. public function setRecipients(iterable $recipients): self
  126. {
  127. foreach($this->recipients as $recipient)
  128. {
  129. $this->removeRecipient($recipient);
  130. }
  131. foreach($recipients as $recipient)
  132. {
  133. $this->addRecipient($recipient);
  134. }
  135. return $this;
  136. }
  137. public function addRecipient(ApiMailRecipient $recipient): self
  138. {
  139. if (!$this->recipients->contains($recipient)) {
  140. $this->recipients[] = $recipient;
  141. $recipient->setApiMailRequest($this);
  142. }
  143. return $this;
  144. }
  145. public function removeRecipient(ApiMailRecipient $recipient): self
  146. {
  147. if ($this->recipients->removeElement($recipient)) {
  148. // set the owning side to null (unless already changed)
  149. if ($recipient->getApiMailRequest() === $this) {
  150. $recipient->setApiMailRequest(NULL);
  151. }
  152. }
  153. return $this;
  154. }
  155. public function getError(): ?bool
  156. {
  157. return $this->error;
  158. }
  159. public function setError(bool $error): self
  160. {
  161. $this->error = $error;
  162. return $this;
  163. }
  164. public function getErrorMessage(): ?string
  165. {
  166. return $this->errorMessage;
  167. }
  168. public function setErrorMessage(?string $errorMessage): self
  169. {
  170. $this->errorMessage = $errorMessage;
  171. return $this;
  172. }
  173. }