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.         public function addRecipient(ApiMailRecipient $recipient): self
  121.         {
  122.             if (!$this->recipients->contains($recipient)) {
  123.                 $this->recipients[] = $recipient;
  124.                 $recipient->setApiMailRequest($this);
  125.             }
  126.             return $this;
  127.         }
  128.         public function removeRecipient(ApiMailRecipient $recipient): self
  129.         {
  130.             if ($this->recipients->removeElement($recipient)) {
  131.                 // set the owning side to null (unless already changed)
  132.                 if ($recipient->getApiMailRequest() === $this) {
  133.                     $recipient->setApiMailRequest(NULL);
  134.                 }
  135.             }
  136.             return $this;
  137.         }
  138.         public function getError(): ?bool
  139.         {
  140.             return $this->error;
  141.         }
  142.         public function setError(bool $error): self
  143.         {
  144.             $this->error $error;
  145.             return $this;
  146.         }
  147.         public function getErrorMessage(): ?string
  148.         {
  149.             return $this->errorMessage;
  150.         }
  151.         public function setErrorMessage(?string $errorMessage): self
  152.         {
  153.             $this->errorMessage $errorMessage;
  154.             return $this;
  155.         }
  156.     }