<?php
namespace App\Entity;
use App\Constants\ActiveConstants;
use App\Repository\UserRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Sonata\UserBundle\Entity\BaseUser;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Validator\Constraints as Assert;
#[UniqueEntity('email')]
#[ORM\Entity(repositoryClass: UserRepository::class)]
#[ORM\HasLifecycleCallbacks]
class User extends BaseUser
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
protected $id;
#[ORM\Column(name: 'timezone', type: 'string', length: 255, nullable: true)]
protected ?string $timezone = null;
#[ORM\ManyToMany(targetEntity: Company::class, mappedBy: 'users')]
private Collection $companies;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: PhoneNumber::class)]
private Collection $phoneNumbers;
#[ORM\OneToMany(mappedBy: 'lockedUser', targetEntity: PhoneNumber::class)]
private Collection $lockedPhones;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: Order::class)]
private Collection $orders;
#[ORM\Column(length: 191, nullable: true)]
private ?string $firstName = null;
#[ORM\Column(length: 191, nullable: true)]
private ?string $middleName = null;
#[ORM\Column(length: 191, nullable: true)]
private ?string $lastName = null;
#[ORM\Column(length: 191, nullable: true)]
private ?string $verifyCode = null;
#[ORM\Column(name: 'email_verified_at', type: 'datetime', nullable: true)]
private $emailVerifiedAt;
#[ORM\Column(name: 'code_sent_at', type: 'datetime', nullable: true)]
private $codeSentAt;
#[ORM\Column(name: 'generate_phone_hash_at', type: 'datetime', nullable: true)]
private $generatePhoneHashAt;
#[Assert\NotBlank]
#[Assert\Email]
protected ?string $email;
#[ORM\Column(length: 191, nullable: true)]
private ?string $resetHash = null;
#[ORM\Column(length: 191, nullable: true)]
private ?string $numberHash = null;
#[ORM\Column(type: 'text', nullable: true)]
private ?string $metaTags = null;
public function __construct()
{
$this->companies = new ArrayCollection();
$this->phoneNumbers = new ArrayCollection();
$this->orders = new ArrayCollection();
$this->lockedPhones = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getTimezone(): ?string
{
return $this->timezone;
}
public function setTimezone(?string $timezone): self
{
$this->timezone = $timezone;
return $this;
}
/**
* @return Collection<int, Company>
*/
public function getCompanies(): Collection
{
return $this->companies;
}
public function addCompany(Company $company): static
{
if (!$this->companies->contains($company)) {
$this->companies->add($company);
$company->addUser($this);
}
return $this;
}
public function hasCompany(Company $company)
{
return $this->companies->contains($company);
}
public function removeCompany(Company $company): static
{
if ($this->companies->removeElement($company)) {
$company->removeUser($this);
}
return $this;
}
/**
* @return Collection<int, PhoneNumber>
*/
public function getPhoneNumbers(): Collection
{
return $this->phoneNumbers;
}
public function addPhoneNumber(PhoneNumber $phoneNumber): static
{
if (!$this->phoneNumbers->contains($phoneNumber)) {
$this->phoneNumbers->add($phoneNumber);
$phoneNumber->setUser($this);
}
return $this;
}
public function removePhoneNumber(PhoneNumber $phoneNumber): static
{
if ($this->phoneNumbers->removeElement($phoneNumber)) {
// set the owning side to null (unless already changed)
if ($phoneNumber->getUser() === $this) {
$phoneNumber->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, Order>
*/
public function getOrders(): Collection
{
return $this->orders;
}
public function addOrder(Order $order): static
{
if (!$this->orders->contains($order)) {
$this->orders->add($order);
$order->setUser($this);
}
return $this;
}
public function removeOrder(Order $order): static
{
if ($this->orders->removeElement($order)) {
// set the owning side to null (unless already changed)
if ($order->getUser() === $this) {
$order->setUser(null);
}
}
return $this;
}
public function getFirstName(): ?string
{
return $this->firstName;
}
public function setFirstName(?string $firstName): static
{
$this->firstName = $firstName;
return $this;
}
public function getMiddleName(): ?string
{
return $this->middleName;
}
public function setMiddleName(?string $middleName): static
{
$this->middleName = $middleName;
return $this;
}
public function getLastName(): ?string
{
return $this->lastName;
}
public function setLastName(?string $lastName): static
{
$this->lastName = $lastName;
return $this;
}
public function getVerifyCode(): ?string
{
return $this->verifyCode;
}
public function setVerifyCode(?string $verifyCode): static
{
$this->verifyCode = $verifyCode;
return $this;
}
public function getEmailVerifiedAt(): ?\DateTimeInterface
{
return $this->emailVerifiedAt;
}
public function setEmailVerifiedAt(?\DateTimeInterface $emailVerifiedAt): static
{
$this->emailVerifiedAt = $emailVerifiedAt;
return $this;
}
public function getCodeSentAt(): ?\DateTimeInterface
{
return $this->codeSentAt;
}
public function setCodeSentAt(?\DateTimeInterface $codeSentAt): static
{
$this->codeSentAt = $codeSentAt;
return $this;
}
public function getResetHash(): ?string
{
return $this->resetHash;
}
public function setResetHash(?string $resetHash): static
{
$this->resetHash = $resetHash;
return $this;
}
/**
* @return Collection<int, PhoneNumber>
*/
public function getLockedPhones(): Collection
{
return $this->lockedPhones;
}
public function addLockedPhone(PhoneNumber $lockedPhone): static
{
if (!$this->lockedPhones->contains($lockedPhone)) {
$this->lockedPhones->add($lockedPhone);
$lockedPhone->setLockedUser($this);
}
return $this;
}
public function removeLockedPhone(PhoneNumber $lockedPhone): static
{
if ($this->lockedPhones->removeElement($lockedPhone)) {
// set the owning side to null (unless already changed)
if ($lockedPhone->getLockedUser() === $this) {
$lockedPhone->setLockedUser(null);
}
}
return $this;
}
public function getNumberHash(): ?string
{
return $this->numberHash;
}
public function setNumberHash(?string $numberHash): static
{
$this->numberHash = $numberHash;
return $this;
}
public function getGeneratePhoneHashAt(): ?\DateTimeInterface
{
return $this->generatePhoneHashAt;
}
public function setGeneratePhoneHashAt(?\DateTimeInterface $generatePhoneHashAt): static
{
$this->generatePhoneHashAt = $generatePhoneHashAt;
return $this;
}
public function getMetaTags(): ?string
{
return $this->metaTags;
}
public function setMetaTags(?string $metaTags): static
{
$this->metaTags = $metaTags;
return $this;
}
public function getEnabledLabel(): string
{
return $this->isEnabled() ? ActiveConstants::LABEL_YES : ActiveConstants::LABEL_NO;
}
}