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

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