src/Entity/User.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Enum\User\Role;
  4. use App\Repository\UserRepository;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  7. use Symfony\Component\Security\Core\User\UserInterface;
  8. /**
  9.  * @ORM\Entity(repositoryClass=UserRepository::class)
  10.  */
  11. class User implements UserInterfacePasswordAuthenticatedUserInterface
  12. {
  13.     const USER_FIELD_NAME "user";
  14.     /**
  15.      * @ORM\Id
  16.      * @ORM\GeneratedValue
  17.      * @ORM\Column(type="integer")
  18.      */
  19.     private $id;
  20.     /**
  21.      * @ORM\Column(type="string", length=180, unique=true)
  22.      */
  23.     private $username;
  24.     /**
  25.      * @ORM\Column(type="json")
  26.      */
  27.     private $roles = [];
  28.     /**
  29.      * @var string The hashed password
  30.      * @ORM\Column(type="string")
  31.      */
  32.     private $password;
  33.     /**
  34.      * @ORM\Column(type="string", length=255)
  35.      */
  36.     private $firstName;
  37.     /**
  38.      * @ORM\Column(type="string", length=255, nullable=true)
  39.      */
  40.     private $lastName;
  41.     /**
  42.      * @var string|null
  43.      */
  44.     private $oldPassword;
  45.     /**
  46.      * @var string|null
  47.      */
  48.     private $newPassword;
  49.     /**
  50.      * @ORM\OneToOne(targetEntity=UserSettings::class, cascade={"persist", "remove"})
  51.      * @ORM\JoinColumn(nullable=false)
  52.      */
  53.     private $settings;
  54.     /**
  55.      * @ORM\Column(type="string", length=30, nullable=true)
  56.      */
  57.     private $telegramUserId;
  58.     /**
  59.      * @ORM\Column(type="string", length=30, nullable=true)
  60.      */
  61.     private $telegramPhone;
  62.     /**
  63.      * @ORM\Column(type="integer", nullable=true)
  64.      */
  65.     private $sortId;
  66.     /**
  67.      * @ORM\OneToOne(targetEntity=ReviewerSettings::class, mappedBy="user", cascade={"persist", "remove"})
  68.      */
  69.     private $reviewerSettings;
  70.     /**
  71.      * @ORM\OneToOne(targetEntity=TipSettings::class, mappedBy="user", cascade={"persist", "remove"})
  72.      */
  73.     private $tipSettings;
  74.     public function getId(): ?int
  75.     {
  76.         return $this->id;
  77.     }
  78.     /**
  79.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  80.      */
  81.     public function getUsername(): string
  82.     {
  83.         return (string) $this->username;
  84.     }
  85.     public function setUsername(string $username): self
  86.     {
  87.         $this->username $username;
  88.         return $this;
  89.     }
  90.     /**
  91.      * A visual identifier that represents this user.
  92.      *
  93.      * @see UserInterface
  94.      */
  95.     public function getUserIdentifier(): string
  96.     {
  97.         return (string) $this->username;
  98.     }
  99.     /**
  100.      * @see UserInterface
  101.      */
  102.     public function getRoles(): array
  103.     {
  104.         $roles $this->roles;
  105.         // guarantee every user at least has ROLE_USER
  106.         // $roles[] = 'ROLE_USER';
  107.         return array_unique($roles);
  108.     }
  109.     public function getRolesData(): array
  110.     {
  111.         $rolesData = [];
  112.         foreach ($this->getRoles() as $role) {
  113.             $rolesData[] = [
  114.                 'value' => $role,
  115.                 'text' => Role::getText($role),
  116.             ];
  117.         }
  118.         return $rolesData;
  119.     }
  120.     public function setRoles(array $roles): self
  121.     {
  122.         $this->roles $roles;
  123.         return $this;
  124.     }
  125.     public function isAdmin(): bool
  126.     {
  127.         return in_array(Role::ROLE_ADMIN$this->getRoles(), true);
  128.     }
  129.     public function isModerator(): bool
  130.     {
  131.         return in_array(Role::ROLE_MODERATOR$this->getRoles(), true);
  132.     }
  133.     public function isDeveloper(): bool
  134.     {
  135.         return in_array(Role::ROLE_DEVELOPER$this->getRoles(), true);
  136.     }
  137.     /**
  138.      * @see PasswordAuthenticatedUserInterface
  139.      */
  140.     public function getPassword(): ?string
  141.     {
  142.         return $this->password;
  143.     }
  144.     public function setPassword(?string $password): self
  145.     {
  146.         $this->password $password;
  147.         return $this;
  148.     }
  149.     public function getOldPassword(): ?string
  150.     {
  151.         return $this->oldPassword;
  152.     }
  153.     public function setOldPassword(string $oldPassword): self
  154.     {
  155.         $this->oldPassword $oldPassword;
  156.         return $this;
  157.     }
  158.     public function getNewPassword(): ?string
  159.     {
  160.         return $this->newPassword;
  161.     }
  162.     public function setNewPassword(string $newPassword): self
  163.     {
  164.         $this->newPassword $newPassword;
  165.         return $this;
  166.     }
  167.     /**
  168.      * Returning a salt is only needed, if you are not using a modern
  169.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  170.      *
  171.      * @see UserInterface
  172.      */
  173.     public function getSalt(): ?string
  174.     {
  175.         return null;
  176.     }
  177.     /**
  178.      * @see UserInterface
  179.      */
  180.     public function eraseCredentials()
  181.     {
  182.         // If you store any temporary, sensitive data on the user, clear it here
  183.         // $this->plainPassword = null;
  184.     }
  185.     public function getFirstName(): ?string
  186.     {
  187.         return $this->firstName;
  188.     }
  189.     public function setFirstName(string $firstName): self
  190.     {
  191.         $this->firstName $firstName;
  192.         return $this;
  193.     }
  194.     public function getLastName(): ?string
  195.     {
  196.         return $this->lastName;
  197.     }
  198.     public function setLastName(?string $lastName): self
  199.     {
  200.         $this->lastName $lastName;
  201.         return $this;
  202.     }
  203.     public function getName(): string
  204.     {
  205.         return $this->firstName ' ' $this->lastName;
  206.     }
  207.     public function getSettings(): ?UserSettings
  208.     {
  209.         return $this->settings;
  210.     }
  211.     public function setSettings(UserSettings $settings): self
  212.     {
  213.         $this->settings $settings;
  214.         return $this;
  215.     }
  216.     public function getTelegramUserId(): ?string
  217.     {
  218.         return $this->telegramUserId;
  219.     }
  220.     public function setTelegramUserId(?string $telegramUserId): self
  221.     {
  222.         $this->telegramUserId $telegramUserId;
  223.         return $this;
  224.     }
  225.     public function getTelegramPhone(): ?string
  226.     {
  227.         return $this->telegramPhone;
  228.     }
  229.     public function setTelegramPhone(?string $telegramPhone): self
  230.     {
  231.         $this->telegramPhone $telegramPhone;
  232.         return $this;
  233.     }
  234.     public function getSortId(): ?int
  235.     {
  236.         return $this->sortId;
  237.     }
  238.     public function setSortId(?int $sortId): self
  239.     {
  240.         $this->sortId $sortId;
  241.         return $this;
  242.     }
  243.     public function getReviewerSettings(): ?ReviewerSettings
  244.     {
  245.         return $this->reviewerSettings;
  246.     }
  247.     public function setReviewerSettings(?ReviewerSettings $reviewerSettings): self
  248.     {
  249.         // unset the owning side of the relation if necessary
  250.         if ($reviewerSettings === null && $this->reviewerSettings !== null) {
  251.             $this->reviewerSettings->setUser(null);
  252.         }
  253.         // set the owning side of the relation if necessary
  254.         if ($reviewerSettings !== null && $reviewerSettings->getUser() !== $this) {
  255.             $reviewerSettings->setUser($this);
  256.         }
  257.         $this->reviewerSettings $reviewerSettings;
  258.         return $this;
  259.     }
  260.     public function getTipSettings(): ?TipSettings
  261.     {
  262.         return $this->tipSettings;
  263.     }
  264.     public function setTipSettings(TipSettings $tipSettings): self
  265.     {
  266.         // set the owning side of the relation if necessary
  267.         if ($tipSettings->getUser() !== $this) {
  268.             $tipSettings->setUser($this);
  269.         }
  270.         $this->tipSettings $tipSettings;
  271.         return $this;
  272.     }
  273. }