<?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\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* @ORM\Entity(repositoryClass=UserRepository::class)
* @UniqueEntity(fields={"email"}, message="There is already an account with this email")
*/
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=180, unique=true)
*/
private $email;
/**
* @ORM\Column(type="json")
*/
private $roles = [];
/**
* @var string The hashed password
* @ORM\Column(type="string")
*/
private $password;
/**
* @ORM\Column(type="boolean")
*/
private $isCancellato = 0;
/**
* @ORM\Column(type="boolean")
*/
private $isAttivo = 1;
/**
* @ORM\ManyToOne(targetEntity=Azienda::class, inversedBy="users")
*/
private $azienda;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $nome;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $cognome;
/**
* @ORM\Column(type="boolean")
*/
private $completataRegistrazione = 0;
/**
* @ORM\OneToMany(targetEntity=Domanda::class, mappedBy="user")
*/
private $domandas;
public function __construct()
{
$this->domandas = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
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 isCancellato(): ?bool
{
return $this->isCancellato;
}
public function setCancellato(bool $isCancellato): self
{
$this->isCancellato = $isCancellato;
return $this;
}
public function isAttivo(): ?bool
{
return $this->isAttivo;
}
public function setAttivo(bool $isAttivo): self
{
$this->isAttivo = $isAttivo;
return $this;
}
public function getAzienda(): ?Azienda
{
return $this->azienda;
}
public function setAzienda(?Azienda $azienda): self
{
$this->azienda = $azienda;
return $this;
}
public function getNome(): ?string
{
return $this->nome;
}
public function setNome(?string $nome): self
{
$this->nome = $nome;
return $this;
}
public function getCognome(): ?string
{
return $this->cognome;
}
public function setCognome(?string $cognome): self
{
$this->cognome = $cognome;
return $this;
}
public function isCompletataRegistrazione(): ?bool
{
return $this->completataRegistrazione;
}
public function setCompletataRegistrazione(bool $completataRegistrazione): self
{
$this->completataRegistrazione = $completataRegistrazione;
return $this;
}
/**
* @return Collection<int, Domanda>
*/
public function getDomandas(): Collection
{
return $this->domandas;
}
public function addDomanda(Domanda $domanda): self
{
if (!$this->domandas->contains($domanda)) {
$this->domandas[] = $domanda;
$domanda->setUser($this);
}
return $this;
}
public function removeDomanda(Domanda $domanda): self
{
if ($this->domandas->removeElement($domanda)) {
// set the owning side to null (unless already changed)
if ($domanda->getUser() === $this) {
$domanda->setUser(null);
}
}
return $this;
}
}