src/Entity/Gestiform/Users/User.php line 35

  1. <?php
  2. namespace App\Entity\Gestiform\Users;
  3. use App\Entity\AbstractEntity;
  4. use App\Entity\Common\Adresse;
  5. use App\Entity\Common\Upload;
  6. use App\Entity\Trait\ApiGestiformEntity;
  7. use App\Enums\RolesEnum;
  8. use App\Repository\Gestiform\Users\UserRepository;
  9. use Doctrine\Common\Collections\ArrayCollection;
  10. use Doctrine\ORM\Mapping as ORM;
  11. use Doctrine\ORM\Mapping\DiscriminatorColumn;
  12. use Doctrine\ORM\Mapping\DiscriminatorMap;
  13. use Doctrine\ORM\Mapping\InheritanceType;
  14. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  15. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  16. use Symfony\Component\Security\Core\User\UserInterface;
  17. use Symfony\Component\Validator\Constraints\NotBlank;
  18. #[ORM\Entity(repositoryClassUserRepository::class)]
  19. #[UniqueEntity('email'message'cette adresse email est déja prise')]
  20. #[InheritanceType('JOINED')]
  21. #[DiscriminatorColumn(name'type'type'string')]
  22. #[DiscriminatorMap(['user' => User::class, 'employe' => Employe::class, 'apprenant' => Apprenant::class, 'formateur' => Formateur::class, 'personne' => Personne::class])]
  23. class User extends AbstractEntity implements UserInterfacePasswordAuthenticatedUserInterface
  24. {
  25.     use ApiGestiformEntity;
  26.     #[ORM\Column(type'string'length255nullablefalse)]
  27.     #[NotBlank]
  28.     protected string $email;
  29.     #[ORM\Column(type'string'length500nullabletrue)]
  30.     protected ?string $password null;
  31.     #[ORM\Column(type'string'length500nullabletrue)]
  32.     private ?string $plainPassword null;
  33.     #[ORM\Column(type'json')]
  34.     protected array $roles = [];
  35.     #[ORM\Column(type'boolean')]
  36.     protected bool $enabled true;
  37.     #[ORM\Column(type'boolean'nullabletrue)]
  38.     protected ?bool $status null;
  39.     #[ORM\Column(type'boolean'nullabletrue)]
  40.     private ?bool $rgpd false;
  41.     #[ORM\JoinColumn(nullabletrue)]
  42.     #[ORM\ManyToOne(targetEntityAdresse::class, cascade: ['all'])]
  43.     protected ?Adresse $adresse null;
  44.     #[ORM\JoinColumn(nullabletrue)]
  45.     #[ORM\OneToOne(targetEntityUpload::class, cascade: ['persist''remove'])]
  46.     protected ?Upload $photo null;
  47.     #[ORM\Column(type'string'length255nullablefalse)]
  48.     private ?string $apiToken null;
  49.     public function getEmail(): string
  50.     {
  51.         return $this->email;
  52.     }
  53.     public function setEmail(string $email): self
  54.     {
  55.         $this->email $email;
  56.         return $this;
  57.     }
  58.     public function getPassword(): ?string
  59.     {
  60.         return $this->password;
  61.     }
  62.     public function setPassword(?string $password): self
  63.     {
  64.         $this->password $password;
  65.         return $this;
  66.     }
  67.     public function getStatus(): ?bool
  68.     {
  69.         return $this->status;
  70.     }
  71.     public function setStatus(?bool $status): self
  72.     {
  73.         $this->status $status;
  74.         return $this;
  75.     }
  76.     public function getRoles(): array
  77.     {
  78.         $roles $this->roles;
  79.         $roles[] = RolesEnum::ROLE_MEMBRE->value;
  80.         return array_unique($roles);
  81.     }
  82.     public function setRoles(array $roles): self
  83.     {
  84.         $this->roles $roles;
  85.         return $this;
  86.     }
  87.     public function addRole(string $role): self
  88.     {
  89.         if (!in_array($role$this->getRoles(), true)) {
  90.             $this->roles array_merge($this->roles, [$role]);
  91.         }
  92.         return $this;
  93.     }
  94.     public function removeRoles(): self
  95.     {
  96.         $this->roles = [];
  97.         return $this;
  98.     }
  99.     public function removeRole(string $role): self
  100.     {
  101.         $this->roles array_diff($this->roles, [$role]);
  102.         return $this;
  103.     }
  104.     public function hasRole(string $role): bool
  105.     {
  106.         return in_array($role$this->getRoles(), true);
  107.     }
  108.     /**
  109.      * @param string[][] $rolesListsToCheck
  110.      * @return bool
  111.      * check with logic OR between args and logic AND between same array
  112.      */
  113.     public function hasRoles(array ...$rolesListsToCheck): bool
  114.     {
  115.         $roles = new ArrayCollection($this->getRoles());
  116.         foreach ($rolesListsToCheck as $rolesToCheck) {
  117.             if ($roles->filter(fn(string $role) => in_array($role$rolesToCheck))->count() !== 0) {
  118.                 return true;
  119.             }
  120.         }
  121.         return false;
  122.     }
  123.     public function getUserIdentifier(): string
  124.     {
  125.         return $this->email;
  126.     }
  127.     public function getSalt(): ?string
  128.     {
  129.         return null;
  130.     }
  131.     public function getUsername(): string
  132.     {
  133.         return $this->getUserIdentifier();
  134.     }
  135.     public function setEnabled(bool $enabled): self
  136.     {
  137.         $this->enabled $enabled;
  138.         return $this;
  139.     }
  140.     public function isEnabled(): ?bool
  141.     {
  142.         return $this->enabled;
  143.     }
  144.     public function getAdresse(): ?Adresse
  145.     {
  146.         return $this->adresse;
  147.     }
  148.     public function setAdresse(?Adresse $adresse): self
  149.     {
  150.         $this->adresse $adresse;
  151.         return $this;
  152.     }
  153.     public function getPhoto(): ?Upload
  154.     {
  155.         return $this->photo;
  156.     }
  157.     public function setPhoto(?Upload $photo): self
  158.     {
  159.         $this->photo $photo;
  160.         return $this;
  161.     }
  162.     public function isRgpd(): ?bool
  163.     {
  164.         return $this->rgpd;
  165.     }
  166.     public function setRgpd(?bool $rgpd): User
  167.     {
  168.         $this->rgpd $rgpd;
  169.         return $this;
  170.     }
  171.     public function isStatus(): ?bool
  172.     {
  173.         return $this->status;
  174.     }
  175.     public function eraseCredentials(): void
  176.     {
  177.         $this->plainPassword null// Nettoyage du mot de passe en clair
  178.     }
  179.     public function getPlainPassword(): ?string
  180.     {
  181.         return $this->plainPassword;
  182.     }
  183.     public function setPlainPassword(?string $plainPassword): self
  184.     {
  185.         $this->plainPassword $plainPassword;
  186.         return $this;
  187.     }
  188.     public function getApiToken(): ?string
  189.     {
  190.         return $this->apiToken;
  191.     }
  192.     public function setApiToken(?string $apiToken): self
  193.     {
  194.         $this->apiToken $apiToken;
  195.         return $this;
  196.     }
  197. }