src/Entity/Users.php line 26
<?php
namespace App\Entity;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\LegacyPasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\User\EquatableInterface;
/**
* Users
*/
#[UniqueEntity('username', message: 'Uživatel s tímto uživatelským jménem už existuje.')]
#[UniqueEntity(fields: ['email', 'isDeleted'], message: 'Uživatel s tímto emailem už existuje.')]
#[ORM\Table(name: 'users')]
#[ORM\Index(name: 'IDX_D69CF8AF460D9222', columns: ['google_id'])]
#[ORM\Index(name: 'IDX_D69CF8AF460D9333', columns: ['google_access_token'])]
#[ORM\Index(name: 'IDX_D69CF8AF460D8989', columns: ['linkedin_id'])]
#[ORM\Entity]
class Users implements UserInterface, \Serializable, EquatableInterface, PasswordAuthenticatedUserInterface, LegacyPasswordAuthenticatedUserInterface
{
#[ORM\Column(name: 'id', type: 'integer', options: ['comment' => 'ID'])]
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'SEQUENCE')]
#[ORM\SequenceGenerator(sequenceName: 'seq_users_id', allocationSize: 1, initialValue: 1)]
private int $id;
#[ORM\Column(name: 'username', type: 'string', length: 96, nullable: false, options: ['comment' => 'Username'])]
private string $username;
#[ORM\Column(name: 'password', type: 'string', length: 128, nullable: false, options: ['comment' => 'Password'])]
private string $password;
#[ORM\Column(name: 'salt', type: 'string', length: 96, nullable: false, options: ['default' => 'tmpSolution'])]
private string $salt;
#[ORM\Column(name: 'first_name', type: 'string', length: 64, nullable: false, options: ['comment' => 'First name'])]
private ?string $firstName;
#[ORM\Column(name: 'last_name', type: 'string', length: 64, nullable: false, options: ['comment' => 'Last name'])]
private ?string $lastName;
#[ORM\Column(name: 'email', type: 'string', length: 128, nullable: false, options: ['comment' => 'Email'])]
private ?string $email;
#[ORM\Column(name: 'phone', type: 'string', length: 64, nullable: true, options: ['comment' => 'Phone'])]
private ?string $phone;
#[ORM\Column(name: 'institution', type: 'string', length: 128, nullable: true, options: ['comment' => 'Institution'])]
private ?string $institution;
#[ORM\Column(name: 'address', type: 'string', length: 255, nullable: true, options: ['comment' => 'Address'])]
private ?string $address;
#[ORM\Column(name: 'city', type: 'string', length: 128, nullable: true, options: ['comment' => 'City'])]
private ?string $city;
#[ORM\Column(name: 'postalcode', type: 'string', length: 15, nullable: true, options: ['comment' => 'Postal code'])]
private ?string $postalcode;
#[ORM\Column(name: 'auth_role', type: 'string', length: 20, nullable: false, options: ['comment' => 'Role'])]
private string $authRole;
#[ORM\Column(name: 'lastvisit_at', type: 'datetime', nullable: true)]
private ?DateTime $lastvisitAt;
#[ORM\Column(name: 'created_at', type: 'datetime', nullable: false, options: ['comment' => 'Created at', 'default' => 'now()'])]
private DateTime $createdAt;
#[ORM\Column(name: 'lastmod_at', type: 'datetime', nullable: true)]
private ?DateTime $lastmodAt;
#[ORM\ManyToOne(targetEntity: 'App\Entity\Users')]
#[ORM\JoinColumn(name: 'users_id', referencedColumnName: 'id')]
private ?Users $users;
#[ORM\Column(name: 'users_id', type: 'integer', nullable: false, options: ['comment' => 'Creating/editing user'])]
protected int $usersId;
#[ORM\Column(name: 'is_deleted', type: 'boolean', nullable: false, options: ['default' => false])]
private bool $isDeleted = false;
#[Assert\Length(min: 7, minMessage: "Heslo musí obsahovat minimálně 7 znaků.")]
#[Assert\Length(max: 4096, maxMessage: "Heslo může obsahovat maximálně 4096 znaků.")]
#[Assert\Regex(pattern: "/\d/", match: true, message: "Heslo musí obsahovat číslo.")]
#[Assert\Regex(pattern: "/[A-Z]/", match: true, message: "Heslo musí obsahovat velké písmeno.")]
#[Assert\Regex(pattern: "/[a-z]/", match: true, message: "Heslo musí obsahovat malé písmeno.")]
private ?string $plainPassword = null;
/**
* Null or expire date
*/
#[ORM\Column(name: 'PASSWORD_EXPIRE', type: 'datetime', nullable: true, options: ['comment' => 'Password expire date'])]
public $passwordExpire = null;
#[ORM\Column(name: 'PASSWORD_RESET_HASH', type: 'string', nullable: true, options: ['comment' => 'Hash needed to reset password'])]
protected ?string $passwordResetHash;
#[ORM\Column(name: 'PASSWORD_RESET_HASH_VALIDITY', type: 'datetime', nullable: true, options: ['comment' => 'Date until the password reset hash is valid'])]
protected ?DateTime $hashValidUntil;
#[ORM\Column(name: 'CREDENTIALS_SENT_LAST_ON', type: 'datetime', nullable: true, options: ['comment' => 'Last time sent user credentials'])]
protected ?DateTime $credentialsSentLastOn;
#[ORM\Column(name: 'SEND_CREDENTIALS_IMMEDIATELY', type: 'boolean', nullable: true, options: ['default' => true])]
protected ?bool $sendCredentialsImmediately = false;
#[ORM\Column(name: 'google_id', type: 'string', length: 2500, nullable: true)]
private ?string $googleId;
#[ORM\Column(name: 'google_access_token', type: 'string', length: 2500, nullable: true)]
private ?string $googleAccessToken;
#[ORM\Column(name: 'linkedin_id', type: 'string', length: 2500, nullable: true)]
private ?string $linkedinId;
#[ORM\Column(name: 'linkedin_access_token', type: 'string', length: 2500, nullable: true)]
private ?string $linkedinAccessToken;
#[ORM\Column(name: 'personal_number', type: 'string', length: 64, nullable: true, options: ['comment' => 'Personal number'])]
private ?string $personalNumber;
/**
* Stats where users used
*/
#[ORM\JoinTable(name: 'STAT_USERS')]
#[ORM\JoinColumn(name: 'USERS_ID', referencedColumnName: 'id', nullable: false)]
#[ORM\InverseJoinColumn(name: 'STAT_ID', referencedColumnName: 'id', nullable: false)]
#[ORM\ManyToMany(targetEntity: 'Stat', inversedBy: 'users')]
protected $stats;
public function __construct()
{
$this->stats = new ArrayCollection();
}
/**
* Set username
*
* @param string $username
*
* @return Users
*/
public function setUsername(string $username): Users
{
$this->username = $username;
return $this;
}
/**
* Set username
*
* @param string $username
*
* @return Users
*/
public function setUserIdentifier(string $username): Users
{
$this->username = $username;
return $this;
}
/**
* Get username
*
* @return string
*/
public function getUsername(): string
{
return $this->username;
}
/**
* Get username
*
* @return string
*/
public function getUserIdentifier(): string
{
return $this->username;
}
/**
* Set password
*
* @param string $password
*
* @return Users
*/
public function setPassword(string $password): Users
{
$this->password = $password;
return $this;
}
/**
* Get password
*
* @return string
*/
public function getPassword(): string
{
return $this->password;
}
/**
* Set salt
*
* @param string $salt
*
* @return Users
*/
public function setSalt(string $salt): Users
{
$this->salt = $salt;
return $this;
}
/**
* Get salt
*
* @return string
*/
public function getSalt(): string
{
return $this->salt;
}
/**
* Set firstName
*
* @param string $firstName
*
* @return Users
*/
public function setFirstName(string $firstName): Users
{
$this->firstName = $firstName;
return $this;
}
/**
* Get firstName
*
* @return string
*/
public function getFirstName(): string
{
return (string)$this->firstName;
}
/**
* Set lastName
*
* @param string $lastName
*
* @return Users
*/
public function setLastName(string $lastName): Users
{
$this->lastName = $lastName;
return $this;
}
/**
* Get lastName
*
* @return string
*/
public function getLastName(): string
{
return (string)$this->lastName;
}
/**
* Set email
*
* @param string $email
*
* @return Users
*/
public function setEmail(string $email): Users
{
$this->email = $email;
return $this;
}
/**
* Get email
*
* @return string
*/
public function getEmail(): string
{
return (string)$this->email;
}
/**
* Set phone
*
* @param string|null $phone
*
* @return Users
*/
public function setPhone(?string $phone): Users
{
$this->phone = $phone;
return $this;
}
/**
* Get phone
*
* @return string|null
*/
public function getPhone(): ?string
{
return $this->phone;
}
/**
* Set institution
*
* @param string|null $institution
*
* @return Users
*/
public function setInstitution(?string $institution): Users
{
$this->institution = $institution;
return $this;
}
/**
* Get institution
*
* @return string|null
*/
public function getInstitution(): ?string
{
return $this->institution;
}
/**
* Set address
*
* @param string|null $address
*
* @return Users
*/
public function setAddress(?string $address): Users
{
$this->address = $address;
return $this;
}
/**
* Get address
*
* @return string|null
*/
public function getAddress(): ?string
{
return $this->address;
}
/**
* Set city
*
* @param string|null $city
*
* @return Users
*/
public function setCity(?string $city): Users
{
$this->city = $city;
return $this;
}
/**
* Get city
*
* @return string|null
*/
public function getCity(): ?string
{
return $this->city;
}
/**
* Set postalcode
*
* @param string|null $postalcode
*
* @return Users
*/
public function setPostalcode(?string $postalcode): Users
{
$this->postalcode = $postalcode;
return $this;
}
/**
* Get postalcode
*
* @return string|null
*/
public function getPostalcode(): ?string
{
return $this->postalcode;
}
/**
* Set authRole
*
* @param string $authRole
*
* @return Users
*/
public function setAuthRole(string $authRole): Users
{
$this->authRole = $authRole;
return $this;
}
/**
* Get authRole
*
* @return string
*/
public function getAuthRole(): string
{
return $this->authRole;
}
/**
* Set lastvisitAt
*
* @param DateTime $lastvisitAt
*
* @return Users
*/
public function setLastvisitAt(DateTime $lastvisitAt): Users
{
$this->lastvisitAt = $lastvisitAt;
return $this;
}
/**
* Get lastvisitAt
*
* @return DateTime|null
*/
public function getLastvisitAt(): ?DateTime
{
return $this->lastvisitAt;
}
/**
* Set createdAt
*
* @param DateTime $createdAt
*
* @return Users
*/
public function setCreatedAt(DateTime $createdAt): Users
{
$this->createdAt = $createdAt;
return $this;
}
/**
* Get createdAt
*
* @return DateTime|null
*/
public function getCreatedAt(): ?DateTime
{
return $this->createdAt;
}
/**
* Set lastmodAt
*
* @param DateTime $lastmodAt
*
* @return Users
*/
public function setLastmodAt(DateTime $lastmodAt): Users
{
$this->lastmodAt = $lastmodAt;
return $this;
}
/**
* Get lastmodAt
*
* @return DateTime|null
*/
public function getLastmodAt(): ?DateTime
{
return $this->lastmodAt;
}
/**
* @return boolean
*/
public function isIsDeleted(): bool
{
return $this->isDeleted;
}
/**
* @param boolean $isDeleted
*/
public function setIsDeleted(bool $isDeleted)
{
$this->isDeleted = $isDeleted;
}
public function getPlainPassword()
{
return $this->plainPassword;
}
public function setPlainPassword($password)
{
$this->plainPassword = $password;
}
/**
* Get id
*
* @return integer
*/
public function getId(): int
{
return $this->id;
}
public function isAccountNonExpired(): bool
{
return true;
}
public function isAccountNonLocked(): bool
{
return true;
}
public function isCredentialsNonExpired(): bool
{
return true;
}
public function isEnabled(): bool
{
return !$this->getIsDeleted();
}
public function getRoles(): array
{
return array($this->getAuthRole());
}
public function eraseCredentials()
{
}
/** @see \Serializable::serialize() */
public function serialize(): ?string
{
return serialize(array(
$this->id,
$this->username,
$this->password,
// see section on salt below
// $this->salt,
));
}
/** @see \Serializable::unserialize() */
public function unserialize($serialized)
{
list (
$this->id,
$this->username,
$this->password,
// see section on salt below
// $this->salt
) = unserialize($serialized);
}
/**
* Get isDeleted
*
* @return boolean
*/
public function getIsDeleted(): bool
{
return $this->isDeleted;
}
/**
* @return Users|null
*/
public function getUsers(): ?Users
{
return $this->users;
}
/**
* @param Users $users
*/
public function setUsers(Users $users)
{
$this->users = $users;
}
/**
* @return int
*/
public function getUsersId(): int
{
return $this->usersId;
}
/**
* @param int $usersId
*/
public function setUsersId(int $usersId)
{
$this->usersId = $usersId;
}
/**
* @return null
*/
public function getPasswordExpire()
{
return $this->passwordExpire;
}
/**
* @param null $passwordExpire
*/
public function setPasswordExpire($passwordExpire)
{
$this->passwordExpire = $passwordExpire;
}
/**
* @return mixed
*/
public function getPasswordResetHash()
{
return $this->passwordResetHash;
}
/**
* @param mixed $passwordResetHash
*/
public function setPasswordResetHash($passwordResetHash)
{
$this->passwordResetHash = $passwordResetHash;
}
/**
* @return DateTime|null
*/
public function getHashValidUntil(): ?DateTime
{
return $this->hashValidUntil;
}
/**
* @param DateTime|null $hashValidUntil
*/
public function setHashValidUntil(?DateTime $hashValidUntil)
{
$this->hashValidUntil = $hashValidUntil;
}
/**
* @return DateTime|null
*/
public function getCredentialsSentLastOn(): ?DateTime
{
return $this->credentialsSentLastOn;
}
/**
* @param DateTime|null $credentialsSentLastOn
*/
public function setCredentialsSentLastOn(?DateTime $credentialsSentLastOn)
{
$this->credentialsSentLastOn = $credentialsSentLastOn;
}
/**
* @return bool
*/
public function isSendCredentialsImmediately(): bool
{
return $this->sendCredentialsImmediately;
}
/**
* @param bool $sendCredentialsImmediately
*/
public function setSendCredentialsImmediately(bool $sendCredentialsImmediately)
{
$this->sendCredentialsImmediately = $sendCredentialsImmediately;
}
public function isEqualTo(UserInterface $user): bool
{
if ($this->password !== $user->getPassword()) {
return false;
}
if ($this->username !== $user->getUserIdentifier()) {
return false;
}
return true;
}
/**
* @return string
*/
public function getGoogleId()
{
return $this->googleId;
}
/**
* @param string $googleId
*/
public function setGoogleId($googleId)
{
$this->googleId = $googleId;
}
/**
* @return string
*/
public function getGoogleAccessToken()
{
return $this->googleAccessToken;
}
/**
* @param string $googleAccessToken
*/
public function setGoogleAccessToken($googleAccessToken)
{
$this->googleAccessToken = $googleAccessToken;
}
/**
* @return string
*/
public function getLinkedinId()
{
return $this->linkedinId;
}
/**
* @param string $linkedinId
*/
public function setLinkedinId($linkedinId)
{
$this->linkedinId = $linkedinId;
}
/**
* @return string
*/
public function getLinkedinAccessToken()
{
return $this->linkedinAccessToken;
}
/**
* @param string $linkedinAccessToken
*/
public function setLinkedinAccessToken($linkedinAccessToken)
{
$this->linkedinAccessToken = $linkedinAccessToken;
}
/**
* @return string|null
*/
public function getPersonalNumber(): ?string
{
return $this->personalNumber;
}
/**
* @param string|null $personalNumber
*/
public function setPersonalNumber(?string $personalNumber): void
{
$this->personalNumber = $personalNumber;
}
public function getStats(): Collection
{
return $this->stats;
}
public function setStats(Collection $stats): Stat
{
$this->stat = $stats;
return $this;
}
public function customFormTitle() {
return trim($this->getLastName().' '.$this->getFirstName().' ('.$this->getId().')');
}
}