src/Entity/User.php line 22

  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Participation\Participation;
  4. use App\Entity\Traits\TimestampableTrait;
  5. use App\Repository\UserRepository;
  6. use App\Service\ParticipationService;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. use Doctrine\DBAL\Types\Types;
  10. use Doctrine\ORM\Mapping as ORM;
  11. use Symfony\Component\Serializer\Annotation\Groups;
  12. use Symfony\Component\Serializer\Annotation\SerializedName;
  13. use Symfony\Component\Validator\Constraints as Assert;
  14. use App\Validator as AppAssert;
  15. use Symfony\Component\Validator\Context\ExecutionContextInterface;
  16. #[ORM\Entity(repositoryClassUserRepository::class)]
  17. #[AppAssert\CheckLimitationParticipation()]
  18. class User
  19. {
  20.     use TimestampableTrait;
  21.     #[ORM\Id]
  22.     #[ORM\GeneratedValue]
  23.     #[ORM\Column]
  24.     private ?int $id null;
  25.     #[ORM\Column(length10nullabletrue)]
  26.     private ?string $civility null;
  27.     #[ORM\Column(length80nullabletrue)]
  28.     #[Assert\Regex(pattern"/^[\p{L}\-\s]+$/u"message'Ce champ est invalide')]
  29.     #[Groups(['consumer'])]
  30.     #[SerializedName('lastname')]
  31.     #[Assert\Length(
  32.         max14,
  33.         maxMessage'Le nombre de caractères ne doit pas dépasser 14',
  34.     )]
  35.     private ?string $lastname null;
  36.     #[ORM\Column(length80nullabletrue)]
  37.     #[Assert\Regex(pattern"/^[\p{L}\-\s]+$/u"message'Ce champ est invalide')]
  38.     #[Groups(['consumer'])]
  39.     #[Assert\Length(
  40.         max14,
  41.         maxMessage'Le nombre de caractères ne doit pas dépasser 14',
  42.     )]
  43.     private ?string $firstname null;
  44.     #[ORM\Column(length50nullablefalse)]
  45.     #[Assert\NotBlank(message"Le mail est obligatoire")]
  46.     #[Assert\Email(message"Le mail est incorrect"mode'strict')]
  47.     #[Groups(['consumer'])]
  48.     private ?string $email;
  49.     #[ORM\Column(length50nullabletrue)]
  50.     #[SerializedName('phone')]
  51.     #[Groups(['consumer'])]
  52.     private ?string $phone null;
  53.     #[ORM\Column(length255nullabletrue)]
  54.     #[Assert\Length(
  55.         max38,
  56.         maxMessage'Le nombre de caractères ne doit pas dépasser 38',
  57.     )]
  58.     #[SerializedName('address_3')]
  59.     #[Groups(['consumer'])]
  60.     private ?string $address;
  61.     #[ORM\Column(length40nullabletrue)]
  62.     #[Assert\Length(
  63.         max38,
  64.         maxMessage'Le nombre de caractères ne doit pas dépasser 38',
  65.     )]
  66.     #[SerializedName('address_1')]
  67.     #[Groups(['consumer'])]
  68.     private ?string $address2 null;
  69.     #[ORM\Column(name"zip_code"length10nullabletrue)]
  70.     #[SerializedName('postal_code')]
  71.     #[Assert\Regex(pattern"/^[0-9]{5}$/"message'Ce champ est invalide')]
  72.     #[Groups(['consumer'])]
  73.     private ?string $zipcode;
  74.     #[ORM\Column(length80nullabletrue)]
  75.     #[Assert\Regex(pattern"/^[\p{L}\-\'\s]+$/u"message'Ce champ est invalide')]
  76.     #[Groups(['consumer'])]
  77.     private ?string $city;
  78.     #[ORM\OneToMany(mappedBy'user'targetEntityParticipation::class)]
  79.     private Collection $participations;
  80.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  81.     #[Assert\LessThan(['value' => '-18 years''message' => "Tu dois être majeur pour participer"])]
  82.     private ?\DateTimeInterface $birthday null;
  83.     #[ORM\Column(length255)]
  84.     private ?string $emailCleaned null;
  85.     public function __construct()
  86.     {
  87.         $this->participations = new ArrayCollection();
  88.     }
  89.     public function getId(): ?int
  90.     {
  91.         return $this->id;
  92.     }
  93.     public function getCivility(): ?string
  94.     {
  95.         return $this->civility;
  96.     }
  97.     public function setCivility(?string $civility): self
  98.     {
  99.         $this->civility $civility;
  100.         return $this;
  101.     }
  102.     public function getLastname(): ?string
  103.     {
  104.         return $this->lastname;
  105.     }
  106.     public function setLastname(?string $lastname): self
  107.     {
  108.         $this->lastname $lastname;
  109.         return $this;
  110.     }
  111.     public function getFirstname(): ?string
  112.     {
  113.         return $this->firstname;
  114.     }
  115.     public function setFirstname(?string $firstname): self
  116.     {
  117.         $this->firstname $firstname;
  118.         return $this;
  119.     }
  120.     public function getEmail(): string
  121.     {
  122.         return $this->email;
  123.     }
  124.     public function setEmail(string $email): self
  125.     {
  126.         $this->email $email;
  127.         return $this;
  128.     }
  129.     public function getPhone(): ?string
  130.     {
  131.         return $this->phone;
  132.     }
  133.     public function setPhone(?string $phone): self
  134.     {
  135.         $this->phone $phone;
  136.         return $this;
  137.     }
  138.     public function getAddress(): ?string
  139.     {
  140.         return $this->address;
  141.     }
  142.     public function setAddress(string $address): self
  143.     {
  144.         $this->address $address;
  145.         return $this;
  146.     }
  147.     public function getAddress2(): ?string
  148.     {
  149.         return $this->address2;
  150.     }
  151.     public function setAddress2(?string $address2): self
  152.     {
  153.         $this->address2 $address2;
  154.         return $this;
  155.     }
  156.     public function getZipcode(): ?string
  157.     {
  158.         return $this->zipcode;
  159.     }
  160.     public function setZipcode(?string $zipcode): self
  161.     {
  162.         $this->zipcode $zipcode;
  163.         return $this;
  164.     }
  165.     public function getCity(): ?string
  166.     {
  167.         return $this->city;
  168.     }
  169.     public function setCity(?string $city): self
  170.     {
  171.         $this->city $city;
  172.         return $this;
  173.     }
  174.     /**
  175.      * @return Collection<int, Participation>
  176.      */
  177.     public function getParticipations(): Collection
  178.     {
  179.         return $this->participations;
  180.     }
  181.     public function addParticipation(Participation $participation): self
  182.     {
  183.         if (!$this->participations->contains($participation)) {
  184.             $this->participations->add($participation);
  185.             $participation->setUser($this);
  186.         }
  187.         return $this;
  188.     }
  189.     public function removeParticipation(Participation $participation): self
  190.     {
  191.         if ($this->participations->removeElement($participation)) {
  192.             // set the owning side to null (unless already changed)
  193.             if ($participation->getUser() === $this) {
  194.                 $participation->setUser(null);
  195.             }
  196.         }
  197.         return $this;
  198.     }
  199.     public function getBirthday(): ?\DateTimeInterface
  200.     {
  201.         return $this->birthday;
  202.     }
  203.     public function setBirthday(?\DateTimeInterface $birthday): self
  204.     {
  205.         $this->birthday $birthday;
  206.         return $this;
  207.     }
  208.     public function getEmailCleaned(): ?string
  209.     {
  210.         return $this->emailCleaned;
  211.     }
  212.     public function setEmailCleaned(?string $emailCleaned): self
  213.     {
  214.         $this->emailCleaned $emailCleaned;
  215.         return $this;
  216.     }
  217.     public function __toString(): string
  218.     {
  219.         return $this->getEmail();
  220.     }
  221.     #[SerializedName('date_birthday')]
  222.     #[Groups(['consumer'])]
  223.     public function getDateBirthay(): ?string
  224.     {
  225.         return $this->birthday;
  226.     }
  227.     #[SerializedName('civility')]
  228.     #[Groups(['consumer'])]
  229.     public function getConsumerCivility(): ?string
  230.     {
  231.         return $this->civility ?? ParticipationService::translateCivility($this->civility2);
  232.     }
  233.     #[Assert\Callback]
  234.     public function validate(ExecutionContextInterface $context$payload): void
  235.     {
  236.         if (!filter_var($this->emailFILTER_VALIDATE_EMAIL)) {
  237.             $context->buildViolation("Le format de l'e-mail ou les caractères insérés ne sont pas valides.")
  238.                 ->atPath('email')
  239.                 ->addViolation();
  240.         }
  241.     }
  242. }