src/Entity/User.php line 22

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use App\Repository\UserRepository;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use libphonenumber\PhoneNumber;
  8. use Symfony\Component\Security\Core\User\UserInterface;
  9. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  10. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  11. use Symfony\Component\Uid\Uuid;
  12. /**
  13.  * Table pour la gestion des utilisateurs
  14.  *
  15.  * @ORM\Entity(repositoryClass=UserRepository::class)
  16.  * @UniqueEntity(fields={"email"},message="Un compte exist déjà avec ce mail")
  17.  * @UniqueEntity(fields={"cardNumber"},message="Un compte exist déjà pour ce numéro de pièce d'identité")
  18.  */
  19. class User implements UserInterfacePasswordAuthenticatedUserInterface
  20. {
  21.     /**
  22.      * @ORM\Id
  23.      * @ORM\Column(type="uuid", unique=true)
  24.      * @ORM\GeneratedValue(strategy="CUSTOM")
  25.      * @ORM\CustomIdGenerator(class="doctrine.uuid_generator")
  26.      */
  27.     private $id;
  28.     /**
  29.      * @ORM\Column(name="email", type="string", length=255, nullable=true)
  30.      */
  31.     private $email;
  32.     /**
  33.      * @ORM\Column(type="json", nullable=true)
  34.      */
  35.     private $roles = [];
  36.     /**
  37.      * @var string The hashed password
  38.      * @ORM\Column(type="string", nullable=true)
  39.      */
  40.     private $password;
  41.     /**
  42.      * @ORM\Column(type="string", length=255, nullable=true)
  43.      */
  44.     private $name;
  45.     /**
  46.      * @ORM\Column(type="phone_number", length=255, nullable=true)
  47.      */
  48.     private $number;
  49.     /**
  50.      * @ORM\Column(type="string", length=255, nullable=true)
  51.      */
  52.     private $location;
  53.     /**
  54.      * @ORM\Column(type="string", length=255, nullable=true)
  55.      */
  56.     private $position;
  57.     /**
  58.      * @ORM\OneToMany(targetEntity=Requests::class, mappedBy="userRequest", cascade={"persist", "remove"})
  59.      */
  60.     private $requests;
  61.     /**
  62.      * @ORM\Column(type="string", length=255, nullable=true)
  63.      */
  64.     private $profile;
  65.     /**
  66.      * @ORM\Column(type="boolean", length=255, nullable=true)
  67.      */
  68.     private $locked true;
  69.     /**
  70.      * @ORM\OneToMany(targetEntity=History::class, mappedBy="user", cascade={"persist", "remove"})
  71.      */
  72.     private $histories;
  73.     /**
  74.      * @ORM\Column(type="string", length=255, nullable=true)
  75.      */
  76.     private $token;
  77.     /**
  78.      * @ORM\Column(type="string", length=255, nullable=true)
  79.      */
  80.     private $picture;
  81.     /**
  82.      * @ORM\Column(type="string", length=255, nullable=true)
  83.      */
  84.     private $idCard;
  85.     /**
  86.      * @ORM\Column(type="string", length=255, nullable=true)
  87.      */
  88.     private $cardNumber;
  89.     /**
  90.      * @ORM\Column(type="array", nullable=true)
  91.      */
  92.     private $certificate = [];
  93.     /**
  94.      * @ORM\Column(type="boolean")
  95.      */
  96.     private $verified false;
  97.     /**
  98.      * @ORM\Column(type="string", length=255, nullable=true)
  99.      */
  100.     private $verifiedToken;
  101.     /**
  102.      * @ORM\Column(type="datetime", nullable=true)
  103.      */
  104.     private $verifiedExpiration;
  105.     /**
  106.      * @ORM\Column(type="boolean",)
  107.      */
  108.     private $updatedPassword false;
  109.     /**
  110.      * @ORM\Column(type="string", length=255, nullable=true)
  111.      */
  112.     private $civility;
  113.     /**
  114.      * @ORM\Column(type="string", length=255, nullable=true)
  115.      */
  116.     private $city;
  117.     /**
  118.      * @ORM\Column(type="string", length=255, nullable=true)
  119.      */
  120.     private $residence;
  121.     /**
  122.      * @ORM\Column(type="string", length=255, nullable=true)
  123.      */
  124.     private $companyName;
  125.     public function __construct()
  126.     {
  127.         $this->requests = new ArrayCollection();
  128.         $this->histories = new ArrayCollection();
  129.     }
  130.     public function getId(): ?Uuid
  131.     {
  132.         return $this->id;
  133.     }
  134.     public function getEmail(): ?string
  135.     {
  136.         return $this->email;
  137.     }
  138.     public function setEmail(?string $email): self
  139.     {
  140.         $this->email $email;
  141.         return $this;
  142.     }
  143.     /**
  144.      * A visual identifier that represents this user.
  145.      *
  146.      * @see UserInterface
  147.      */
  148.     public function getUserIdentifier(): string
  149.     {
  150.         return (string) $this->email;
  151.     }
  152.     /**
  153.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  154.      */
  155.     public function getUsername(): string
  156.     {
  157.         return (string) $this->email;
  158.     }
  159.     /**
  160.      * @see UserInterface
  161.      */
  162.     public function getRoles(): array
  163.     {
  164.         $roles $this->roles;
  165.         // guarantee every user at least has ROLE_USER
  166.         if(!in_array('ROLE_ADMIN'$rolestrue) && !in_array('ROLE_MANAGER'$rolestrue)){
  167.             $roles[] = 'ROLE_USER';
  168.         }
  169.         return array_unique($roles);
  170.     }
  171.     public function setRoles(array $roles): self
  172.     {
  173.         $this->roles $roles ?? ['ROLE_USER'];
  174.         return $this;
  175.     }
  176.     /**
  177.      * @see PasswordAuthenticatedUserInterface
  178.      */
  179.     public function getPassword(): string
  180.     {
  181.         return $this->password;
  182.     }
  183.     public function setPassword(?string $password): self
  184.     {
  185.         $this->password $password;
  186.         return $this;
  187.     }
  188.     /**
  189.      * Returning a salt is only needed, if you are not using a modern
  190.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  191.      *
  192.      * @see UserInterface
  193.      */
  194.     public function getSalt(): ?string
  195.     {
  196.         return null;
  197.     }
  198.     /**
  199.      * @see UserInterface
  200.      */
  201.     public function eraseCredentials()
  202.     {
  203.         // If you store any temporary, sensitive data on the user, clear it here
  204.         // $this->plainPassword = null;
  205.     }
  206.     public function getName(): ?string
  207.     {
  208.         return $this->name;
  209.     }
  210.     public function setName(?string $name): self
  211.     {
  212.         $this->name $name;
  213.         return $this;
  214.     }
  215.     public function getNumber(): ?PhoneNumber
  216.     {
  217.         return $this->number;
  218.     }
  219.     public function setNumber(?PhoneNumber $number): self
  220.     {
  221.         $this->number $number;
  222.         return $this;
  223.     }
  224.     public function getLocation(): ?string
  225.     {
  226.         return $this->location;
  227.     }
  228.     public function setLocation(?string $location): self
  229.     {
  230.         $this->location $location;
  231.         return $this;
  232.     }
  233.     public function getPosition(): ?string
  234.     {
  235.         return $this->position;
  236.     }
  237.     public function setPosition(?string $position): self
  238.     {
  239.         $this->position $position;
  240.         return $this;
  241.     }
  242.     /**
  243.      * @return Collection<int, Requests>
  244.      */
  245.     public function getRequests(): Collection
  246.     {
  247.         return $this->requests;
  248.     }
  249.     public function addRequest(Requests $request): self
  250.     {
  251.         if (!$this->requests->contains($request)) {
  252.             $this->requests[] = $request;
  253.             $request->setUserRequest($this);
  254.         }
  255.         return $this;
  256.     }
  257.     public function removeRequest(Requests $request): self
  258.     {
  259.         if ($this->requests->removeElement($request)) {
  260.             // set the owning side to null (unless already changed)
  261.             if ($request->getUserRequest() === $this) {
  262.                 $request->setUserRequest(null);
  263.             }
  264.         }
  265.         return $this;
  266.     }
  267.     public function getProfile(): ?string
  268.     {
  269.         return $this->profile;
  270.     }
  271.     public function setProfile(?string $profile): self
  272.     {
  273.         $this->profile $profile;
  274.         return $this;
  275.     }
  276.     public function isLocked(): ?bool
  277.     {
  278.         return $this->locked;
  279.     }
  280.     public function setLocked(?bool $locked): self
  281.     {
  282.         $this->locked $locked;
  283.         return $this;
  284.     }
  285.     /**
  286.      * @return Collection<int, History>
  287.      */
  288.     public function getHistories(): Collection
  289.     {
  290.         return $this->histories;
  291.     }
  292.     public function addHistory(History $history): self
  293.     {
  294.         if (!$this->histories->contains($history)) {
  295.             $this->histories[] = $history;
  296.             $history->setUser($this);
  297.         }
  298.         return $this;
  299.     }
  300.     public function removeHistory(History $history): self
  301.     {
  302.         if ($this->histories->removeElement($history)) {
  303.             // set the owning side to null (unless already changed)
  304.             if ($history->getUser() === $this) {
  305.                 $history->setUser(null);
  306.             }
  307.         }
  308.         return $this;
  309.     }
  310.     public function getToken(): ?string
  311.     {
  312.         return $this->token;
  313.     }
  314.     public function setToken(?string $token): self
  315.     {
  316.         $this->token $token;
  317.         return $this;
  318.     }
  319.     public function getPicture(): ?string
  320.     {
  321.         return $this->picture;
  322.     }
  323.     public function setPicture(?string $picture): self
  324.     {
  325.         $this->picture $picture;
  326.         return $this;
  327.     }
  328.     public function getIdCard(): ?string
  329.     {
  330.         return $this->idCard;
  331.     }
  332.     public function setIdCard(?string $idCard): self
  333.     {
  334.         $this->idCard $idCard;
  335.         return $this;
  336.     }
  337.     public function getCardNumber(): ?string
  338.     {
  339.         return $this->cardNumber;
  340.     }
  341.     public function setCardNumber(?string $cardNumber): self
  342.     {
  343.         $this->cardNumber $cardNumber;
  344.         return $this;
  345.     }
  346.     public function getCertificate(): ?array
  347.     {
  348.         return array_unique($this->certificate);
  349.     }
  350.     public function setCertificate(?array $certificate): self
  351.     {
  352.         $this->certificate $certificate;
  353.         return $this;
  354.     }
  355.     public function isVerified(): ?bool
  356.     {
  357.         return $this->verified;
  358.     }
  359.     public function setVerified(bool $verified): self
  360.     {
  361.         $this->verified $verified;
  362.         return $this;
  363.     }
  364.     public function getVerifiedToken(): ?string
  365.     {
  366.         return $this->verifiedToken;
  367.     }
  368.     public function setVerifiedToken(?string $verifiedToken): self
  369.     {
  370.         $this->verifiedToken $verifiedToken;
  371.         return $this;
  372.     }
  373.     public function getVerifiedExpiration(): ?\DateTimeInterface
  374.     {
  375.         return $this->verifiedExpiration;
  376.     }
  377.     public function setVerifiedExpiration(?\DateTimeInterface $verifiedExpiration): self
  378.     {
  379.         $this->verifiedExpiration $verifiedExpiration;
  380.         return $this;
  381.     }
  382.     public function isUpdatedPassword(): ?bool
  383.     {
  384.         return $this->updatedPassword;
  385.     }
  386.     public function setUpdatedPassword(bool $updatedPassword): self
  387.     {
  388.         $this->updatedPassword $updatedPassword;
  389.         return $this;
  390.     }
  391.     public function getCivility(): ?string
  392.     {
  393.         return $this->civility;
  394.     }
  395.     public function setCivility(?string $civility): self
  396.     {
  397.         $this->civility $civility;
  398.         return $this;
  399.     }
  400.     public function getCity(): ?string
  401.     {
  402.         return $this->city;
  403.     }
  404.     public function setCity(?string $city): self
  405.     {
  406.         $this->city $city;
  407.         return $this;
  408.     }
  409.     public function getResidence(): ?string
  410.     {
  411.         return $this->residence;
  412.     }
  413.     public function setResidence(?string $residence): self
  414.     {
  415.         $this->residence $residence;
  416.         return $this;
  417.     }
  418.     public function getCompanyName(): ?string
  419.     {
  420.         return $this->companyName;
  421.     }
  422.     public function setCompanyName(?string $companyName): self
  423.     {
  424.         $this->companyName $companyName;
  425.         return $this;
  426.     }
  427. }