src/Entity/User.php line 15

  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity;
  4. use App\Enum\Admin\RolesEnum;
  5. use App\Repository\UserRepository;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  8. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  9. use Symfony\Component\Security\Core\User\UserInterface;
  10. #[ORM\Entity(repositoryClassUserRepository::class)]
  11. #[UniqueEntity(fields: ['email'], message'There is already an account with this email')]
  12. class User implements UserInterfacePasswordAuthenticatedUserInterface
  13. {
  14.     #[ORM\Id]
  15.     #[ORM\GeneratedValue]
  16.     #[ORM\Column]
  17.     private ?int $id null;
  18.     #[ORM\Column(length180uniquetrue)]
  19.     private ?string $email null;
  20.     #[ORM\Column(length255nullabletrue)]
  21.     private ?string $firstname null;
  22.     #[ORM\Column(length255nullabletrue)]
  23.     private ?string $lastname null;
  24.     #[ORM\Column]
  25.     private array $roles = [];
  26.     #[ORM\Column(type'string'nullabletrue)]
  27.     private ?string $password null;
  28.     #[ORM\Column(type'boolean')]
  29.     private bool $isVerified false;
  30.     #[ORM\Column(type'boolean')]
  31.     private bool $receiveNotifications false;
  32.     #[ORM\Column(length2)]
  33.     private string $lang 'en';
  34.     public function __construct()
  35.     {
  36.     }
  37.     public function getId(): ?int
  38.     {
  39.         return $this->id;
  40.     }
  41.     public function getEmail(): ?string
  42.     {
  43.         return $this->email;
  44.     }
  45.     public function setEmail(string $email): self
  46.     {
  47.         $this->email $email;
  48.         return $this;
  49.     }
  50.     public function getLogin(): ?string
  51.     {
  52.         return $this->login;
  53.     }
  54.     public function setLogin(string $login): self
  55.     {
  56.         $this->login $login;
  57.         return $this;
  58.     }
  59.     public function getFirstname(): ?string
  60.     {
  61.         return $this->firstname;
  62.     }
  63.     public function setFirstname(?string $firstname): self
  64.     {
  65.         $this->firstname $firstname;
  66.         return $this;
  67.     }
  68.     public function getLastname(): ?string
  69.     {
  70.         return $this->lastname;
  71.     }
  72.     public function setLastname(?string $lastname): self
  73.     {
  74.         $this->lastname $lastname;
  75.         return $this;
  76.     }
  77.     /**
  78.      * A visual identifier that represents this user.
  79.      *
  80.      * @see UserInterface
  81.      */
  82.     public function getUserIdentifier(): string
  83.     {
  84.         return (string)$this->email;
  85.     }
  86.     /**
  87.      * @see UserInterface
  88.      */
  89.     public function getRoles(): array
  90.     {
  91.         $roles $this->roles;
  92.         // guarantee every user at least has ROLE_USER
  93.         $roles[] = RolesEnum::ROLE_USER->name;
  94.         RolesEnum::sortTextRoles($roles);
  95.         return array_unique($roles);
  96.     }
  97.     public function setRoles(array $roles): self
  98.     {
  99.         $this->roles $roles;
  100.         return $this;
  101.     }
  102.     /**
  103.      * @see PasswordAuthenticatedUserInterface
  104.      */
  105.     public function getPassword(): string
  106.     {
  107.         return $this->password;
  108.     }
  109.     public function setPassword(?string $password): self
  110.     {
  111.         if (!is_null($password)) {
  112.             $this->password $password;
  113.         }
  114.         return $this;
  115.     }
  116.     /**
  117.      * @see UserInterface
  118.      */
  119.     public function eraseCredentials(): void
  120.     {
  121.         // If you store any temporary, sensitive data on the user, clear it here
  122.         // $this->plainPassword = null;
  123.     }
  124.     public function isVerified(): bool
  125.     {
  126.         return $this->isVerified;
  127.     }
  128.     public function setIsVerified(bool $isVerified): self
  129.     {
  130.         $this->isVerified $isVerified;
  131.         return $this;
  132.     }
  133.     public function getReceiveNotifications(): bool
  134.     {
  135.         return $this->receiveNotifications;
  136.     }
  137.     public function setReceiveNotifications(bool $receiveNotifications): self
  138.     {
  139.         $this->receiveNotifications $receiveNotifications;
  140.         return $this;
  141.     }
  142.     public function getLang(): string
  143.     {
  144.         return $this->lang ?: 'en';
  145.     }
  146.     public function setLang(string $lang): self
  147.     {
  148.         $this->lang $lang;
  149.         return $this;
  150.     }
  151.     public function getFullName(): string
  152.     {
  153.         return trim(implode(' 'array_filter([
  154.             $this->getFirstname(),
  155.             $this->getLastname(),
  156.         ])));
  157.     }
  158. }