src/Entity/Contact.php line 15

  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Traits\TimestampableTrait;
  4. use App\Repository\ContactRepository;
  5. use Doctrine\DBAL\Types\Types;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\Validator\Constraints as Assert;
  8. use App\Validator as AppAssert;
  9. use Symfony\Component\Validator\Context\ExecutionContextInterface;
  10. #[ORM\Entity(repositoryClassContactRepository::class)]
  11. #[AppAssert\CheckExistedParticipation()]
  12. class Contact
  13. {
  14.     use TimestampableTrait;
  15.     #[ORM\Id]
  16.     #[ORM\GeneratedValue]
  17.     #[ORM\Column]
  18.     private ?int $id null;
  19.     #[ORM\Column(length10nullabletrue)]
  20.     #[Assert\NotBlank(message"La civilité est obligatoire")]
  21.     private ?string $civility null;
  22.     #[ORM\Column(length80)]
  23.     #[Assert\NotBlank(message"Le nom est obligatoire")]
  24.     #[Assert\Regex(pattern"/^[\p{L}\-\s]+$/u"message'Ce champ est invalide')]
  25.     private string $lastname;
  26.     #[ORM\Column(length80)]
  27.     #[Assert\NotBlank(message"Le prénom est obligatoire")]
  28.     #[Assert\Regex(pattern"/^[\p{L}\-\s]+$/u"message'Ce champ est invalide')]
  29.     private string $firstname;
  30.     #[ORM\Column(length50)]
  31.     #[Assert\NotBlank(message"Le mail est obligatoire")]
  32.     private string $email;
  33.     #[ORM\Column(length255nullabletrue)]
  34.     private ?string $reference null;
  35.     #[ORM\Column(length255)]
  36.     #[Assert\NotBlank(message"Le sujet est obligatoire")]
  37.     private string $title;
  38.     #[ORM\Column(typeTypes::TEXT)]
  39.     #[Assert\NotBlank(message"Le message est obligatoire")]
  40.     private string $message;
  41.     public function getId(): ?int
  42.     {
  43.         return $this->id;
  44.     }
  45.     public function getCivility(): ?string
  46.     {
  47.         return $this->civility;
  48.     }
  49.     public function setCivility(?string $civility): self
  50.     {
  51.         $this->civility $civility;
  52.         return $this;
  53.     }
  54.     public function getLastname(): string
  55.     {
  56.         return $this->lastname;
  57.     }
  58.     public function setLastname(string $lastname): self
  59.     {
  60.         $this->lastname $lastname;
  61.         return $this;
  62.     }
  63.     public function getFirstname(): string
  64.     {
  65.         return $this->firstname;
  66.     }
  67.     public function setFirstname(string $firstname): self
  68.     {
  69.         $this->firstname $firstname;
  70.         return $this;
  71.     }
  72.     public function getEmail(): string
  73.     {
  74.         return $this->email;
  75.     }
  76.     public function setEmail(string $email): self
  77.     {
  78.         $this->email $email;
  79.         return $this;
  80.     }
  81.     public function getReference(): ?string
  82.     {
  83.         return $this->reference;
  84.     }
  85.     public function setReference(?string $reference): self
  86.     {
  87.         $this->reference $reference;
  88.         return $this;
  89.     }
  90.     public function getTitle(): string
  91.     {
  92.         return $this->title;
  93.     }
  94.     public function setTitle(string $title): self
  95.     {
  96.         $this->title $title;
  97.         return $this;
  98.     }
  99.     public function getMessage(): string
  100.     {
  101.         return $this->message;
  102.     }
  103.     public function setMessage(string $message): self
  104.     {
  105.         $this->message $message;
  106.         return $this;
  107.     }
  108.     public function __toArray()
  109.     {
  110.         return call_user_func('get_object_vars'$this);
  111.     }
  112.     #[Assert\Callback]
  113.     public function validate(ExecutionContextInterface $context$payload): void
  114.     {
  115.         if (array_key_exists('email'$this->__toArray()) && !filter_var($this->emailFILTER_VALIDATE_EMAIL)) {
  116.             $context->buildViolation("Le format de l'e-mail ou les caractères insérés ne sont pas valides.")
  117.                 ->atPath('email')
  118.                 ->addViolation();
  119.         }
  120.     }
  121. }