src/Entity/User.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Trait\isActif;
  4. use App\Entity\Trait\isSlugger;
  5. use App\Repository\UserRepository;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  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. /**
  13.  * @ORM\Entity(repositoryClass=UserRepository::class)
  14.  * @UniqueEntity(fields={"email"}, message="Il éxiste déjà un compte possédant cet email")
  15.  * @UniqueEntity("slug")
  16.  */
  17. class User implements UserInterfacePasswordAuthenticatedUserInterface
  18. {
  19.     use isActif;
  20.     /**
  21.      * @ORM\Id
  22.      * @ORM\GeneratedValue
  23.      * @ORM\Column(type="integer")
  24.      */
  25.     private $id;
  26.     /**
  27.      * @ORM\Column(type="string", length=180, unique=true)
  28.      */
  29.     private $email;
  30.     /**
  31.      * @ORM\Column(type="json")
  32.      */
  33.     private $roles = [];
  34.     /**
  35.      * @var string The hashed password
  36.      * @ORM\Column(type="string")
  37.      */
  38.     private $password;
  39.     /**
  40.      * @ORM\Column(type="boolean")
  41.      */
  42.     private $isVerified false;
  43.     /**
  44.      * @ORM\ManyToOne(targetEntity=Enterprise::class, inversedBy="users", cascade={"persist"})
  45.      */
  46.     private $enterprise;
  47.     /**
  48.      * @ORM\Column(type="string", length=255)
  49.      */
  50.     private $firstname;
  51.     /**
  52.      * @ORM\Column(type="string", length=255)
  53.      */
  54.     private $lastname;
  55.     /**
  56.      * @ORM\OneToMany(targetEntity=Contract::class, mappedBy="user")
  57.      */
  58.     private $contracts;
  59.     /**
  60.      * @ORM\Column(type="string", length=255)
  61.      */
  62.     private $slug;
  63.     /**
  64.      * @ORM\Column(type="boolean")
  65.      */
  66.     private $createPassword false;
  67.     /**
  68.      * @ORM\Column(type="string", length=255, nullable=true)
  69.      */
  70.     private $resetToken;
  71.     /**
  72.      * @ORM\Column(type="string", length=255, nullable=true)
  73.      */
  74.     private $stripeId;
  75.     public function __construct()
  76.     {
  77.         $this->contracts = new ArrayCollection();
  78.         $this->abonnements = new ArrayCollection();
  79.         $this->cards = new ArrayCollection();
  80.     }
  81.     public function getId(): ?int
  82.     {
  83.         return $this->id;
  84.     }
  85.     public function getEmail(): ?string
  86.     {
  87.         return $this->email;
  88.     }
  89.     public function setEmail(string $email): self
  90.     {
  91.         $this->email $email;
  92.         return $this;
  93.     }
  94.     /**
  95.      * A visual identifier that represents this user.
  96.      *
  97.      * @see UserInterface
  98.      */
  99.     public function getUserIdentifier(): string
  100.     {
  101.         return (string) $this->email;
  102.     }
  103.     /**
  104.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  105.      */
  106.     public function getUsername(): string
  107.     {
  108.         return (string) $this->email;
  109.     }
  110.     /**
  111.      * @see UserInterface
  112.      */
  113.     public function getRoles(): array
  114.     {
  115.         $roles $this->roles;
  116.         // guarantee every user at least has ROLE_USER
  117.         $roles[] = 'ROLE_USER';
  118.         return array_unique($roles);
  119.     }
  120.     public function setRoles(array $roles): self
  121.     {
  122.         $this->roles $roles;
  123.         return $this;
  124.     }
  125.     /**
  126.      * @see PasswordAuthenticatedUserInterface
  127.      */
  128.     public function getPassword(): string
  129.     {
  130.         return $this->password;
  131.     }
  132.     public function setPassword(string $password): self
  133.     {
  134.         $this->password $password;
  135.         return $this;
  136.     }
  137.     /**
  138.      * Returning a salt is only needed, if you are not using a modern
  139.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  140.      *
  141.      * @see UserInterface
  142.      */
  143.     public function getSalt(): ?string
  144.     {
  145.         return null;
  146.     }
  147.     /**
  148.      * @see UserInterface
  149.      */
  150.     public function eraseCredentials()
  151.     {
  152.         // If you store any temporary, sensitive data on the user, clear it here
  153.         // $this->plainPassword = null;
  154.     }
  155.     public function isVerified(): bool
  156.     {
  157.         return $this->isVerified;
  158.     }
  159.     public function setIsVerified(bool $isVerified): self
  160.     {
  161.         $this->isVerified $isVerified;
  162.         return $this;
  163.     }
  164.     public function getEnterprise(): ?Enterprise
  165.     {
  166.         return $this->enterprise;
  167.     }
  168.     public function setEnterprise(?Enterprise $enterprise): self
  169.     {
  170.         $this->enterprise $enterprise;
  171.         return $this;
  172.     }
  173.     public function getFirstname(): ?string
  174.     {
  175.         return $this->firstname;
  176.     }
  177.     public function setFirstname(string $firstname): self
  178.     {
  179.         $this->firstname $firstname;
  180.         return $this;
  181.     }
  182.     public function getLastname(): ?string
  183.     {
  184.         return $this->lastname;
  185.     }
  186.     public function setLastname(string $lastname): self
  187.     {
  188.         $this->lastname $lastname;
  189.         return $this;
  190.     }
  191.     public function getFullName(): string
  192.     {
  193.         return $this->firstname === null $this->lastname $this->firstname ' ' $this->lastname;
  194.     }
  195.     /**
  196.      * @return Collection|Contract[]
  197.      */
  198.     public function getContracts(): Collection
  199.     {
  200.         return $this->contracts;
  201.     }
  202.     public function addContract(Contract $contract): self
  203.     {
  204.         if (! $this->contracts->contains($contract)) {
  205.             $this->contracts[] = $contract;
  206.             $contract->setUser($this);
  207.         }
  208.         return $this;
  209.     }
  210.     public function removeContract(Contract $contract): self
  211.     {
  212.         if ($this->contracts->removeElement($contract)) {
  213.             // set the owning side to null (unless already changed)
  214.             if ($contract->getUser() === $this) {
  215.                 $contract->setUser(null);
  216.             }
  217.         }
  218.         return $this;
  219.     }
  220.     public function getSlug(): ?string
  221.     {
  222.         return $this->slug;
  223.     }
  224.     public function setSlug(string $slug): self
  225.     {
  226.         $this->slug $slug;
  227.         return $this;
  228.     }
  229.     public function getNameRole()
  230.     {
  231.         $role $this->getRoles()[0];
  232.         return match (true) {
  233.             $role === "ROLE_ADMIN" => "Administrateur de l'entreprise",
  234.             $role === "ROLE_MANAGER" => "Manager de l'entreprise",
  235.             $role === "ROLE_SUPERADMIN_RECYCLINK" => "Administrateur recyclink",
  236.         };
  237.     }
  238.     public function getCreatePassword(): ?bool
  239.     {
  240.         return $this->createPassword;
  241.     }
  242.     public function setCreatePassword(bool $createPassword): self
  243.     {
  244.         $this->createPassword $createPassword;
  245.         return $this;
  246.     }
  247.     public function getResetToken(): ?string
  248.     {
  249.         return $this->resetToken;
  250.     }
  251.     public function setResetToken(?string $resetToken): self
  252.     {
  253.         $this->resetToken $resetToken;
  254.         return $this;
  255.     }
  256.     public function getStripeId(): ?string
  257.     {
  258.         return $this->stripeId;
  259.     }
  260.     public function setStripeId(?string $stripeId): self
  261.     {
  262.         $this->stripeId $stripeId;
  263.         return $this;
  264.     }
  265. }