src/Entity/CRM/MailMessage.php line 17

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