<?php
namespace App\Admin\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Validator\Constraints as Assert;
/**
* StdUsers
*/
#[ORM\Table(name: 'std_users')]
#[ORM\Index(name: 'fk_std_users_std_users', columns: ['created_by'])]
#[ORM\Index(name: 'fk_std_users_std_users_upd', columns: ['updated_by'])]
#[ORM\Entity(repositoryClass: 'App\Admin\Repository\StdUsersRepository')]
#[ORM\HasLifecycleCallbacks]
class StdUsers implements UserInterface/*, \Serializable*/, PasswordAuthenticatedUserInterface
{
/**
* @var int
*/
#[ORM\Column(name: 'id', type: 'integer', nullable: false, options: ['unsigned' => true, 'comment' => 'Unique identifier'])]
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'IDENTITY')]
private $id;
/**
* @var string|null
*/
#[ORM\Column(name: 'name', type: 'string', length: 255, nullable: true, options: ['comment' => "User's name"])]
private $name;
/**
* @var string
*/
#[ORM\Column(name: 'username', type: 'string', length: 100, nullable: false, options: ['comment' => 'Username used to login'])]
private $username;
/**
* @var string
*/
#[Assert\Email]
#[ORM\Column(name: 'email', type: 'string', length: 254, nullable: false, options: ['comment' => 'Email address of the user'])]
private $email;
/**
* @var string
*/
#[ORM\Column(name: 'password', type: 'string', length: 255, nullable: false, options: ['comment' => "User's password"])]
private $password;
/**
* @var \DateTime|null
*/
#[ORM\Column(name: 'password_date', type: 'datetime', nullable: true, options: ['comment' => 'Last date and time the password was updated'])]
private $passwordDate;
/**
* @var int|null
*/
#[ORM\Column(name: 'failed_attempts', type: 'integer', nullable: true, options: ['unsigned' => true, 'comment' => 'Number of failed login attempts'])]
private $failedAttempts = '0';
/**
* @var bool|null
*/
#[ORM\Column(name: 'force_password_change', type: 'boolean', nullable: true, options: ['comment' => 'Flag to force the user to change the password on the next login'])]
private $forcePasswordChange;
/**
* @var \DateTime|null
*/
#[ORM\Column(name: 'last_login_date', type: 'datetime', nullable: true, options: ['comment' => 'Date and time of the last successful login'])]
private $lastLoginDate;
/**
* @var \DateTime|null
*/
#[ORM\Column(name: 'penultimate_login_date', type: 'datetime', nullable: true, options: ['comment' => 'Date and time of the penultimate successful login'])]
private $penultimateLoginDate;
/**
* @var string|null
*/
#[ORM\Column(name: 'language', type: 'string', length: 3, nullable: true, options: ['comment' => "Preferred user interface's language code"])]
private $language;
/**
* @var bool
*/
#[ORM\Column(name: 'is_locked', type: 'boolean', nullable: false, options: ['comment' => 'Flag to lock the user'])]
private $isLocked = '0';
/**
* @var bool
*/
#[ORM\Column(name: 'is_super_user', type: 'boolean', nullable: false, options: ['comment' => 'Flag indicating super user privileges'])]
private $isSuperUser = '0';
/**
* @var bool
*/
#[ORM\Column(name: 'is_deleted', type: 'boolean', nullable: false, options: ['comment' => 'Flag that indicates the user has been deleted'])]
private $isDeleted = '0';
/**
* @var bool
*/
#[ORM\Column(name: 'is_active', type: 'boolean', nullable: false, options: ['default' => 1, 'comment' => 'Flag that indicates if the user is active'])]
private $isActive = '1';
/**
* @var \DateTime
*/
#[ORM\Column(name: 'created_date', type: 'datetime', nullable: false, options: ['comment' => 'Date and time of the record creation'])]
private $createdDate;
/**
* @var \DateTime
*/
#[ORM\Column(name: 'updated_date', type: 'datetime', nullable: false, options: ['comment' => 'Date and time the record was last updated'])]
private $updatedDate;
/**
* @var \App\Admin\Entity\StdUsers
*/
#[ORM\JoinColumn(name: 'created_by', referencedColumnName: 'id')]
#[ORM\ManyToOne(targetEntity: '\App\Admin\Entity\StdUsers')]
private $createdBy;
/**
* @var \App\Admin\Entity\StdUsers
*/
#[ORM\JoinColumn(name: 'updated_by', referencedColumnName: 'id')]
#[ORM\ManyToOne(targetEntity: '\App\Admin\Entity\StdUsers')]
private $updatedBy;
/**
* @var Doctrine\Common\Collections\ArrayCollection|null
*/
#[ORM\OneToMany(targetEntity: 'StdFavoritePagesUsers', mappedBy: 'userId', cascade: ['persist', 'remove'], orphanRemoval: true, fetch: 'EXTRA_LAZY')]
private $favoritePages;
#[ORM\ManyToMany(targetEntity: StdRoles::class, inversedBy: 'users')]
private Collection $userRoles;
/**
* @var Collection<int, StdPages>
*/
#[ORM\ManyToMany(targetEntity: StdPages::class, mappedBy: 'pageAuthors')]
#[ORM\JoinTable(name: 'std_pages_authors')]
private Collection $authoredPages;
/**
* @var string|null
*/
#[ORM\Column(name: 'author_function', type: 'string', length: 2048, nullable: true, options: ['comment' => 'User function/role when authoring pages'])]
private $authorFunction;
/**
* @var string|null
*/
#[ORM\Column(name: 'user_image', type: 'string', length: 255, nullable: true, options: ['comment' => 'User avatar image'])]
private $userImage;
public function __construct()
{
$this->userRoles = new ArrayCollection();
$this->authoredPages = new ArrayCollection();
}
/**
* @param bool $firewallCall this must be true if used to validate user roles on Symfony's native code, otherwise it'll return a Collection and Symfony will be mad
* @return array|Collection<int, StdRoles> this will return either an array or a Collection, depending on how the parameter above is setup
*/
public function getRoles(bool $firewallCall = true): array|Collection
{
if ($firewallCall) {
$roleArray = [];
foreach ($this->userRoles as $role) {
if ($role->getIsActive()) {
$roleArray[] = $role->getName();
}
}
if (empty($roleArray)) {
$roleArray[] = 'ROLE_ADMIN';
}
} else {
$roleArray = $this->userRoles;
}
return $roleArray;
}
/**
* @return Collection<int, StdRoles> this will return a Collection
*/
public function getUserRoles(): array|Collection
{
return $this->userRoles;
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(?string $name): self
{
$this->name = $name;
return $this;
}
public function getUsername(): ?string
{
return $this->username;
}
public function getUserIdentifier(): string
{
return (string) $this->username;
}
public function setUsername(string $username): self
{
$this->username = $username;
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
public function getPassword(): ?string
{
return $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
public function getPasswordDate(): ?\DateTimeInterface
{
return $this->passwordDate;
}
public function setPasswordDate(?\DateTimeInterface $passwordDate): self
{
$this->passwordDate = $passwordDate;
return $this;
}
public function getFailedAttempts(): ?int
{
return $this->failedAttempts;
}
public function setFailedAttempts(?int $failedAttempts): self
{
$this->failedAttempts = $failedAttempts;
return $this;
}
public function getForcePasswordChange(): ?bool
{
return $this->forcePasswordChange;
}
public function setForcePasswordChange(?bool $forcePasswordChange): self
{
$this->forcePasswordChange = $forcePasswordChange;
return $this;
}
public function getLastLoginDate(): ?\DateTimeInterface
{
return $this->lastLoginDate;
}
public function setLastLoginDate(?\DateTimeInterface $lastLoginDate): self
{
$this->lastLoginDate = $lastLoginDate;
return $this;
}
public function getPenultimateLoginDate(): ?\DateTimeInterface
{
return $this->penultimateLoginDate;
}
public function setPenultimateLoginDate(?\DateTimeInterface $penultimateLoginDate): self
{
$this->penultimateLoginDate = $penultimateLoginDate;
return $this;
}
public function getLanguage(): ?string
{
return $this->language;
}
public function setLanguage(?string $language): self
{
$this->language = $language;
return $this;
}
public function getIsLocked(): ?bool
{
return $this->isLocked;
}
public function setIsLocked(bool $isLocked): self
{
$this->isLocked = $isLocked;
return $this;
}
public function getIsSuperUser(): ?bool
{
return $this->isSuperUser;
}
public function setIsSuperUser(bool $isSuperUser): self
{
$this->isSuperUser = $isSuperUser;
return $this;
}
public function getIsDeleted(): ?bool
{
return $this->isDeleted;
}
public function setIsDeleted(bool $isDeleted): self
{
$this->isDeleted = $isDeleted;
return $this;
}
public function getIsActive(): ?bool
{
return $this->isActive;
}
public function setIsActive(bool $isActive): self
{
$this->isActive = $isActive;
return $this;
}
public function getCreatedDate(): ?\DateTimeInterface
{
return $this->createdDate;
}
public function setCreatedDate(\DateTimeInterface $createdDate): self
{
$this->createdDate = $createdDate;
return $this;
}
public function getUpdatedDate(): ?\DateTimeInterface
{
return $this->updatedDate;
}
public function setUpdatedDate(\DateTimeInterface $updatedDate): self
{
$this->updatedDate = $updatedDate;
return $this;
}
public function getCreatedBy(): ?\App\Admin\Entity\StdUsers
{
return $this->createdBy;
}
public function setCreatedBy(?self $createdBy): self
{
$this->createdBy = $createdBy;
return $this;
}
public function getUpdatedBy(): ?self
{
return $this->updatedBy;
}
public function setUpdatedBy(?self $updatedBy): self
{
$this->updatedBy = $updatedBy;
return $this;
}
public function getSalt(): ?string
{
return null;
}
public function eraseCredentials()
{
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
}
#[ORM\PreUpdate]
public function setUpdated()
{
$this->setUpdatedDate(new \DateTime());
}
#[ORM\PrePersist]
public function setCreated()
{
$this->setUpdatedDate(new \DateTime());
$this->setCreatedDate(new \DateTime());
}
/**
* Get the value of favoritePage
*
* @return object
*/
public function getFavoritePage()
{
return $this->favoritePages;
}
/**
* Set the value of favoritePage
*
* @param Page $favoritePage
*
* @return self
*/
public function setFavoritePage(object $favoritePage)
{
$this->favoritePages = $favoritePage;
return $this;
}
/** Function serialize is here to solve "Notice: unserialize(): Error at offset" on php version 7.3 */
/*public function serialize()
{
list($major, $minor, $release) = explode(".", phpversion());
$vars = get_object_vars($this);
if ($major == 7 && $minor == 3)
{
unset($vars["createdBy"]);
unset($vars["updatedBy"]);
unset($vars["favoritePages"]);
}
return serialize($vars);
}*/
/** Function unserialize is here to solve "Notice: unserialize(): Error at offset" on php version 7.3 */
/*public function unserialize($data)
{
$vars = unserialize($data);
foreach ($vars as $key => $value)
{
$this->$key = $value;
}
}*/
public function addUserRole(StdRoles $role): static
{
if (!$this->userRoles->contains($role)) {
$this->userRoles->add($role);
}
return $this;
}
public function removeUserRole(StdRoles $role): static
{
$this->userRoles->removeElement($role);
return $this;
}
public function isSuperAdmin(): bool
{
foreach ($this->getRoles() as $role) {
if ($role === "ROLE_SUPER_ADMIN") {
return true;
}
}
return false;
}
/**
* @return Collection<int, StdPages>
*/
public function getAuthoredPages(): Collection
{
return $this->authoredPages;
}
public function addAuthoredPage(StdPages $page): self
{
if (!$this->authoredPages->contains($page)) {
$this->authoredPages->add($page);
}
return $this;
}
public function removeAuthoredPage(StdPages $page): self
{
$this->authoredPages->removeElement($page);
return $this;
}
public function getAuthorFunction(): ?string
{
return $this->authorFunction;
}
public function setAuthorFunction(?string $authorFunction): self
{
$this->authorFunction = $authorFunction;
return $this;
}
public function getUserImage(): ?string
{
return $this->userImage;
}
public function setUserImage(?string $userImage): self
{
$this->userImage = $userImage;
return $this;
}
}