src/Entity/User.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\UserRepository;
  4. use Doctrine\DBAL\Types\Types;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  7. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  8. use Symfony\Component\Security\Core\User\UserInterface;
  9. use Symfony\Component\Validator\Constraints as Assert;
  10. #[ORM\Entity(repositoryClassUserRepository::class)]
  11. #[ORM\Table(name'app_user')]
  12. #[UniqueEntity(fields: ['email'], message'User.Form.ExistingEmail')]
  13. class User implements UserInterfacePasswordAuthenticatedUserInterface
  14. {
  15.     public const ROLE_SUPER_ADMIN 'ROLE_SUPER_ADMIN';
  16.     public const ROLE_CLIENT_MANAGER 'ROLE_CLIENT_MANAGER';
  17.     public const ROLE_CLIENT 'ROLE_CLIENT';
  18.     public const ROLE_EMPLOYEE 'ROLE_EMPLOYEE';
  19.     public const ROLES_AVAILABLES = [
  20.         self::ROLE_SUPER_ADMIN => 'Super Admin',
  21.         'ROLE_ADMIN' => 'Fayat - administateur',
  22.         'ROLE_USER' => 'Utilisateur',
  23.         self::ROLE_EMPLOYEE => 'Fayat - Utilisateur',
  24.         self::ROLE_CLIENT => 'Utilisateur Société (externe)',
  25.         self::ROLE_CLIENT_MANAGER => 'Responsable Société (externe)',
  26.     ];
  27.     #[ORM\Id]
  28.     #[ORM\GeneratedValue]
  29.     #[ORM\Column(type'integer')]
  30.     private $id;
  31.     #[ORM\Column(type'string'length180uniquetrue)]
  32.     private $email;
  33.     #[ORM\Column(type'json')]
  34.     private $roles = [];
  35.     #[ORM\Column(type'string'nullabletrue)]
  36.     private $password;
  37.     #[Assert\NotBlank(groups: ['create'])]
  38.     #[Assert\Length(
  39.         min6,
  40.         max142,
  41.         groups: ['create']
  42.     )]
  43.     private ?string $plainPassword null;
  44.     #[ORM\Column(type'boolean')]
  45.     private ?bool $isVerified false;
  46.     #[ORM\Column(length20nullabletrue)]
  47.     private ?string $telephone null;
  48.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLEnullabletrue)]
  49.     private ?\DateTimeInterface $emailSentAt null;
  50.     #[ORM\Column]
  51.     private ?bool $forceChangePassword true;
  52.     #[ORM\Column]
  53.     private ?bool $enabledAlert true;
  54.     #[ORM\Column(nullabletrue)]
  55.     private ?bool $enabled null;
  56.     #[ORM\Column(length75nullabletrue)]
  57.     private ?string $givenName null;
  58.     #[ORM\Column(length75nullabletrue)]
  59.     private ?string $familyName null;
  60.     #[ORM\ManyToOne(inversedBy'employees')]
  61.     private ?Company $company null;
  62.     #[ORM\Column(nullabletrue)]
  63.     private ?array $informationForModeration null;
  64.     public function __toString(): string
  65.     {
  66.         return $this->email;
  67.     }
  68.     public function getDisplayName(): string
  69.     {
  70.         return $this->familyName strtoupper($this->familyName).' '.ucfirst($this->givenName) : $this->email;
  71.     }
  72.     public function isManager(): bool
  73.     {
  74.         return in_array(self::ROLE_CLIENT_MANAGER$this->roles);
  75.     }
  76.     public function getId(): ?int
  77.     {
  78.         return $this->id;
  79.     }
  80.     public function getEmail(): ?string
  81.     {
  82.         return $this->email;
  83.     }
  84.     public function setEmail(string $email): self
  85.     {
  86.         $this->email $email;
  87.         return $this;
  88.     }
  89.     /**
  90.      * A visual identifier that represents this user.
  91.      *
  92.      * @see UserInterface
  93.      */
  94.     public function getUserIdentifier(): string
  95.     {
  96.         return (string) $this->email;
  97.     }
  98.     /**
  99.      * @see UserInterface
  100.      */
  101.     public function getRoles(): array
  102.     {
  103.         $roles $this->roles;
  104.         // guarantee every user at least has ROLE_USER
  105.         $roles[] = 'ROLE_USER';
  106.         return array_unique($roles);
  107.     }
  108.     public function setRoles(array $roles): self
  109.     {
  110.         $this->roles $roles;
  111.         return $this;
  112.     }
  113.     /**
  114.      * @see PasswordAuthenticatedUserInterface
  115.      */
  116.     public function getPassword(): ?string
  117.     {
  118.         return $this->password;
  119.     }
  120.     public function setPassword(string $password): self
  121.     {
  122.         $this->password $password;
  123.         return $this;
  124.     }
  125.     public function getPlainPassword(): ?string
  126.     {
  127.         return $this->plainPassword;
  128.     }
  129.     public function setPlainPassword(string $password): void
  130.     {
  131.         $this->plainPassword $password;
  132.     }
  133.     /**
  134.      * @see UserInterface
  135.      */
  136.     public function eraseCredentials()
  137.     {
  138.         // If you store any temporary, sensitive data on the user, clear it here
  139.         // $this->plainPassword = null;
  140.     }
  141.     public function isVerified(): bool
  142.     {
  143.         return $this->isVerified;
  144.     }
  145.     public function setIsVerified(bool $isVerified): self
  146.     {
  147.         $this->isVerified $isVerified;
  148.         return $this;
  149.     }
  150.     public function getTelephone(): ?string
  151.     {
  152.         return $this->telephone;
  153.     }
  154.     public function setTelephone(?string $telephone): self
  155.     {
  156.         $this->telephone $telephone;
  157.         return $this;
  158.     }
  159.     public function getEmailSentAt(): ?\DateTimeInterface
  160.     {
  161.         return $this->emailSentAt;
  162.     }
  163.     public function setEmailSentAt(?\DateTimeInterface $emailSentAt): self
  164.     {
  165.         $this->emailSentAt $emailSentAt;
  166.         return $this;
  167.     }
  168.     public function isForceChangePassword(): ?bool
  169.     {
  170.         return $this->forceChangePassword;
  171.     }
  172.     public function setForceChangePassword(bool $forceChangePassword): self
  173.     {
  174.         $this->forceChangePassword $forceChangePassword;
  175.         return $this;
  176.     }
  177.     public function isEnabledAlert(): ?bool
  178.     {
  179.         return $this->enabledAlert;
  180.     }
  181.     public function setEnabledAlert(bool $enabledAlert): self
  182.     {
  183.         $this->enabledAlert $enabledAlert;
  184.         return $this;
  185.     }
  186.     public function isEnabled(): ?bool
  187.     {
  188.         return $this->enabled;
  189.     }
  190.     public function setEnabled(?bool $enabled): self
  191.     {
  192.         $this->enabled $enabled;
  193.         return $this;
  194.     }
  195.     public function getGivenName(): ?string
  196.     {
  197.         return $this->givenName;
  198.     }
  199.     public function setGivenName(?string $givenName): self
  200.     {
  201.         $this->givenName $givenName;
  202.         return $this;
  203.     }
  204.     public function getFamilyName(): ?string
  205.     {
  206.         return $this->familyName;
  207.     }
  208.     public function setFamilyName(?string $familyName): self
  209.     {
  210.         $this->familyName $familyName;
  211.         return $this;
  212.     }
  213.     public function getCompany(): ?Company
  214.     {
  215.         return $this->company;
  216.     }
  217.     public function setCompany(?Company $company): self
  218.     {
  219.         $this->company $company;
  220.         return $this;
  221.     }
  222.     public function getLocale(): string
  223.     {
  224.         return $this->getCompany()?->getLocale() ?? 'fr';
  225.     }
  226.     public function getInformationForModeration(): ?array
  227.     {
  228.         return $this->informationForModeration;
  229.     }
  230.     public function setInformationForModeration(?array $informationForModeration): self
  231.     {
  232.         $this->informationForModeration $informationForModeration;
  233.         return $this;
  234.     }
  235.     public function isPremium(): bool
  236.     {
  237.         return $this->getCompany()?->isPremium() ?? false;
  238.     }
  239. }