<?php
namespace App\Admin\Entity;
use App\Entity\StdPagesTracking;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\UserInterface;
use App\Admin\Entity\StdWebUsersAddresses as StdWebUsersAddresses;
use JsonSerializable;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
/**
* StdUsers
*/
#[ORM\Table(name: 'std_web_users')]
#[ORM\Entity(repositoryClass: 'App\Admin\Repository\StdWebUsersRepository')]
#[ORM\HasLifecycleCallbacks]
class StdWebUsers implements UserInterface, JsonSerializable, 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|null
*/
#[ORM\Column(name: 'erp_code', type: 'string', length: 50, nullable: true, options: ['comment' => "User's erp code"])]
private $erpCode;
/**
* @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: true, 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 \App\Admin\Entity\StdUsers
*/
#[ORM\JoinColumn(name: 'created_by', referencedColumnName: 'id')]
#[ORM\ManyToOne(targetEntity: 'App\Admin\Entity\StdUsers')]
private $createdBy;
/**
* @var \DateTime
*/
#[ORM\Column(name: 'created_date', type: 'datetime', nullable: false, options: ['comment' => 'Date and time of the record creation'])]
private $createdDate;
/**
* @var string|null
*/
#[ORM\Column(name: 'passwordrecovery', type: 'string', length: 250, nullable: true)]
private $passwordrecovery;
/**
* @var json|null
*/
#[ORM\Column(name: 'info', type: 'json', nullable: true, options: ['comment' => 'Other information'])]
private $info;
/**
* @var string|null
*/
#[ORM\Column(name: 'logintoken', type: 'string', length: 32, nullable: true)]
private $logintoken;
/**
* @var string|null
*/
#[ORM\Column(name: 'activationkey', type: 'string', length: 100, nullable: true)]
private $activationkey;
/**
* @var string|null
*/
#[ORM\Column(name: 'facebook_id', type: 'string', length: 255, nullable: true)]
private $facebookId;
/**
* @var bool|null
*/
#[ORM\Column(name: 'facebook_integration', type: 'boolean', nullable: true)]
private $facebookIntegration;
/**
* @var string|null
*/
#[ORM\Column(name: 'google_id', type: 'string', length: 255, nullable: true)]
private $googleId;
/**
* @var bool|null
*/
#[ORM\Column(name: 'google_integration', type: 'boolean', nullable: true)]
private $googleIntegration;
/**
* @var string|null
*/
#[ORM\Column(name: 'apple_id', type: 'string', length: 255, nullable: true)]
private $appleId;
/**
* @var string|null
*/
#[ORM\Column(name: 'apple_refresh_token', type: 'string', length: 255, nullable: true)]
private $appleRefreshToken;
/**
* @var \DateTime|null
*/
#[ORM\Column(name: 'terms_accepted_at', type: 'datetime', nullable: true)]
private $termsAcceptedAt;
/**
* @var string|null
*/
#[ORM\Column(name: 'phone', type: 'string', length: 20, nullable: true)]
private $phone;
/**
* @var string|null
*/
#[ORM\Column(name: 'mobile', type: 'string', length: 20, nullable: true)]
private $mobile;
/**
* @var string|null
*/
#[ORM\Column(name: 'vat', type: 'string', length: 20, nullable: true)]
private $vat;
#[ORM\OneToMany(targetEntity: 'StdWebUsersAddresses', mappedBy: 'webuser', cascade: ['persist', 'remove'], orphanRemoval: true)]
private $addresses;
/**
* @var \App\Admin\Entity\StdUsers
*/
#[ORM\JoinColumn(name: 'updated_by', referencedColumnName: 'id')]
#[ORM\ManyToOne(targetEntity: 'App\Admin\Entity\StdUsers')]
private $updatedBy;
/**
* @var \DateTime
*/
#[ORM\Column(name: 'updated_date', type: 'datetime', nullable: false, options: ['comment' => 'Date and time the record was last updated'])]
private $updatedDate;
/**
* @var array
*/
#[ORM\Column(type: 'json')]
private $roles = [];
#[ORM\OneToMany(mappedBy: 'webUser', targetEntity: StdPagesTracking::class)]
private Collection $pageTrackings;
public function __construct()
{
$this->addresses = new ArrayCollection();
$this->pageTrackings = new ArrayCollection();
}
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
{
if(empty($this->username)){
return $this->getEmail();
}else{
return $this->username;
}
}
public function getUserIdentifier(): string
{
if(empty($this->username)){
return (string) $this->getEmail();
}else{
return (string) $this->username;
}
}
public function setUsername(string $username): self
{
$this->username = $username;
return $this;
}
public function getErpCode(): ?string
{
return $this->erpCode;
}
public function setErpCode(?string $erpcode): self
{
$this->erpCode = $erpcode;
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 getRoles(): array
{
return $this->roles;
}
public function setRoles(array $roles): self
{
foreach ($roles as $value) {
$data[] = $value->getName();
}
$this->roles = $data;
return $this;
}
public function getPasswordrecovery(): ?string
{
return $this->passwordrecovery;
}
public function setPasswordrecovery(?string $passwordrecovery): self
{
$this->passwordrecovery = $passwordrecovery;
return $this;
}
public function getInfo(): ?array
{
return $this->info;
}
public function setInfo(?array $info): self
{
$this->info = $info;
return $this;
}
public function getLogintoken(): ?string
{
return $this->logintoken;
}
public function setLogintoken(?string $logintoken): self
{
$this->logintoken = $logintoken;
return $this;
}
public function getActivationkey(): ?string
{
return $this->activationkey;
}
public function setActivationkey(?string $activationkey): self
{
$this->activationkey = $activationkey;
return $this;
}
public function getFacebookId(): ?string
{
return $this->facebookId;
}
public function setFacebookId(?string $facebookId): self
{
$this->facebookId = $facebookId;
return $this;
}
public function getFacebookIntegration(): ?bool
{
return $this->facebookIntegration;
}
public function setFacebookIntegration(?bool $facebookIntegration): self
{
$this->facebookIntegration = $facebookIntegration;
return $this;
}
public function getGoogleId(): ?string
{
return $this->googleId;
}
public function setGoogleId(?string $googleId): self
{
$this->googleId = $googleId;
return $this;
}
public function getAppleId(): ?string
{
return $this->appleId;
}
public function setAppleId(?string $appleId): self
{
$this->appleId = $appleId;
return $this;
}
public function getAppleRefreshToken(): ?string
{
return $this->appleRefreshToken;
}
public function setAppleRefreshToken(?string $appleRefreshToken): self
{
$this->appleRefreshToken = $appleRefreshToken;
return $this;
}
public function getGoogleIntegration(): ?bool
{
return $this->googleIntegration;
}
public function setGoogleIntegration(?bool $googleIntegration): self
{
$this->googleIntegration = $googleIntegration;
return $this;
}
public function getTermsAcceptedAt(): ?\DateTimeInterface
{
return $this->termsAcceptedAt;
}
public function setTermsAcceptedAt(?\DateTimeInterface $termsAcceptedAt): self
{
$this->termsAcceptedAt = $termsAcceptedAt;
return $this;
}
public function getPhone(): ?string
{
return $this->phone;
}
public function setPhone(?string $phone): self
{
$this->phone = $phone;
return $this;
}
public function getMobile(): ?string
{
return $this->mobile;
}
public function setMobile(?string $mobile): self
{
$this->mobile = $mobile;
return $this;
}
public function getVat(): ?string
{
return $this->vat;
}
public function setVat(?string $vat): self
{
$this->vat = $vat;
return $this;
}
/**
* @return Collection|StdWebUsersAddresses[]
*/
public function getAddresses(): Collection
{
return $this->addresses;
}
public function removeAddress(StdWebUsersAddresses $address): self
{
if ($this->addresses->contains($address)) {
$this->addresses->removeElement($address);
// set the owning side to null (unless already changed)
if ($address->getWebuser() === $this) {
$address->setWebuser(null);
}
}
return $this;
}
public function addAddress(StdWebUsersAddresses $address): self
{
if (!$this->addresses->contains($address)) {
$this->addresses[] = $address;
$address->setWebuser($this);
}
return $this;
}
public function getUpdatedBy(): ?\App\Admin\Entity\StdUsers
{
return $this->updatedBy;
}
public function setUpdatedBy(?StdUsers $updatedBy): self
{
$this->updatedBy = $updatedBy;
return $this;
}
public function getCreatedBy(): ?\App\Admin\Entity\StdUsers
{
return $this->createdBy;
}
public function setCreatedBy(?StdUsers $createdBy): self
{
$this->createdBy = $createdBy;
return $this;
}
public function eraseCredentials(){
return true;
}
#[ORM\PreUpdate]
public function setUpdated()
{
$newroles = [];
if (is_array(($roles = $this->getRoles())))
foreach ($roles as $role)
if ($role instanceof StdWebRoles)
$newroles[] = $role->getName();
else
$newroles[] = $role;
$this->roles=$newroles;
$this->setUpdatedDate(new \DateTime());
}
#[ORM\PrePersist]
public function setCreated()
{
$newroles = [];
if (is_array(($roles = $this->getRoles())))
foreach ($roles as $role)
if ($role instanceof StdWebRoles)
$newroles[] = $role->getName();
else
$newroles[] = $role;
$this->roles=$newroles;
$this->setUpdatedDate(new \DateTime());
$this->setCreatedDate(new \DateTime());
}
public function getSalt(): ?string
{
return null;
}
public function jsonSerialize(): mixed
{
$result = get_object_vars($this);
$result['addresses']=[];
foreach ($this->getAddresses() as $address)
{
$result["addresses"][]=$address->jsonSerialize();
}
return $result;
}
/**
* @return Collection<int, StdPagesTracking>
*/
public function getPageTrackings(): Collection
{
return $this->pageTrackings;
}
public function addPageTracking(StdPagesTracking $pageTracking): static
{
if (!$this->pageTrackings->contains($pageTracking)) {
$this->pageTrackings->add($pageTracking);
$pageTracking->setWebUser($this);
}
return $this;
}
public function removePageTracking(StdPagesTracking $pageTracking): static
{
if ($this->pageTrackings->removeElement($pageTracking)) {
// set the owning side to null (unless already changed)
if ($pageTracking->getWebUser() === $this) {
$pageTracking->setWebUser(null);
}
}
return $this;
}
}