src/Entity/User/User.php line 16

  1. <?php
  2. namespace App\Entity\User;
  3. use App\Entity\Traits\ActiveTrait;
  4. use App\Entity\Traits\TrackerFields;
  5. use DateTime;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Serializable;
  8. use Symfony\Component\Security\Core\User\EquatableInterface;
  9. use Symfony\Component\Security\Core\User\UserInterface;
  10. #[ORM\Table(name'users')]
  11. #[ORM\Entity(repositoryClass'App\Repository\User\UserRepository')]
  12. #[ORM\HasLifecycleCallbacks]
  13. class User implements UserInterfaceEquatableInterface\Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface
  14. {
  15.     use TrackerFields;
  16.     use ActiveTrait;
  17.     public const ADMIN_PER_PAGE 25;
  18.     /**
  19.      *
  20.      * @var DateTime|null
  21.      */
  22.     #[ORM\Column(type'datetime'nullabletrue)]
  23.     protected $last_action_at;
  24.     /**
  25.      * @var int|null
  26.      */
  27.     #[ORM\Id]
  28.     #[ORM\GeneratedValue]
  29.     #[ORM\Column(type'integer')]
  30.     private $id;
  31.     /**
  32.      * @var string|null Email
  33.      */
  34.     #[ORM\Column(type'string'uniquetruelength50)]
  35.     private $username;
  36.     /**
  37.      * @var string|null
  38.      */
  39.     #[ORM\Column(type'string'nullabletrue)]
  40.     private $firstName;
  41.     /**
  42.      * @var string|null
  43.      */
  44.     #[ORM\Column(type'string'nullabletrue)]
  45.     private $middleName;
  46.     /**
  47.      * @var string|null
  48.      */
  49.     #[ORM\Column(type'string'nullabletrue)]
  50.     private $lastName;
  51.     /**
  52.      * @var DateTime
  53.      */
  54.     #[ORM\Column(type'date'nullabletrue)]
  55.     private $birthday;
  56.     /**
  57.      * @var string|null
  58.      */
  59.     #[ORM\Column(type'string'length50nullabletrue)]
  60.     private $phone;
  61.     /**
  62.      * @var string|null
  63.      */
  64.     #[ORM\Column(type'string'length255)]
  65.     private $password;
  66.     #[ORM\Column(type'text'nullabletrue)]
  67.     private $adminComment;
  68.     /**
  69.      * @var bool
  70.      */
  71.     #[ORM\Column(type'boolean'options: ['default' => true])]
  72.     private $scholar true;
  73.     /**
  74.      * @var array
  75.      */
  76.     #[ORM\Column(type'json'nullablefalse)]
  77.     private $roles = ['ROLE_USER'];
  78.     /**
  79.      * @var array
  80.      */
  81.     private $rolesAdditional = [];
  82.     public function __serialize()
  83.     {
  84.         return array($this->id$this->username$this->password$this->active,);
  85.     }
  86.     public function __unserialize($serialized)
  87.     {
  88.         list($this->id$this->username$this->password$this->active, ) = $serialized;
  89.     }
  90.     /**
  91.      * Returns the salt that was originally used to encode the password.
  92.      *
  93.      * This can return null if the password was not encoded using a salt.
  94.      *
  95.      * @return string|null The salt
  96.      */
  97.     public function getSalt()
  98.     {
  99.         return null;
  100.     }
  101.     /**
  102.      * Removes sensitive data from the user.
  103.      *
  104.      * This is important if, at any given point, sensitive information like
  105.      * the plain-text password is stored on this object.
  106.      */
  107.     public function eraseCredentials()
  108.     {
  109.     }
  110.     /**
  111.      * @inheritDoc
  112.      */
  113.     public function getRoles(): array
  114.     {
  115.         return array_merge($this->roles$this->rolesAdditional);
  116.     }
  117.     /**
  118.      * @param mixed $roles
  119.      */
  120.     public function setRoles(array $roles): void
  121.     {
  122.         $this->roles $roles;
  123.     }
  124.     public function addRole(string $role)
  125.     {
  126.         if (!in_array($role$this->roles)) {
  127.             $this->roles[] = $role;
  128.         }
  129.     }
  130.     /**
  131.      * @return DateTime|null
  132.      */
  133.     public function getLastActionAt(): ?DateTime
  134.     {
  135.         return $this->last_action_at;
  136.     }
  137.     /**
  138.      * @param DateTime|null $last_action_at
  139.      */
  140.     public function setLastActionAt(?DateTime $last_action_at): void
  141.     {
  142.         $this->last_action_at $last_action_at;
  143.     }
  144.     /**
  145.      * @return string|null
  146.      */
  147.     public function getFirstName(): ?string
  148.     {
  149.         return $this->firstName;
  150.     }
  151.     /**
  152.      * @param string|null $firstName
  153.      */
  154.     public function setFirstName(?string $firstName): void
  155.     {
  156.         $this->firstName $firstName;
  157.     }
  158.     /**
  159.      * @return string|null
  160.      */
  161.     public function getMiddleName(): ?string
  162.     {
  163.         return $this->middleName;
  164.     }
  165.     /**
  166.      * @param string|null $middleName
  167.      */
  168.     public function setMiddleName(?string $middleName): void
  169.     {
  170.         $this->middleName $middleName;
  171.     }
  172.     /**
  173.      * @return string|null
  174.      */
  175.     public function getLastName(): ?string
  176.     {
  177.         return $this->lastName;
  178.     }
  179.     /**
  180.      * @param string|null $lastName
  181.      */
  182.     public function setLastName(?string $lastName): void
  183.     {
  184.         $this->lastName $lastName;
  185.     }
  186.     /**
  187.      * @return mixed
  188.      */
  189.     public function getAdminComment()
  190.     {
  191.         return $this->adminComment;
  192.     }
  193.     /**
  194.      * @param mixed $adminComment
  195.      */
  196.     public function setAdminComment($adminComment): void
  197.     {
  198.         $this->adminComment $adminComment;
  199.     }
  200.     public function getFullname()
  201.     {
  202.         return trim(str_replace('  '' 'sprintf('%s %s %s'$this->firstName$this->middleName$this->lastName)));
  203.     }
  204.     /**
  205.      * @return array
  206.      */
  207.     public function getRolesAdditional(): array
  208.     {
  209.         return $this->rolesAdditional;
  210.     }
  211.     /**
  212.      * @param array $rolesAdditional
  213.      */
  214.     public function setRolesAdditional(array $rolesAdditional): void
  215.     {
  216.         $this->rolesAdditional $rolesAdditional;
  217.     }
  218.     public function addRoleAdditional($role)
  219.     {
  220.         $this->rolesAdditional[] = $role;
  221.     }
  222.     public function isEqualTo(UserInterface $user): bool
  223.     {
  224.         if ($user->getId() != $this->getId()) {
  225.             return false;
  226.         }
  227.         if ($user->getUsername() != $this->getUsername()) {
  228.             return false;
  229.         }
  230.         if ($user->getPassword() != $this->getPassword()) {
  231.             return false;
  232.         }
  233. //        if ($user->isActive() != $this->isActive()) {
  234. //            return false;
  235. //        }
  236.         return true;
  237.     }
  238.     /**
  239.      * @return int|null
  240.      */
  241.     public function getId(): ?int
  242.     {
  243.         return $this->id;
  244.     }
  245.     /**
  246.      * @param int|null $id
  247.      */
  248.     public function setId(?int $id): void
  249.     {
  250.         $this->id $id;
  251.     }
  252.     /**
  253.      * Returns the username used to authenticate the user.
  254.      *
  255.      * @return string The username
  256.      */
  257.     public function getUsername()
  258.     {
  259.         return $this->username;
  260.     }
  261.     /**
  262.      * @param string $username
  263.      */
  264.     public function setUsername(string $username): void
  265.     {
  266.         $this->username $username;
  267.     }
  268.     /**
  269.      * Returns the password used to authenticate the user.
  270.      *
  271.      * This should be the encoded password. On authentication, a plain-text
  272.      * password will be salted, encoded, and then compared to this value.
  273.      *
  274.      * @return string The password
  275.      */
  276.     public function getPassword(): string
  277.     {
  278.         return $this->password;
  279.     }
  280.     /**
  281.      * @param mixed $password
  282.      */
  283.     public function setPassword($password): void
  284.     {
  285.         $this->password $password;
  286.     }
  287.     public function getUserIdentifier(): string
  288.     {
  289.         return $this->username;
  290.     }
  291.     /**
  292.      * @return DateTime
  293.      */
  294.     public function getBirthday(): ?DateTime
  295.     {
  296.         return $this->birthday;
  297.     }
  298.     /**
  299.      * @param DateTime $birthday
  300.      */
  301.     public function setBirthday(?DateTime $birthday): void
  302.     {
  303.         $this->birthday $birthday;
  304.     }
  305.     /**
  306.      * @return string|null
  307.      */
  308.     public function getPhone(): ?string
  309.     {
  310.         return $this->phone;
  311.     }
  312.     /**
  313.      * @param string|null $phone
  314.      */
  315.     public function setPhone(?string $phone): void
  316.     {
  317.         $this->phone $phone;
  318.     }
  319.     /**
  320.      * @return bool
  321.      */
  322.     public function isScholar(): bool
  323.     {
  324.         return $this->scholar;
  325.     }
  326.     /**
  327.      * @param bool $scholar
  328.      */
  329.     public function setScholar(bool $scholar): void
  330.     {
  331.         $this->scholar $scholar;
  332.     }
  333. }