<?php
namespace App\Entity;
use App\Entity\Traits\TimestampableTrait;
use App\Repository\UserRepository;
use DateTimeImmutable;
use DateTimeInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\EquatableInterface;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* @ORM\Entity(repositoryClass=UserRepository::class)
*/
class User implements UserInterface, PasswordAuthenticatedUserInterface, EquatableInterface
{
use TimestampableTrait;
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $email;
/**
* @ORM\Column(type="string", length=255)
*/
private $password;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $firstname;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $lastname;
/**
* @ORM\Column(type="json")
*/
private $roles = [];
/**
* @ORM\OneToMany(targetEntity=Demand::class, mappedBy="user")
*/
private $demands;
/**
* @ORM\Column(type="date", nullable=true)
*/
private $dateOfBirth;
/**
* @ORM\Column(type="string", length=10, nullable=true)
*/
private $phone;
/**
* @ORM\OneToMany(targetEntity=Company::class, mappedBy="user", orphanRemoval=true)
*/
private $companies;
/**
* @ORM\OneToMany(targetEntity=File::class, mappedBy="user", orphanRemoval=true)
*/
private $files;
/**
* @ORM\OneToMany(targetEntity=Token::class, mappedBy="user", orphanRemoval=true)
*/
private $tokens;
/**
* @ORM\OneToMany(targetEntity=Article::class, mappedBy="user", orphanRemoval=true)
*/
private $articles;
/**
* @ORM\OneToMany(targetEntity=News::class, mappedBy="user", orphanRemoval=true)
*/
private $news;
/**
* @ORM\Column(type="boolean")
*/
private $completed = false;
/**
* @ORM\Column(type="boolean")
*/
private $archived = false;
/**
* @ORM\Column(type="boolean")
*/
private $commitmentCharterValidated = false;
/**
* @ORM\Column(type="datetime_immutable", nullable=true)
*/
private $commitmentCharterValidatedAt;
public function __construct()
{
$this->demands = new ArrayCollection();
$this->companies = new ArrayCollection();
$this->files = new ArrayCollection();
$this->tokens = new ArrayCollection();
$this->articles = new ArrayCollection();
$this->news = 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;
}
public function getPassword(): ?string
{
return $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
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;
}
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;
}
public function getDateOfBirth(): ?DateTimeInterface
{
return $this->dateOfBirth;
}
public function setDateOfBirth(DateTimeInterface $dateOfBirth): self
{
$this->dateOfBirth = $dateOfBirth;
return $this;
}
/**
* @return Collection|Demand[]
*/
public function getDemands(): Collection
{
return $this->demands;
}
public function addDemand(Demand $demand): self
{
if (!$this->demands->contains($demand)) {
$this->demands[] = $demand;
$demand->setUser($this);
}
return $this;
}
public function removeDemand(Demand $demand): self
{
if ($this->demands->removeElement($demand)) {
// set the owning side to null (unless already changed)
if ($demand->getUser() === $this) {
$demand->setUser(null);
}
}
return $this;
}
public function getSalt()
{
return null;
}
public function eraseCredentials()
{
return null;
}
public function getUsername()
{
return $this->getUserIdentifier();
}
public function getUserIdentifier()
{
return $this->email;
}
public function getPhone(): ?string
{
return $this->phone;
}
public function setPhone(string $phone): self
{
$this->phone = $phone;
return $this;
}
public function isEqualTo(UserInterface|User $user): bool
{
// TODO: Implement isEqualTo() method.
return $this->id === $user->getId();
}
/**
* @return Collection|Company[]
*/
public function getCompanies(): Collection
{
return $this->companies;
}
public function addCompany(Company $company): self
{
if (!$this->companies->contains($company)) {
$this->companies[] = $company;
$company->setUser($this);
}
return $this;
}
public function removeCompany(Company $company): self
{
if ($this->companies->removeElement($company)) {
// set the owning side to null (unless already changed)
if ($company->getUser() === $this) {
$company->setUser(null);
}
}
return $this;
}
/**
* @return Collection|File[]
*/
public function getFiles(): Collection
{
return $this->files;
}
public function addFile(File $file): self
{
if (!$this->files->contains($file)) {
$this->files[] = $file;
$file->setUser($this);
}
return $this;
}
public function removeFile(File $file): self
{
if ($this->files->removeElement($file)) {
// set the owning side to null (unless already changed)
if ($file->getUser() === $this) {
$file->setUser(null);
}
}
return $this;
}
/**
* @return Collection|Token[]
*/
public function getTokens(): Collection
{
return $this->tokens;
}
public function addToken(Token $token): self
{
if (!$this->tokens->contains($token)) {
$this->tokens[] = $token;
$token->setUser($this);
}
return $this;
}
public function removeToken(Token $token): self
{
if ($this->tokens->removeElement($token)) {
// set the owning side to null (unless already changed)
if ($token->getUser() === $this) {
$token->setUser(null);
}
}
return $this;
}
/**
* @return Collection|Article[]
*/
public function getArticles(): Collection
{
return $this->articles;
}
public function addArticle(Article $article): self
{
if (!$this->articles->contains($article)) {
$this->articles[] = $article;
$article->setUser($this);
}
return $this;
}
public function removeArticle(Article $article): self
{
if ($this->articles->removeElement($article)) {
// set the owning side to null (unless already changed)
if ($article->getUser() === $this) {
$article->setUser(null);
}
}
return $this;
}
/**
* @return Collection|News[]
*/
public function getNews(): Collection
{
return $this->news;
}
public function addNews(News $news): self
{
if (!$this->news->contains($news)) {
$this->news[] = $news;
$news->setUser($this);
}
return $this;
}
public function removeNews(News $news): self
{
if ($this->news->removeElement($news)) {
// set the owning side to null (unless already changed)
if ($news->getUser() === $this) {
$news->setUser(null);
}
}
return $this;
}
public function isCompleted(): ?bool
{
return $this->completed;
}
public function setCompleted(bool $completed): self
{
$this->completed = $completed;
return $this;
}
public function getArchived(): ?bool
{
return $this->archived;
}
public function setArchived(bool $archived): self
{
$this->archived = $archived;
return $this;
}
public function isCommitmentCharterValidated(): ?bool
{
return $this->commitmentCharterValidated;
}
public function setCommitmentCharterValidated(bool $commitmentCharterValidated): self
{
$this->commitmentCharterValidated = $commitmentCharterValidated;
return $this;
}
public function getCommitmentCharterValidatedAt(): ?DateTimeImmutable
{
return $this->commitmentCharterValidatedAt;
}
public function setCommitmentCharterValidatedAt(?DateTimeImmutable $commitmentCharterValidatedAt): self
{
$this->commitmentCharterValidatedAt = $commitmentCharterValidatedAt;
return $this;
}
}