<?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 ?int $id;
#[ORM\Column(type: 'string', length: 180, unique: true)]
private ?string $email;
#[ORM\Column(type: 'json')]
private array $roles = [];
#[ORM\Column(type: 'string', length: 255)]
private ?string $firstName;
#[ORM\Column(type: 'string', length: 255)]
private ?string $lastName;
#[ORM\Column(type: 'string', length: 255)]
private $password;
private $plainPassword;
#[ORM\Column(type: 'boolean')]
private $isVerified = false;
#[ORM\OneToMany(mappedBy: 'school', targetEntity: SchoolClass::class)]
private $schoolClasses;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: SchoolRegistration::class)]
private $schoolRegistrations;
public function __construct()
{
$this->schoolClasses = new ArrayCollection();
$this->schoolRegistrations = 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;
}
/**
* @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 eraseCredentials()
{
$this->plainPassword = null;
}
public function getFirstName(): ?string
{
return $this->firstName;
}
public function setFirstName(string $firstName): self
{
$this->firstName = $firstName;
return $this;
}
public function getLastName(): ?string
{
return $this->lastName;
}
public function setLastName(string $lastName): self
{
$this->lastName = $lastName;
return $this;
}
/**
* @return string|null
*/
public function getPassword(): ?string
{
return $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
public function getPlainPassword(): ?string
{
return $this->plainPassword;
}
public function setPlainPassword(string $plainPassword): self
{
$this->plainPassword = $plainPassword;
return $this;
}
public function getIsVerified(): ?bool
{
return $this->isVerified;
}
public function setIsVerified(bool $isVerified): self
{
$this->isVerified = $isVerified;
return $this;
}
/**
* @return Collection<int, SchoolClass>
*/
public function getSchoolClasses(): Collection
{
return $this->schoolClasses;
}
public function addSchoolClass(SchoolClass $schoolClass): self
{
if (!$this->schoolClasses->contains($schoolClass)) {
$this->schoolClasses[] = $schoolClass;
$schoolClass->setSchool($this);
}
return $this;
}
public function removeSchoolClass(SchoolClass $schoolClass): self
{
if ($this->schoolClasses->removeElement($schoolClass)) {
// set the owning side to null (unless already changed)
if ($schoolClass->getSchool() === $this) {
$schoolClass->setSchool(null);
}
}
return $this;
}
/**
* @return Collection<int, SchoolRegistration>
*/
public function getSchoolRegistrations(): Collection
{
return $this->schoolRegistrations;
}
public function addSchoolRegistration(SchoolRegistration $schoolRegistration): self
{
if (!$this->schoolRegistrations->contains($schoolRegistration)) {
$this->schoolRegistrations[] = $schoolRegistration;
$schoolRegistration->setUser($this);
}
return $this;
}
public function removeSchoolRegistration(SchoolRegistration $schoolRegistration): self
{
if ($this->schoolRegistrations->removeElement($schoolRegistration)) {
// set the owning side to null (unless already changed)
if ($schoolRegistration->getUser() === $this) {
$schoolRegistration->setUser(null);
}
}
return $this;
}
}