src/Entity/User.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\UserRepository;
  4. use DateTime;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Component\Validator\Constraints as Assert;
  9. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  10. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  11. use Symfony\Component\Security\Core\User\UserInterface;
  12. #[ORM\Entity(repositoryClassUserRepository::class)]
  13. #[ORM\Table(name'users')]
  14. #[UniqueEntity(fields: ['email'], message'Cet email est déjà utilisé !')]
  15. class User implements UserInterfacePasswordAuthenticatedUserInterface
  16. {
  17.     //---------------------------------- ID ----------------------------------------------------//
  18.     #[ORM\Id]
  19.     #[ORM\GeneratedValue]
  20.     #[ORM\Column(name'id'type'integer'options: ['unsigned' => true])]
  21.     private ?int $id null;
  22.     //---------------------------------- EMAIL ----------------------------------------------------//
  23.     #[Assert\NotBlank(message'L\'email est obligatoire !')]
  24.     #[Assert\Regex(
  25.         pattern'/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/',
  26.         message'Le format de l\'email n\'est pas valide!',)]
  27.     #[ORM\Column(name'email'type'string'length180uniquetrue)]
  28.     private ?string $email null;
  29.     //---------------------------------- SOCIETE ----------------------------------------------------//
  30.     #[Assert\NotBlank(message'Le nom de la socièté est obligatoire!')]
  31.     #[ORM\Column(name'societe'type'string'length100)]
  32.     private ?string $societe null;
  33.     //---------------------------------- TELEPHONE (FIXE)  -------------------------------------------//
  34.     #[Assert\NotBlank(message'Le numéro de téléphone est obligatoire !')]
  35.     #[Assert\Regex(pattern'/\+?\d{1,4}?[-.\s]?\(?\d{1,3}?\)?[-.\s]?\d{1,4}[-.\s]?\d{1,4}[-.\s]?\d{1,9}/',
  36.         message'Le format du numéro de téléphone n\'est pas valide!')]
  37.     #[Assert\Length(
  38.         max20,
  39.         maxMessage'Le numéro de téléphone doit faire au maximun {{ limit }} caractères ! pas plus'
  40.     )]
  41.     #[ORM\Column(name'telephone'type'string'length20)]
  42.     private ?string $telephone null;
  43.     //---------------------------------- FAX ----------------------------------------------------//
  44.     #[Assert\NotBlank(message'Le numéro de fax est obligatoire !')]
  45.     #[Assert\Regex('/\+?\d{1,4}?[-.\s]?\(?\d{1,3}?\)?[-.\s]?\d{1,4}[-.\s]?\d{1,4}[-.\s]?\d{1,9}/',
  46.         message'Le format du numéro de fax n\'est pas valide!')]
  47.     #[ORM\Column(name'fax'type'string'length20)]
  48.     private ?string $fax null;
  49.     //---------------------------------- PORTABLE ----------------------------------------------------//
  50.     #[Assert\Regex(pattern'/\+?\d{1,4}?[-.\s]?\(?\d{1,3}?\)?[-.\s]?\d{1,4}[-.\s]?\d{1,4}[-.\s]?\d{1,9}/',
  51.         message'Le format du numéro de téléphone portable n\'est pas valide!')]
  52.     #[Assert\Length(
  53.         max20,
  54.         maxMessage'Le numéro de portable doit faire au maximum {{ limit }}  caractères !',
  55.     )]
  56.     #[ORM\Column(name'portable'type'integer'length15nullabletrue)]
  57.     private ?int $telephonePortable null;
  58.     //---------------------------------- PRENOM ----------------------------------------------------//
  59.     #[Assert\NotBlank(message'Le prénom est obligatoire !')]
  60.     #[Assert\Regex(
  61.         pattern'/\d/',
  62.         message'Votre prénom ne doit pas contenir de chiffres !',
  63.         match: false,
  64.     )]
  65.     #[Assert\Length(
  66.         min2max100,
  67.         minMessage'Le prénom doit faire au min {{ limit }} caractères !',
  68.         maxMessage'Le prénom doit faire au max {{ limit }} caractères !'
  69.     )]
  70.     #[ORM\Column(name'prenom'type'string'length120)]
  71.     private ?string $prenom null;
  72.     //---------------------------------- NOM ----------------------------------------------------//
  73.     #[Assert\NotBlank(message'Le nom est obligatoire !')]
  74.     #[Assert\Regex(
  75.         pattern'/\d/',
  76.         message'Votre nom ne doit pas contenir de chiffres !',
  77.         match: false,
  78.     )]
  79.     #[Assert\Length(
  80.         min2max100,
  81.         minMessage'Le nom doit faire au minimum {{ limit }} caractères !',
  82.         maxMessage'Le nom doit faire au maximum {{ limit }} caractères !'
  83.     )]
  84.     #[ORM\Column(name'nom'type'string'length120)]
  85.     private ?string $nom null;
  86.     //---------------------------------- FONCTION ----------------------------------------------------//
  87.     #[Assert\NotBlank(message'Votre fonction est obligatoire !')]
  88.     #[ORM\Column(name'fonction'type'string'length120)]
  89.     private ?string $profession null;
  90.     //---------------------------------- MOT DE PASSE ----------------------------------------------------//
  91.     /**
  92.      * @var string The hashed password
  93.      */
  94.     #[Assert\NotBlank(message'Un mot de passe est obligatoire')]
  95.     #[Assert\Regex(
  96.         pattern'/^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[!"#$%&()*+,-.\/:;<=>?@^_`{|}~]).{8,}$/',
  97.         message'Le mot de passe doit contenir au moins 8 caractères et être composé d\'au moins :
  98.          un chiffre, une minuscule, une majuscule et d\'un caractère spécial " !"#$%&()*+,-.\/:;<=>?@^_`{|}~ "!')]
  99.     #[ORM\Column(name'mot_passe',type'string')]
  100.     private string $password;
  101.     // Champs suplementaire (non visible sur le formulaire)
  102.     //---------------------------------- ROLES (GESTION DES ACCES) ----------------------------------------------------//
  103.     #[ORM\Column]
  104.     private array $roles = [];
  105.     //---------------------------------- COMPTE ACTIF ----------------------------------------------------//
  106.     #[ORM\Column (name'compte_active'type'boolean')]
  107.     private ?bool $compteActive null;
  108.     //---------------------------------- DATE D'INSCRIPTION ----------------------------------------------------//
  109.     #[ORM\Column(name'date_inscription'type'datetime')]
  110.     private ?datetime $dateInscription null;
  111.     //---------------------------------- DATE DE DERNIERE CONNEXION --------------------------------------------//
  112.     #[ORM\Column(name'date_der_connexion',type'datetime')]
  113.     private ?datetime $dateDerConnexion null;
  114.     ///---------------------------------- COMPTE VERIFIE (MAIL) --------------------------------------------//
  115.     #[ORM\Column(type'boolean')]
  116.     private bool $isVerified false;
  117.     //-----------------------------------------------------------------------------------------//
  118.     //---------------------------------------- RELATIONS --------------------------------------//
  119.     //---- type d'adherent----//
  120.     #[ORM\ManyToOne(inversedBy'users')]
  121.     private ?TypeAdherent $typeAdherent null;
  122.     //---- adresse----//
  123.     #[ORM\OneToOne(cascade: ['persist''remove'])]
  124.     private ?Adresse $adresse null;
  125.     //---- groupes ----//
  126.     #[ORM\OneToMany(mappedBy'user'targetEntityGroupe::class)]
  127.     private Collection $groupes;
  128.     #[ORM\OneToMany(mappedBy'user'targetEntityVehicule::class)]
  129.     private Collection $vehicules;
  130.     public function __construct()
  131.     {
  132.         $this->groupes = new ArrayCollection();
  133.         $this->vehicules = new ArrayCollection();
  134.     }
  135.     public function __toString(): string
  136.     {
  137.         return $this->societe;
  138.     }
  139.     //------------------------------------------------------------------------------------------------------------//
  140.     //------------------------------------------ GETTER SETTER----------------------------------------------------//
  141.     public function getId(): ?int
  142.     {
  143.         return $this->id;
  144.     }
  145.     /**
  146.      * @return string|null
  147.      */
  148.     public function getSociete(): ?string
  149.     {
  150.         return $this->societe;
  151.     }
  152.     /**
  153.      * @param string|null $societe
  154.      */
  155.     public function setSociete(?string $societe): void
  156.     {
  157.         $this->societe $societe;
  158.     }
  159.     /**
  160.      * @return string|null
  161.      */
  162.     public function getTelephone(): ?string
  163.     {
  164.         return $this->telephone;
  165.     }
  166.     /**
  167.      * @param string|null $telephone
  168.      */
  169.     public function setTelephone(?string $telephone): void
  170.     {
  171.         $this->telephone $telephone;
  172.     }
  173.     /**
  174.      * @return string|null
  175.      */
  176.     public function getFax(): ?string
  177.     {
  178.         return $this->fax;
  179.     }
  180.     /**
  181.      * @param string|null $fax
  182.      */
  183.     public function setFax(?string $fax): void
  184.     {
  185.         $this->fax $fax;
  186.     }
  187.     /**
  188.      * @return string|null
  189.      */
  190.     public function getTelephonePortable(): ?string
  191.     {
  192.         return $this->telephonePortable;
  193.     }
  194.     /**
  195.      * @param string|null $telephonePortable
  196.      */
  197.     public function setTelephonePortable(?string $telephonePortable): void
  198.     {
  199.         $this->telephonePortable $telephonePortable;
  200.     }
  201.     /**
  202.      * @return string|null
  203.      */
  204.     public function getPrenom(): ?string
  205.     {
  206.         return $this->prenom;
  207.     }
  208.     /**
  209.      * @param string|null $prenom
  210.      */
  211.     public function setPrenom(?string $prenom): void
  212.     {
  213.         $this->prenom $prenom;
  214.     }
  215.     /**
  216.      * @return string|null
  217.      */
  218.     public function getNom(): ?string
  219.     {
  220.         return $this->nom;
  221.     }
  222.     /**
  223.      * @param string|null $nom
  224.      */
  225.     public function setNom(?string $nom): void
  226.     {
  227.         $this->nom $nom;
  228.     }
  229.     /**
  230.      * @return string|null
  231.      */
  232.     public function getProfession(): ?string
  233.     {
  234.         return $this->profession;
  235.     }
  236.     /**
  237.      * @param string|null $profession
  238.      */
  239.     public function setProfession(?string $profession): void
  240.     {
  241.         $this->profession $profession;
  242.     }
  243.     /**
  244.      * @return bool|null
  245.      */
  246.     public function getCompteActive(): ?bool
  247.     {
  248.         return $this->compteActive;
  249.     }
  250.     /**
  251.      * @param bool|null $compteActive
  252.      */
  253.     public function setCompteActive(?bool $compteActive): void
  254.     {
  255.         $this->compteActive $compteActive;
  256.     }
  257.     /**
  258.      * @return DateTime|null
  259.      */
  260.     public function getDateInscription(): ?DateTime
  261.     {
  262.         return $this->dateInscription;
  263.     }
  264.     /**
  265.      * @param DateTime|null $dateInscription
  266.      */
  267.     public function setDateInscription(?DateTime $dateInscription): void
  268.     {
  269.         $this->dateInscription $dateInscription;
  270.     }
  271.     /**
  272.      * @return DateTime|null
  273.      */
  274.     public function getDateDerConnexion(): ?DateTime
  275.     {
  276.         return $this->dateDerConnexion;
  277.     }
  278.     /**
  279.      * @param DateTime|null $dateDerConnexion
  280.      */
  281.     public function setDateDerConnexion(?DateTime $dateDerConnexion): void
  282.     {
  283.         $this->dateDerConnexion $dateDerConnexion;
  284.     }
  285.     public function getEmail(): ?string
  286.     {
  287.         return $this->email;
  288.     }
  289.     public function setEmail(string $email): void
  290.     {
  291.         $this->email $email;
  292.     }
  293.     /**
  294.      * A visual identifier that represents this user.
  295.      *
  296.      * @see UserInterface
  297.      */
  298.     public function getUserIdentifier(): string
  299.     {
  300.         return (string) $this->email;
  301.     }
  302.     /**
  303.      * @see UserInterface
  304.      */
  305.     public function getRoles(): array
  306.     {
  307.         $roles $this->roles;
  308.         // guarantee every user at least has ROLE_USER
  309.         $roles[] = 'ROLE_USER';
  310.         return array_unique($roles);
  311.     }
  312.     public function setRoles(array $roles): void
  313.     {
  314.         $this->roles $roles;
  315.     }
  316.     /**
  317.      * @see PasswordAuthenticatedUserInterface
  318.      */
  319.     public function getPassword(): string
  320.     {
  321.         return $this->password;
  322.     }
  323.     public function setPassword(string $password): void
  324.     {
  325.         $this->password $password;
  326.     }
  327.     /**
  328.      * @see UserInterface
  329.      */
  330.     public function eraseCredentials()
  331.     {
  332.         // If you store any temporary, sensitive data on the user, clear it here
  333.         // $this->plainPassword = null;
  334.     }
  335.     public function isVerified(): bool
  336.     {
  337.         return $this->isVerified;
  338.     }
  339.     public function setIsVerified(bool $isVerified): void
  340.     {
  341.         $this->isVerified $isVerified;
  342.     }
  343.     public function getTypeAdherent(): ?TypeAdherent
  344.     {
  345.         return $this->typeAdherent;
  346.     }
  347.     public function setTypeAdherent(?TypeAdherent $typeAdherent): void
  348.     {
  349.         $this->typeAdherent $typeAdherent;
  350.     }
  351.     public function getAdresse(): ?Adresse
  352.     {
  353.         return $this->adresse;
  354.     }
  355.     public function setAdresse(Adresse $adresse): void
  356.     {
  357.         $this->adresse $adresse;
  358.     }
  359.     /**
  360.      * @return Collection<int, Groupe>
  361.      */
  362.     public function getGroupes(): Collection
  363.     {
  364.         return $this->groupes;
  365.     }
  366.     public function addGroupe(Groupe $groupe): self
  367.     {
  368.         if (!$this->groupes->contains($groupe)) {
  369.             $this->groupes->add($groupe);
  370.             $groupe->setUser($this);
  371.         }
  372.         return $this;
  373.     }
  374.     public function removeGroupe(Groupe $groupe): self
  375.     {
  376.         if ($this->groupes->removeElement($groupe)) {
  377.             // set the owning side to null (unless already changed)
  378.             if ($groupe->getUser() === $this) {
  379.                 $groupe->setUser(null);
  380.             }
  381.         }
  382.         return $this;
  383.     }
  384.     /**
  385.      * @return Collection<int, Vehicule>
  386.      */
  387.     public function getVehicules(): Collection
  388.     {
  389.         return $this->vehicules;
  390.     }
  391.     public function addVehicule(Vehicule $vehicule): self
  392.     {
  393.         if (!$this->vehicules->contains($vehicule)) {
  394.             $this->vehicules->add($vehicule);
  395.             $vehicule->setUser($this);
  396.         }
  397.         return $this;
  398.     }
  399.     public function removeVehicule(Vehicule $vehicule): self
  400.     {
  401.         if ($this->vehicules->removeElement($vehicule)) {
  402.             // set the owning side to null (unless already changed)
  403.             if ($vehicule->getUser() === $this) {
  404.                 $vehicule->setUser(null);
  405.             }
  406.         }
  407.         return $this;
  408.     }
  409. }