src/Entity/User.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\UserRepository;
  4. use App\Util\Arr;
  5. use Doctrine\Common\Collections\{ArrayCollectionCollection};
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Gedmo\Mapping\Annotation as Gedmo;
  8. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  9. use Symfony\Component\Security\Core\User\{PasswordAuthenticatedUserInterfaceUserInterface};
  10. use Symfony\Component\Validator\Constraints as Assert;
  11. #[ORM\Entity(repositoryClassUserRepository::class), ORM\Table(name'users')]
  12. #[UniqueEntity(fields: ['username'], message'A user account already exists with this username!')]
  13. class User implements UserInterfacePasswordAuthenticatedUserInterface\Stringable
  14. {
  15.     #[ORM\IdORM\GeneratedValueORM\Column(type'integer')]
  16.     private $id;
  17.     #[ORM\Column(type'string'length50uniquetrue), Assert\NotBlankAssert\Length(min2max50)]
  18.     private $username;
  19.     #[ORM\Column(type'string')]
  20.     private $password;
  21.     #[ORM\Column(type'string'nullabletrue)]
  22.     private $password_old1;
  23.     #[ORM\Column(type'string'nullabletrue)]
  24.     private $password_old2;
  25.     #[ORM\Column(type'string')]
  26.     private $password_md5;
  27.     #[ORM\Column(type'boolean')]
  28.     private bool $isActive false;
  29.     #[ORM\Column(type'string'nullabletrue)]
  30.     private $token;
  31.     #[ORM\OneToOne(targetEntity'StaffProfile'inversedBy'user'cascade: ['persist''remove']), ORM\JoinColumn(nullabletrue)]
  32.     private $profile;
  33.     #[ORM\Column(type'json')]
  34.     private array $roles = [];
  35.     #[ORM\Column(type'datetime'nullabletrue)]
  36.     private $lastLogin;
  37.     #[ORM\Column(type'string'nullabletrue)]
  38.     private $authCode;
  39.     #[Gedmo\Timestampable(on'create'), ORM\Column(type'datetime')]
  40.     private $createdAt;
  41.     #[Gedmo\Timestampable(on'update'), ORM\Column(type'datetime')]
  42.     private $updatedAt;
  43.     #[ORM\OneToMany(targetEntityUserLoginHistory::class, mappedBy'user'orphanRemovaltrue)]
  44.     private $loginHistory;
  45.     public function __construct()
  46.     {
  47.         $this->loginHistory = new ArrayCollection();
  48.     }
  49.     public function getId(): ?int
  50.     {
  51.         return $this->id;
  52.     }
  53.     public function getUserIdentifier(): string
  54.     {
  55.         return $this->username;
  56.     }
  57.     public function getUsername(): ?string
  58.     {
  59.         return $this->username;
  60.     }
  61.     public function setUsername(string $username): self
  62.     {
  63.         $this->username $username;
  64.         return $this;
  65.     }
  66.     public function getPassword(): ?string
  67.     {
  68.         return $this->password;
  69.     }
  70.     public function setPassword(string $password): self
  71.     {
  72.         $this->password $password;
  73.         return $this;
  74.     }
  75.     public function getPasswordOld1(): ?string
  76.     {
  77.         return $this->password_old1;
  78.     }
  79.     public function setPasswordOld1(string $password_old1): self
  80.     {
  81.         $this->password_old1 $password_old1;
  82.         return $this;
  83.     }
  84.     public function getPasswordOld2(): ?string
  85.     {
  86.         return $this->password_old2;
  87.     }
  88.     public function setPasswordOld2(string $password_old2): self
  89.     {
  90.         $this->password_old2 $password_old2;
  91.         return $this;
  92.     }
  93.     public function getPasswordMd5(): ?string
  94.     {
  95.         return $this->password_md5;
  96.     }
  97.     public function setPasswordMd5(string $password_md5): self
  98.     {
  99.         $this->password_md5 $password_md5;
  100.         return $this;
  101.     }
  102.     public function getSalt(): ?string
  103.     {
  104.         return null;
  105.     }
  106.     public function eraseCredentials()
  107.     {
  108.         // If you store any temporary, sensitive data on the user, clear it here
  109.     }
  110.     public function getIsActive(): ?bool
  111.     {
  112.         return $this->isActive;
  113.     }
  114.     public function setIsActive(bool $isActive): self
  115.     {
  116.         $this->isActive $isActive;
  117.         return $this;
  118.     }
  119.     public function getToken(): ?string
  120.     {
  121.         return $this->token;
  122.     }
  123.     public function setToken(?string $token): self
  124.     {
  125.         $this->token $token;
  126.         return $this;
  127.     }
  128.     public function getProfile(): ?StaffProfile
  129.     {
  130.         return $this->profile;
  131.     }
  132.     public function setProfile(StaffProfile $profile): self
  133.     {
  134.         $this->profile $profile;
  135.         return $this;
  136.     }
  137.     public function getCreatedAt(): ?\DateTimeInterface
  138.     {
  139.         return $this->createdAt;
  140.     }
  141.     public function getUpdatedAt(): ?\DateTimeInterface
  142.     {
  143.         return $this->updatedAt;
  144.     }
  145.     public function getRoles(): array
  146.     {
  147.         $roles $this->roles;
  148.         return $roles;
  149.     }
  150.     public function setRoles(array $roles): self
  151.     {
  152.         $this->roles $roles;
  153.         return $this;
  154.     }
  155.     public function getLastLogin(): ?\DateTimeInterface
  156.     {
  157.         return $this->lastLogin;
  158.     }
  159.     public function setLastLogin(?\DateTimeInterface $lastLogin): self
  160.     {
  161.         $this->lastLogin $lastLogin;
  162.         return $this;
  163.     }
  164.     /**
  165.      * @return Collection|UserLoginHistory[]
  166.      */
  167.     public function getLoginHistory(): Collection
  168.     {
  169.         return $this->loginHistory;
  170.     }
  171.     public function addLoginHistory(UserLoginHistory $loginHistory): self
  172.     {
  173.         if (!$this->loginHistory->contains($loginHistory)) {
  174.             $this->loginHistory[] = $loginHistory;
  175.             $loginHistory->setUser($this);
  176.         }
  177.         return $this;
  178.     }
  179.     public function removeLoginHistory(UserLoginHistory $loginHistory): self
  180.     {
  181.         if ($this->loginHistory->removeElement($loginHistory)) {
  182.             if ($loginHistory->getUser() === $this) {
  183.                 $loginHistory->setUser(null);
  184.             }
  185.         }
  186.         return $this;
  187.     }
  188.     public function getEmailAuthCode(): string
  189.     {
  190.         if (null === $this->authCode) {
  191.             throw new \LogicException('The email authentication code was not set');
  192.         }
  193.         return $this->authCode;
  194.     }
  195.     public function setEmailAuthCode(string $authCode): void
  196.     {
  197.         $this->authCode $authCode;
  198.     }
  199.     public function getRole(): string
  200.     {
  201.         $roles $this->roles;
  202.         $roleDisplay = (new Arr())->getUserRolesArr(true);
  203.         return is_array($roleDisplay) && isset($roles[0]) ? $roleDisplay[$roles[0]] : '';
  204.     }
  205.     public function getHospital()
  206.     {
  207.         return $this->profile->getHospital();
  208.     }
  209.     public function getHospitalType()
  210.     {
  211.         return $this->profile->getHospital()->getType();
  212.     }
  213.     public function isEmailAuthEnabled(): bool
  214.     {
  215.         return true;
  216.     }
  217.     public function getEmailAuthRecipient(): string
  218.     {
  219.         return $this->profile->getEmail();
  220.     }
  221.     public function __toString(): string
  222.     {
  223.         return $this->profile->getFullName();
  224.     }
  225.     public function getAuthCode(): ?string
  226.     {
  227.         return $this->authCode;
  228.     }
  229.     public function setAuthCode(?string $authCode): self
  230.     {
  231.         $this->authCode $authCode;
  232.         return $this;
  233.     }
  234.     public function __serialize(): array
  235.     {
  236.         return [$this->id$this->username$this->password];
  237.     }
  238.     public function __unserialize(array $data): void
  239.     {
  240.         [$this->id$this->username$this->password] = $data;
  241.     }
  242. }