<?php
namespace App\Entity;
use App\Repository\UsersRepository;
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: UsersRepository::class)]
#[UniqueEntity(fields: ['email'], message: 'There is already an account with this email')]
class Users 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 = [];
#[ORM\Column(type: 'string')]
private $password;
#[ORM\Column(type: 'boolean')]
private $is_verified = false;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: Questionari::class, orphanRemoval: true)]
private $questionaris;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: UsersAmbienti::class, orphanRemoval: true)]
private $usersAmbientis;
#[ORM\Column(nullable: true)]
private $corsi_moodle;
public function __construct()
{
$this->questionaris = new ArrayCollection();
$this->usersAmbientis = new ArrayCollection();
}
public function __toString()
{
return $this->email;
}
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;
}
/**
* @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;
}
/**
* @see UserInterface
*/
public function eraseCredentials()
{
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
}
public function isVerified(): bool
{
return $this->is_verified;
}
public function setIsVerified(bool $isVerified): self
{
$this->is_verified = $isVerified;
return $this;
}
/**
* @return Collection<int, Questionari>
*/
public function getQuestionaris(): Collection
{
return $this->questionaris;
}
public function addQuestionari(Questionari $questionari): self
{
if (!$this->questionaris->contains($questionari)) {
$this->questionaris[] = $questionari;
$questionari->setUser($this);
}
return $this;
}
public function removeQuestionari(Questionari $questionari): self
{
if ($this->questionaris->removeElement($questionari)) {
// set the owning side to null (unless already changed)
if ($questionari->getUser() === $this) {
$questionari->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, UsersAmbienti>
*/
public function getUsersAmbientis(): Collection
{
return $this->usersAmbientis;
}
public function addUsersAmbienti(UsersAmbienti $usersAmbienti): self
{
if (!$this->usersAmbientis->contains($usersAmbienti)) {
$this->usersAmbientis[] = $usersAmbienti;
$usersAmbienti->setUser($this);
}
return $this;
}
public function removeUsersAmbienti(UsersAmbienti $usersAmbienti): self
{
if ($this->usersAmbientis->removeElement($usersAmbienti)) {
// set the owning side to null (unless already changed)
if ($usersAmbienti->getUser() === $this) {
$usersAmbienti->setUser(null);
}
}
return $this;
}
public function getCorsiMoodle(): ?string
{
return $this->corsi_moodle;
}
public function setCorsiMoodle(string $corsi_moodle): self
{
$this->corsi_moodle = $corsi_moodle;
return $this;
}
}