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.     public function getEmail(): string
  48.     {
  49.         return $this->email;
  50.     }
  51.     public function setEmail(string $email): self
  52.     {
  53.         $this->email $email;
  54.         return $this;
  55.     }
  56.     public function getPassword(): ?string
  57.     {
  58.         return $this->password;
  59.     }
  60.     public function setPassword(?string $password): self
  61.     {
  62.         $this->password $password;
  63.         return $this;
  64.     }
  65.     public function getStatus(): ?bool
  66.     {
  67.         return $this->status;
  68.     }
  69.     public function setStatus(?bool $status): self
  70.     {
  71.         $this->status $status;
  72.         return $this;
  73.     }
  74.     public function getRoles(): array
  75.     {
  76.         $roles $this->roles;
  77.         $roles[] = RolesEnum::ROLE_MEMBRE->value;
  78.         return array_unique($roles);
  79.     }
  80.     public function setRoles(array $roles): self
  81.     {
  82.         $this->roles $roles;
  83.         return $this;
  84.     }
  85.     public function addRole(string $role): self
  86.     {
  87.         if (!in_array($role$this->getRoles(), true)) {
  88.             $this->roles array_merge($this->roles, [$role]);
  89.         }
  90.         return $this;
  91.     }
  92.     public function removeRoles(): self
  93.     {
  94.         $this->roles = [];
  95.         return $this;
  96.     }
  97.     public function removeRole(string $role): self
  98.     {
  99.         $this->roles array_diff($this->roles, [$role]);
  100.         return $this;
  101.     }
  102.     public function hasRole(string $role): bool
  103.     {
  104.         return in_array($role$this->getRoles(), true);
  105.     }
  106.     /**
  107.      * @param string[][] $rolesListsToCheck
  108.      * @return bool
  109.      * check with logic OR between args and logic AND between same array
  110.      */
  111.     public function hasRoles(array ...$rolesListsToCheck): bool
  112.     {
  113.         $roles = new ArrayCollection($this->getRoles());
  114.         foreach ($rolesListsToCheck as $rolesToCheck) {
  115.             if ($roles->filter(fn(string $role) => in_array($role$rolesToCheck))->count() !== 0) {
  116.                 return true;
  117.             }
  118.         }
  119.         return false;
  120.     }
  121.     public function getUserIdentifier(): string
  122.     {
  123.         return $this->email;
  124.     }
  125.     public function getSalt(): ?string
  126.     {
  127.         return null;
  128.     }
  129.     public function getUsername(): string
  130.     {
  131.         return $this->getUserIdentifier();
  132.     }
  133.     public function setEnabled(bool $enabled): self
  134.     {
  135.         $this->enabled $enabled;
  136.         return $this;
  137.     }
  138.     public function isEnabled(): ?bool
  139.     {
  140.         return $this->enabled;
  141.     }
  142.     public function getAdresse(): ?Adresse
  143.     {
  144.         return $this->adresse;
  145.     }
  146.     public function setAdresse(?Adresse $adresse): self
  147.     {
  148.         $this->adresse $adresse;
  149.         return $this;
  150.     }
  151.     public function getPhoto(): ?Upload
  152.     {
  153.         return $this->photo;
  154.     }
  155.     public function setPhoto(?Upload $photo): self
  156.     {
  157.         $this->photo $photo;
  158.         return $this;
  159.     }
  160.     public function isRgpd(): ?bool
  161.     {
  162.         return $this->rgpd;
  163.     }
  164.     public function setRgpd(?bool $rgpd): User
  165.     {
  166.         $this->rgpd $rgpd;
  167.         return $this;
  168.     }
  169.     public function isStatus(): ?bool
  170.     {
  171.         return $this->status;
  172.     }
  173.     public function eraseCredentials(): void
  174.     {
  175.         $this->plainPassword null// Nettoyage du mot de passe en clair
  176.     }
  177.     public function getPlainPassword(): ?string
  178.     {
  179.         return $this->plainPassword;
  180.     }
  181.     public function setPlainPassword(?string $plainPassword): self
  182.     {
  183.         $this->plainPassword $plainPassword;
  184.         return $this;
  185.     }
  186. }