<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
#[ORM\Entity(repositoryClass: \App\Repository\UserRepository::class)]
class User implements UserInterface, PasswordAuthenticatedUserInterface, \Stringable
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private ?int $id = 0;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private ?string $email= null;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private ?string $first_name= null;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private ?string $last_name= null;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private ?string $phone_number= null;
#[ORM\Column(type: 'datetime', nullable: true)]
private mixed $created_at;
#[ORM\Column(type: 'datetime', nullable: true)]
private mixed $updated_at;
#[ORM\Column(type: 'integer', nullable: true)]
private int $term_version;
#[ORM\Column(type: 'integer', nullable: true)]
private mixed $font_size;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private ?string $font_family= null;
#[ORM\Column(type: 'integer', nullable: true)]
private mixed $dark_mode = null;
#[ORM\OneToMany(targetEntity: \App\Entity\Post::class, mappedBy: 'created_by')]
private mixed $created_posts;
#[ORM\OneToMany(targetEntity: \App\Entity\Post::class, mappedBy: 'updated_by')]
private mixed $updated_posts;
#[ORM\Column(name: 'password', type: 'string', length: 255, nullable: true)]
private ?string $password = null;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private ?string $role= null;
#[ORM\ManyToOne(targetEntity: \App\Entity\TargetPublic::class, inversedBy: 'users')]
#[ORM\JoinColumn(onDelete: 'SET NULL')]
private mixed $public;
#[ORM\OneToMany(targetEntity: \App\Entity\Post::class, mappedBy: 'edit_user', cascade: ['remove'])]
private mixed $posts;
#[ORM\OneToMany(targetEntity: \App\Entity\PostLog::class, mappedBy: 'user', cascade: ['remove'])]
private mixed $postLogs;
#[ORM\OneToMany(targetEntity: \App\Entity\AuthToken::class, mappedBy: 'user', cascade: ['remove'])]
private mixed $tokens;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private ?string $token_reset= null;
#[ORM\Column(type: 'boolean')]
private ?bool $active = true;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private ?string $token_activation= null;
#[ORM\ManyToMany(targetEntity: \App\Entity\Post::class, inversedBy: 'users')]
private mixed $favoris;
#[ORM\ManyToMany(targetEntity: \App\Entity\Topic::class, inversedBy: 'users')]
private mixed $thematiques;
#[ORM\ManyToMany(targetEntity: \App\Entity\Territory::class, inversedBy: 'users')]
private mixed $territoires;
#[ORM\Column(type: 'boolean', nullable: true)]
private ?bool $private_posts_only;
#[ORM\OneToMany(targetEntity: Incident::class, mappedBy: 'user')]
private mixed $incidents;
public function __construct()
{
$this->created_posts = new ArrayCollection();
$this->updated_posts = new ArrayCollection();
$this->posts = new ArrayCollection();
$this->postLogs = new ArrayCollection();
$this->tokens = new ArrayCollection();
$this->favoris = new ArrayCollection();
$this->thematiques = new ArrayCollection();
$this->territoires = new ArrayCollection();
$this->incidents = new ArrayCollection();
}
public function getPassword(): ?string
{
return $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
public function getRoles(): array
{
if ($this->role == 'admin') {
return ['ROLE_ADMIN'];
} else if ($this->role == 'superadmin') {
return ['ROLE_SUPERADMIN'];
} else if ($this->role == 'lenordadmin') {
return ['ROLE_LENORDADMIN'];
} else if ($this->role == 'redacteur') {
return ['ROLE_REDACTEUR'];
} else if ($this->role == 'lecteur') {
return ["ROLE_LECTEUR"];
} else if ($this->role == 'agent') {
return ["ROLE_AGENT"];
} else if ($this->role == 'public') {
return ["ROLE_PUBLIC"];
} else if ($this->role == 'presse') {
return ["ROLE_PRESSE"];
} else if ($this->role == 'vip') {
return ["ROLE_VIP"];
} else if ($this->role == 'ged') {
return ["ROLE_GED"];
}
return ['ROLE_USER'];
}
public function getSalt(): ?string
{
return null;
}
public function eraseCredentials(): void
{
}
public function equals(UserInterface $user): bool
{
return $user->getEmail() == $this->getEmail();
}
public function getUsername(): ?string
{
return $this->email;
}
/**
* The public representation of the user (e.g. a username, an email address, etc.)
*
* @see UserInterface
*/
public function getUserIdentifier(): string
{
return (string) $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;
}
public function getFontSize(): ?int
{
return $this->font_size;
}
public function setFontSize(?int $font_size): self
{
$this->font_size = $font_size;
return $this;
}
public function getFontFamily(): ?string
{
return $this->font_family;
}
public function setFontFamily(?string $font_family): self
{
$this->font_family = $font_family;
return $this;
}
public function getDarkMode(): ?int
{
return $this->dark_mode;
}
public function setDarkMode(?int $dark_mode): self
{
$this->dark_mode = $dark_mode;
return $this;
}
public function getFirstName(): ?string
{
return $this->first_name;
}
public function setFirstName(?string $first_name): self
{
$this->first_name = $first_name;
return $this;
}
public function getLastName(): ?string
{
return $this->last_name;
}
public function setLastName(?string $last_name): self
{
$this->last_name = $last_name;
return $this;
}
public function getPhoneNumber(): ?string
{
return $this->phone_number;
}
public function setPhoneNumber(?string $phone_number): self
{
$this->phone_number = $phone_number;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->created_at;
}
public function setCreatedAt(?\DateTimeInterface $created_at): self
{
$this->created_at = $created_at;
return $this;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updated_at;
}
public function setUpdatedAt(?\DateTimeInterface $updated_at): self
{
$this->updated_at = $updated_at;
return $this;
}
public function getTermVersion(): ?int
{
return $this->term_version;
}
public function setTermVersion(?int $term_version): self
{
$this->term_version = $term_version;
return $this;
}
/**
* @return Collection|Post[]
*/
public function getCreatedPosts(): Collection
{
return $this->created_posts;
}
public function addCreatedPost(Post $createdPost): self
{
if (!$this->created_posts->contains($createdPost)) {
$this->created_posts[] = $createdPost;
$createdPost->setCreatedBy($this);
}
return $this;
}
public function removeCreatedPost(Post $createdPost): self
{
if ($this->created_posts->contains($createdPost)) {
$this->created_posts->removeElement($createdPost);
// set the owning side to null (unless already changed)
if ($createdPost->getCreatedBy() === $this) {
$createdPost->setCreatedBy(null);
}
}
return $this;
}
/**
* @return Collection|Post[]
*/
public function getUpdatedPosts(): Collection
{
return $this->updated_posts;
}
public function addUpdatedPost(Post $updatedPost): self
{
if (!$this->updated_posts->contains($updatedPost)) {
$this->updated_posts[] = $updatedPost;
$updatedPost->setUpdatedBy($this);
}
return $this;
}
public function removeUpdatedPost(Post $updatedPost): self
{
if ($this->updated_posts->contains($updatedPost)) {
$this->updated_posts->removeElement($updatedPost);
// set the owning side to null (unless already changed)
if ($updatedPost->getUpdatedBy() === $this) {
$updatedPost->setUpdatedBy(null);
}
}
return $this;
}
public function getRole(): ?string
{
return $this->role;
}
public function setRole(?string $role): self
{
$this->role = $role;
return $this;
}
public function __toString(): string
{
return $this->first_name . ' ' . $this->last_name;
}
public function getPublic(): ?TargetPublic
{
return $this->public;
}
public function setPublic(?TargetPublic $public): self
{
$this->public = $public;
return $this;
}
/**
* @return Collection|Post[]
*/
public function getPosts(): Collection
{
return $this->posts;
}
public function addPost(Post $post): self
{
if (!$this->posts->contains($post)) {
$this->posts[] = $post;
$post->setEditUser($this);
}
return $this;
}
public function removePost(Post $post): self
{
if ($this->posts->contains($post)) {
$this->posts->removeElement($post);
// set the owning side to null (unless already changed)
if ($post->getEditUser() === $this) {
$post->setEditUser(null);
}
}
return $this;
}
/**
* @return Collection|PostLog[]
*/
public function getPostLogs(): Collection
{
return $this->postLogs;
}
public function addPostLog(PostLog $postLog): self
{
if (!$this->postLogs->contains($postLog)) {
$this->postLogs[] = $postLog;
$postLog->setUser($this);
}
return $this;
}
public function removePostLog(PostLog $postLog): self
{
if ($this->postLogs->contains($postLog)) {
$this->postLogs->removeElement($postLog);
// set the owning side to null (unless already changed)
if ($postLog->getUser() === $this) {
$postLog->setUser(null);
}
}
return $this;
}
public function getTokenReset(): ?string
{
return $this->token_reset;
}
public function setTokenReset(?string $token_reset): self
{
$this->token_reset = $token_reset;
return $this;
}
public function getActive(): ?bool
{
return $this->active;
}
public function setActive(bool $active): self
{
$this->active = $active;
return $this;
}
public function getPrivatePostsOnly(): ?bool
{
return $this->private_posts_only;
}
public function setPrivatePostsOnly(bool $private_posts_only): self
{
$this->private_posts_only = $private_posts_only;
return $this;
}
public function getTokenActivation(): ?string
{
return $this->token_activation;
}
public function setTokenActivation(?string $token_activation): self
{
$this->token_activation = $token_activation;
return $this;
}
/**
* @return Collection|Post[]
*/
public function getFavoris(): Collection
{
return $this->favoris;
}
public function addFavori(Post $favori): self
{
if (!$this->favoris->contains($favori)) {
$this->favoris[] = $favori;
}
return $this;
}
public function removeFavori(Post $favori): self
{
if ($this->favoris->contains($favori)) {
$this->favoris->removeElement($favori);
}
return $this;
}
/**
* @return Collection|Topic[]
*/
public function getThematiques(): Collection
{
return $this->thematiques;
}
public function addThematique(Topic $thematique): self
{
if (!$this->thematiques->contains($thematique)) {
$this->thematiques[] = $thematique;
}
return $this;
}
public function removeThematique(Topic $thematique): self
{
if ($this->thematiques->contains($thematique)) {
$this->thematiques->removeElement($thematique);
}
return $this;
}
/**
* @return Collection|Territory[]
*/
public function getTerritoires(): Collection
{
return $this->territoires;
}
public function addTerritoire(Territory $territoire): self
{
if (!$this->territoires->contains($territoire)) {
$this->territoires[] = $territoire;
}
return $this;
}
public function removeTerritoire(Territory $territoire): self
{
if ($this->territoires->contains($territoire)) {
$this->territoires->removeElement($territoire);
}
return $this;
}
/**
* @return Collection|PostLog[]
*/
public function getTokens(): Collection
{
return $this->tokens;
}
public function addToken(AuthToken $postLog): self
{
if (!$this->tokens->contains($postLog)) {
$this->tokens[] = $postLog;
$postLog->setUser($this);
}
return $this;
}
public function removeToken(AuthToken $postLog): self
{
if ($this->tokens->contains($postLog)) {
$this->tokens->removeElement($postLog);
// set the owning side to null (unless already changed)
if ($postLog->getUser() === $this) {
$postLog->setUser(null);
}
}
return $this;
}
/**
* @return Collection|Incident[]
*/
public function getIncidents(): Collection
{
return $this->incidents;
}
public function addIncident(Incident $incident): self
{
if (!$this->incidents->contains($incident)) {
$this->incidents[] = $incident;
$incident->setUser($this);
}
return $this;
}
public function removeIncident(Incident $incident): self
{
if ($this->incidents->removeElement($incident)) {
// set the owning side to null (unless already changed)
if ($incident->getUser() === $this) {
$incident->setUser(null);
}
}
return $this;
}
}