<?php
namespace App\Entity;
use App\Repository\UserRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\Collection;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
/**
* @ORM\Entity(repositoryClass=UserRepository::class)
* @UniqueEntity(fields="email", message="Email has already taken.")
* @UniqueEntity(fields="username", message="Username has already taken.")
*/
class User implements UserInterface
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @ORM\Column(type="string", length=180, unique=true)
*/
private $username;
/**
* @ORM\Column(type="json")
*/
private $roles = [];
/**
* @var string The hashed password
* @ORM\Column(type="string")
*/
private $password;
/**
* @ORM\Column(type="string", length=180, unique=true)
* @Assert\NotBlank(groups={"Default"})
* @Assert\Email(groups={"Default"})
*/
protected $email;
/**
* @ORM\Column(type="boolean", nullable=true, options={"default": 0})
*/
protected $enabled = false;
/**
* @var bool
*
* @ORM\Column(name="is_verified", type="boolean", nullable=false)
*/
private $isVerified;
protected $plainPassword;
/**
* @ORM\OneToOne(targetEntity=PatientHistory::class, mappedBy="idUser", cascade={"persist", "remove"})
*/
private $patientHistory;
/**
* @ORM\OneToOne(targetEntity=Doctor::class, mappedBy="user", cascade={"persist", "remove"})
*/
private $doctor;
/**
* @ORM\OneToOne(targetEntity=Nutritionist::class, mappedBy="user", cascade={"persist", "remove"})
*/
private $nutritionist;
/**
* @ORM\OneToMany(targetEntity=Exams::class, mappedBy="user")
*/
private $examsfile;
public function __construct()
{
$this->examsfile = new ArrayCollection();
}
public function __toString(){
return $this->username;
}
public function getId(): ?int
{
return $this->id;
}
/**
* A visual identifier that represents this user.
*
* @see UserInterface
*/
public function getUsername(): string
{
return (string) $this->username;
}
public function setUsername(string $username): self
{
$this->username = $username;
return $this;
}
/**
* @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 UserInterface
*/
public function getPassword(): ?string
{
return (string) $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
/**
* @see UserInterface
*/
public function getSalt()
{
// not needed when using the "bcrypt" algorithm in security.yaml
}
/**
* @see UserInterface
*/
public function eraseCredentials()
{
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
}
public function getPlainPassword(): ?string
{
return $this->plainPassword;
}
public function setPlainPassword(string $plainPassword): self
{
$this->plainPassword = $plainPassword;
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
public function getEnabled(): ?bool
{
return $this->enabled;
}
public function setEnabled(?bool $enabled): self
{
$this->enabled = $enabled;
return $this;
}
public function getIsVerified(): ?bool
{
return $this->isVerified;
}
public function setIsVerified(bool $isVerified): self
{
$this->isVerified = $isVerified;
return $this;
}
public function getPatientHistory(): ?PatientHistory
{
return $this->patientHistory;
}
public function setPatientHistory(PatientHistory $patientHistory): self
{
// set the owning side of the relation if necessary
if ($patientHistory->getIdUser() !== $this) {
$patientHistory->setIdUser($this);
}
$this->patientHistory = $patientHistory;
return $this;
}
public function getDoctor(): ?Doctor
{
return $this->doctor;
}
public function setDoctor(Doctor $doctor): self
{
// set the owning side of the relation if necessary
if ($doctor->getUser() !== $this) {
$doctor->setUser($this);
}
$this->doctor = $doctor;
return $this;
}
public function getNutritionist(): ?Nutritionist
{
return $this->nutritionist;
}
public function setNutritionist(Nutritionist $nutritionist): self
{
// set the owning side of the relation if necessary
if ($nutritionist->getUser() !== $this) {
$nutritionist->setUser($this);
}
$this->nutritionist = $nutritionist;
return $this;
}
/**
* @return Collection<int, Exams>
*/
public function getExamsfile(): Collection
{
return $this->examsfile;
}
public function addExamsfile(Exams $examsfile): self
{
if (!$this->examsfile->contains($examsfile)) {
$this->examsfile[] = $examsfile;
$examsfile->setUser($this);
}
return $this;
}
public function removeExamsfile(Exams $examsfile): self
{
if ($this->examsfile->removeElement($examsfile)) {
// set the owning side to null (unless already changed)
if ($examsfile->getUser() === $this) {
$examsfile->setUser(null);
}
}
return $this;
}
}