src/Entity/User.php line 15

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