src/Entity/CRM/MailMessage.php line 16

  1. <?php
  2. namespace App\Entity\CRM;
  3. use App\Repository\MailMessageRepository;
  4. use DateTime;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\DBAL\Types\Types;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Symfony\Component\Validator\Constraints as Assert;
  10. #[ORM\Entity(repositoryClassMailMessageRepository::class)]
  11. #[ORM\Table(name'mail_message')]
  12. #[ORM\HasLifecycleCallbacks]
  13. class MailMessage
  14. {
  15.     #[ORM\Id]
  16.     #[ORM\GeneratedValue]
  17.     #[ORM\Column]
  18.     private ?int $id null;
  19.     #[Assert\NotBlank]
  20.     #[Assert\Length(max255)]
  21.     #[ORM\Column(length255)]
  22.     private string $subject '';
  23.     #[Assert\NotBlank]
  24.     #[ORM\Column(name'content_html'typeTypes::TEXT)]
  25.     private string $contentHtml '';
  26.     #[ORM\Column(name'is_active'typeTypes::BOOLEAN)]
  27.     private bool $isActive true;
  28.     #[ORM\Column(name'created_at'typeTypes::DATETIME_MUTABLE)]
  29.     private DateTime $createdAt;
  30.     #[ORM\Column(name'updated_at'typeTypes::DATETIME_MUTABLE)]
  31.     private DateTime $updatedAt;
  32.     #[ORM\OneToMany(mappedBy'mailMessage'targetEntityMailingSend::class)]
  33.     private Collection $mailingSends;
  34.     #[ORM\OneToMany(mappedBy'mailMessage'targetEntityMailAttachment::class, cascade: ['persist''remove'], orphanRemovaltrue)]
  35.     private Collection $mailAttachments;
  36.     public function __construct()
  37.     {
  38.         $now = new DateTime('now');
  39.         $this->createdAt $now;
  40.         $this->updatedAt $now;
  41.         $this->mailingSends = new ArrayCollection();
  42.         $this->mailAttachments = new ArrayCollection();
  43.     }
  44.     public function __toString(): string
  45.     {
  46.         return $this->id ' - ' $this->subject;
  47.     }
  48.     public function getId(): ?int
  49.     {
  50.         return $this->id;
  51.     }
  52.     public function getSubject(): string
  53.     {
  54.         return $this->subject;
  55.     }
  56.     public function setSubject(string $subject): self
  57.     {
  58.         $this->subject trim($subject);
  59.         return $this;
  60.     }
  61.     public function getContentHtml(): string
  62.     {
  63.         return $this->contentHtml;
  64.     }
  65.     public function setContentHtml(string $contentHtml): self
  66.     {
  67.         $this->contentHtml $contentHtml;
  68.         return $this;
  69.     }
  70.     public function isActive(): bool
  71.     {
  72.         return $this->isActive;
  73.     }
  74.     public function setIsActive(bool $isActive): self
  75.     {
  76.         $this->isActive $isActive;
  77.         return $this;
  78.     }
  79.     public function getCreatedAt(): DateTime
  80.     {
  81.         return $this->createdAt;
  82.     }
  83.     public function getUpdatedAt(): DateTime
  84.     {
  85.         return $this->updatedAt;
  86.     }
  87.     #[ORM\PrePersist]
  88.     public function onPrePersist(): void
  89.     {
  90.         $now = new DateTime('now');
  91.         $this->createdAt $now;
  92.         $this->updatedAt $now;
  93.         $this->subject trim($this->subject);
  94.     }
  95.     #[ORM\PreUpdate]
  96.     public function onPreUpdate(): void
  97.     {
  98.         $this->updatedAt = new DateTime('now');
  99.         $this->subject trim($this->subject);
  100.     }
  101.     /**
  102.      * @return Collection<int, MailingSend>
  103.      */
  104.     public function getMailingSends(): Collection
  105.     {
  106.         return $this->mailingSends;
  107.     }
  108.     public function addMailingSend(MailingSend $mailingSend): static
  109.     {
  110.         if (!$this->mailingSends->contains($mailingSend)) {
  111.             $this->mailingSends->add($mailingSend);
  112.             $mailingSend->setMailMessage($this);
  113.         }
  114.         return $this;
  115.     }
  116.     public function removeMailingSend(MailingSend $mailingSend): static
  117.     {
  118.         if ($this->mailingSends->removeElement($mailingSend)) {
  119.             if ($mailingSend->getMailMessage() === $this) {
  120.                 $mailingSend->setMailMessage(null);
  121.             }
  122.         }
  123.         return $this;
  124.     }
  125.     /**
  126.      * @return Collection<int, MailAttachment>
  127.      */
  128.     public function getMailAttachments(): Collection
  129.     {
  130.         return $this->mailAttachments;
  131.     }
  132.     public function addMailAttachment(MailAttachment $mailAttachment): static
  133.     {
  134.         if (!$this->mailAttachments->contains($mailAttachment)) {
  135.             $this->mailAttachments->add($mailAttachment);
  136.             $mailAttachment->setMailMessage($this);
  137.         }
  138.         return $this;
  139.     }
  140.     public function removeMailAttachment(MailAttachment $mailAttachment): static
  141.     {
  142.         if ($this->mailAttachments->removeElement($mailAttachment)) {
  143.             if ($mailAttachment->getMailMessage() === $this) {
  144.                 $mailAttachment->setMailMessage(null);
  145.             }
  146.         }
  147.         return $this;
  148.     }
  149. }