src/Entity/EmailTemplate.php line 19

  1. <?php
  2. /*
  3.  *  @author Guerby Duval <info@tranzaksyon.com>
  4.  *  @link https://tranzaksyon.com
  5.  *  @copyright You are not allowed to remove this author "Guerby Duval <info@tranzaksyon.com>", the link "https://tranzaksyon.com" neither this copyright.
  6.  */
  7. namespace App\Entity;
  8. use App\Repository\EmailTemplateRepository;
  9. use Doctrine\DBAL\Types\Types;
  10. use Doctrine\ORM\Mapping as ORM;
  11. use Symfony\Component\Validator\Constraints\Callback;
  12. use Symfony\Component\Validator\Constraints\NotBlank;
  13. use Symfony\Component\Validator\ConstraintViolation;
  14. use Symfony\Component\Validator\Context\ExecutionContextInterface;
  15. #[ORM\Entity(repositoryClassEmailTemplateRepository::class)]
  16. class EmailTemplate
  17. {
  18.     #[ORM\Id]
  19.     #[ORM\GeneratedValue]
  20.     #[ORM\Column]
  21.     private ?int $id null;
  22.     #[ORM\Column(length255nullabletrue)]
  23.     private ?string $title null;
  24.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  25.     private ?string $template null;
  26.     #[ORM\Column(nullabletrue)]
  27.     private ?bool $html null;
  28.     #[ORM\Column(length20nullabletrue)]
  29.     private ?string $invoiceType null;
  30.     #[ORM\ManyToOne(inversedBy'emailTemplates')]
  31.     #[ORM\JoinColumn(nullabletrue)]
  32.     private ?EmailConfiguration $configuration null;
  33.     #[ORM\Column(nullabletrue)]
  34.     private ?bool $isDefault null;
  35.     #[ORM\Column(nullabletrue)]
  36.     private ?bool $useDefault null;
  37.     public function getId(): ?int
  38.     {
  39.         return $this->id;
  40.     }
  41.     public function getTitle(): ?string
  42.     {
  43.         return $this->title;
  44.     }
  45.     public function setTitle(?string $title): self
  46.     {
  47.         $this->title $title;
  48.         return $this;
  49.     }
  50.     public function getTemplate(): ?string
  51.     {
  52.         return $this->template;
  53.     }
  54.     public function setTemplate(?string $template): self
  55.     {
  56.         $this->template $template;
  57.         return $this;
  58.     }
  59.     public function isHtml(): ?bool
  60.     {
  61.         return $this->html;
  62.     }
  63.     public function setHtml(?bool $html): self
  64.     {
  65.         $this->html $html;
  66.         return $this;
  67.     }
  68.     public function getInvoiceType(): ?string
  69.     {
  70.         return $this->invoiceType;
  71.     }
  72.     public function setInvoiceType(string $invoiceType): self
  73.     {
  74.         $this->invoiceType $invoiceType;
  75.         return $this;
  76.     }
  77.     public function getConfiguration(): ?EmailConfiguration
  78.     {
  79.         return $this->configuration;
  80.     }
  81.     public function setConfiguration(?EmailConfiguration $configuration): self
  82.     {
  83.         $this->configuration $configuration;
  84.         return $this;
  85.     }
  86.     public function isIsDefault(): ?bool
  87.     {
  88.         return $this->isDefault;
  89.     }
  90.     public function setIsDefault(?bool $isDefault): self
  91.     {
  92.         $this->isDefault $isDefault;
  93.         return $this;
  94.     }
  95.     public function isUseDefault(): ?bool
  96.     {
  97.         return $this->useDefault;
  98.     }
  99.     public function setUseDefault(?bool $useDefault): self
  100.     {
  101.         $this->useDefault $useDefault;
  102.         return $this;
  103.     }
  104.     #[Callback(payload'title')]
  105.     public function isTitleValid(ExecutionContextInterface $context)
  106.     {
  107.         if (!$this->isUseDefault()) {
  108.             $validations $context->getValidator()->validate($this->getTitle(), [new NotBlank()]);
  109.             /** @var ConstraintViolation $validation */
  110.             foreach ($validations as $validation) {
  111.                 $context->buildViolation($validation->getMessage())->atPath('title')->addViolation();
  112.             }
  113.         }
  114.     }
  115.     #[Callback(payload'template')]
  116.     public function isTemplateValid(ExecutionContextInterface $context)
  117.     {
  118.         if (!$this->isUseDefault()) {
  119.             $validations $context->getValidator()->validate($this->getTemplate(), [new NotBlank()]);
  120.             /** @var ConstraintViolation $validation */
  121.             foreach ($validations as $validation) {
  122.                 $context->buildViolation($validation->getMessage())->atPath('template')->addViolation();
  123.             }
  124.         }
  125.     }
  126. }