<?php
namespace App\Entity;
use App\Repository\UserRepository;
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;
/**
* @ORM\Entity(repositoryClass=UserRepository::class)
* @ORM\Table(name="app_user")
*/
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private ?int $id;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $name;
/**
* @ORM\Column(type="datetime_immutable", nullable=true, options={"default": "CURRENT_TIMESTAMP"})
*/
private $createAt;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $telegramId;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $phone;
/**
* @ORM\OneToMany(targetEntity=QuestionnaireResult::class, mappedBy="user")
*/
private $questionnaireResults;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $isAdmin;
/**
* @ORM\Column(type="boolean", nullable=true, options={"default": false})
*/
private ?bool $isBanned = false;
/**
* @ORM\Column(type="string", length=180, unique=true, nullable=true)
*/
private ?string $email;
/**
* @ORM\Column(type="string", length=180, nullable=true)
*/
private ?string $city;
/**
* @ORM\Column(type="json", nullable=true)
*/
private ?array $roles = null;
/**
* @var string The hashed password
* @ORM\Column(type="string", nullable=true)
*/
private string $password;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $brandsHistory = null;
public function __construct()
{
$this->questionnaireResults = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function __toString(): string
{
return $this->getPhone().", ".$this->getName();
}
public function getName(): ?string
{
return $this->name;
}
public function setName(?string $name): self
{
$this->name = $name;
return $this;
}
public function getCreateAt(): ?\DateTimeImmutable
{
return $this->createAt;
}
public function setCreateAt(\DateTimeInterface $createAt): self
{
$this->createAt = $createAt;
return $this;
}
public function getTelegramId(): ?string
{
return $this->telegramId;
}
public function setTelegramId(?string $telegramId): self
{
$this->telegramId = $telegramId;
return $this;
}
public function getPhone(): ?string
{
return $this->phone;
}
public function setPhone(?string $phone): self
{
$this->phone = $phone;
return $this;
}
/**
* @return Collection<int, QuestionnaireResult>
*/
public function getQuestionnaireResults(): Collection
{
return $this->questionnaireResults;
}
public function addQuestionnaireResult(QuestionnaireResult $questionnaireResult): self
{
if (!$this->questionnaireResults->contains($questionnaireResult)) {
$this->questionnaireResults[] = $questionnaireResult;
$questionnaireResult->setUser($this);
}
return $this;
}
public function removeQuestionnaireResult(QuestionnaireResult $questionnaireResult): self
{
if ($this->questionnaireResults->removeElement($questionnaireResult)) {
// set the owning side to null (unless already changed)
if ($questionnaireResult->getUser() === $this) {
$questionnaireResult->setUser(null);
}
}
return $this;
}
public function isIsAdmin(): ?bool
{
return $this->isAdmin;
}
public function setIsAdmin(?bool $isAdmin): self
{
$this->isAdmin = $isAdmin;
return $this;
}
public function isBanned(): ?bool
{
return $this->isBanned;
}
public function setIsBanned(?bool $isBanned): self
{
$this->isBanned = $isBanned;
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
/**
* A visual identifier that represents this user.
*
* @see UserInterface
*/
public function getUserIdentifier(): string
{
return (string) $this->email;
}
/**
* @deprecated since Symfony 5.3, use getUserIdentifier instead
*/
public function getUsername(): string
{
return (string) $this->email;
}
/**
* @see UserInterface
*/
public function getRoles(): array
{
$roles = $this->roles;
// guarantee every user at least has ROLE_USER
$roles[] = 'ROLE_USER';
return array_unique($roles);
}
public function setRoles(array $roles): self
{
$this->roles = $roles;
return $this;
}
/**
* @see PasswordAuthenticatedUserInterface
*/
public function getPassword(): string
{
return $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
/**
* Returning a salt is only needed, if you are not using a modern
* hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
*
* @see UserInterface
*/
public function getSalt(): ?string
{
return null;
}
/**
* @see UserInterface
*/
public function eraseCredentials()
{
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
}
public function getCity(): ?string
{
return $this->city;
}
public function setCity(?string $city): self
{
$this->city = $city;
return $this;
}
public function getBrandsHistory(): ?string
{
return $this->brandsHistory;
}
public function setBrandsHistory(?string $brandsHistory): self
{
$this->brandsHistory = $brandsHistory;
return $this;
}
}