src/Entity/User/User.php line 16
<?php
namespace App\Entity\User;
use App\Entity\Traits\ActiveTrait;
use App\Entity\Traits\TrackerFields;
use DateTime;
use Doctrine\ORM\Mapping as ORM;
use Serializable;
use Symfony\Component\Security\Core\User\EquatableInterface;
use Symfony\Component\Security\Core\User\UserInterface;
#[ORM\Table(name: 'users')]
#[ORM\Entity(repositoryClass: 'App\Repository\User\UserRepository')]
#[ORM\HasLifecycleCallbacks]
class User implements UserInterface, EquatableInterface, \Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface
{
use TrackerFields;
use ActiveTrait;
public const ADMIN_PER_PAGE = 25;
/**
*
* @var DateTime|null
*/
#[ORM\Column(type: 'datetime', nullable: true)]
protected $last_action_at;
/**
* @var int|null
*/
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
/**
* @var string|null Email
*/
#[ORM\Column(type: 'string', unique: true, length: 50)]
private $username;
/**
* @var string|null
*/
#[ORM\Column(type: 'string', nullable: true)]
private $firstName;
/**
* @var string|null
*/
#[ORM\Column(type: 'string', nullable: true)]
private $middleName;
/**
* @var string|null
*/
#[ORM\Column(type: 'string', nullable: true)]
private $lastName;
/**
* @var DateTime
*/
#[ORM\Column(type: 'date', nullable: true)]
private $birthday;
/**
* @var string|null
*/
#[ORM\Column(type: 'string', length: 50, nullable: true)]
private $phone;
/**
* @var string|null
*/
#[ORM\Column(type: 'string', length: 255)]
private $password;
#[ORM\Column(type: 'text', nullable: true)]
private $adminComment;
/**
* @var bool
*/
#[ORM\Column(type: 'boolean', options: ['default' => true])]
private $scholar = true;
/**
* @var array
*/
#[ORM\Column(type: 'json', nullable: false)]
private $roles = ['ROLE_USER'];
/**
* @var array
*/
private $rolesAdditional = [];
public function __serialize()
{
return array($this->id, $this->username, $this->password, $this->active,);
}
public function __unserialize($serialized)
{
list($this->id, $this->username, $this->password, $this->active, ) = $serialized;
}
/**
* Returns the salt that was originally used to encode the password.
*
* This can return null if the password was not encoded using a salt.
*
* @return string|null The salt
*/
public function getSalt()
{
return null;
}
/**
* Removes sensitive data from the user.
*
* This is important if, at any given point, sensitive information like
* the plain-text password is stored on this object.
*/
public function eraseCredentials()
{
}
/**
* @inheritDoc
*/
public function getRoles(): array
{
return array_merge($this->roles, $this->rolesAdditional);
}
/**
* @param mixed $roles
*/
public function setRoles(array $roles): void
{
$this->roles = $roles;
}
public function addRole(string $role)
{
if (!in_array($role, $this->roles)) {
$this->roles[] = $role;
}
}
/**
* @return DateTime|null
*/
public function getLastActionAt(): ?DateTime
{
return $this->last_action_at;
}
/**
* @param DateTime|null $last_action_at
*/
public function setLastActionAt(?DateTime $last_action_at): void
{
$this->last_action_at = $last_action_at;
}
/**
* @return string|null
*/
public function getFirstName(): ?string
{
return $this->firstName;
}
/**
* @param string|null $firstName
*/
public function setFirstName(?string $firstName): void
{
$this->firstName = $firstName;
}
/**
* @return string|null
*/
public function getMiddleName(): ?string
{
return $this->middleName;
}
/**
* @param string|null $middleName
*/
public function setMiddleName(?string $middleName): void
{
$this->middleName = $middleName;
}
/**
* @return string|null
*/
public function getLastName(): ?string
{
return $this->lastName;
}
/**
* @param string|null $lastName
*/
public function setLastName(?string $lastName): void
{
$this->lastName = $lastName;
}
/**
* @return mixed
*/
public function getAdminComment()
{
return $this->adminComment;
}
/**
* @param mixed $adminComment
*/
public function setAdminComment($adminComment): void
{
$this->adminComment = $adminComment;
}
public function getFullname()
{
return trim(str_replace(' ', ' ', sprintf('%s %s %s', $this->firstName, $this->middleName, $this->lastName)));
}
/**
* @return array
*/
public function getRolesAdditional(): array
{
return $this->rolesAdditional;
}
/**
* @param array $rolesAdditional
*/
public function setRolesAdditional(array $rolesAdditional): void
{
$this->rolesAdditional = $rolesAdditional;
}
public function addRoleAdditional($role)
{
$this->rolesAdditional[] = $role;
}
public function isEqualTo(UserInterface $user): bool
{
if ($user->getId() != $this->getId()) {
return false;
}
if ($user->getUsername() != $this->getUsername()) {
return false;
}
if ($user->getPassword() != $this->getPassword()) {
return false;
}
// if ($user->isActive() != $this->isActive()) {
// return false;
// }
return true;
}
/**
* @return int|null
*/
public function getId(): ?int
{
return $this->id;
}
/**
* @param int|null $id
*/
public function setId(?int $id): void
{
$this->id = $id;
}
/**
* Returns the username used to authenticate the user.
*
* @return string The username
*/
public function getUsername()
{
return $this->username;
}
/**
* @param string $username
*/
public function setUsername(string $username): void
{
$this->username = $username;
}
/**
* Returns the password used to authenticate the user.
*
* This should be the encoded password. On authentication, a plain-text
* password will be salted, encoded, and then compared to this value.
*
* @return string The password
*/
public function getPassword(): string
{
return $this->password;
}
/**
* @param mixed $password
*/
public function setPassword($password): void
{
$this->password = $password;
}
public function getUserIdentifier(): string
{
return $this->username;
}
/**
* @return DateTime
*/
public function getBirthday(): ?DateTime
{
return $this->birthday;
}
/**
* @param DateTime $birthday
*/
public function setBirthday(?DateTime $birthday): void
{
$this->birthday = $birthday;
}
/**
* @return string|null
*/
public function getPhone(): ?string
{
return $this->phone;
}
/**
* @param string|null $phone
*/
public function setPhone(?string $phone): void
{
$this->phone = $phone;
}
/**
* @return bool
*/
public function isScholar(): bool
{
return $this->scholar;
}
/**
* @param bool $scholar
*/
public function setScholar(bool $scholar): void
{
$this->scholar = $scholar;
}
}