<?php
namespace App\Entity;
use App\Repository\UserRepository;
use DateTimeImmutable;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Form\Exception\InvalidArgumentException;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Serializer\Annotation\Groups;
#[ORM\Entity(repositoryClass: UserRepository::class)]
#[UniqueEntity(fields: ['email'], message: 'There is already an account with this email')]
#[ORM\HasLifecycleCallbacks]
#[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')]
#[Groups(['user:read', 'membre:read', 'meetParticipant:read','task:read'])]
private ?int $id;
#[ORM\Column(type: 'string', length: 180, unique: true)]
#[Groups(['user:read', 'membre:read', 'meetParticipant:read', 'task:read','documentProjet:read'])]
private ?string $email;
#[ORM\Column(type: 'json')]
#[Groups(['user:read', 'task:read'])]
private array $roles = [];
#[ORM\Column(type: 'string')]
private string $password;
#[ORM\Column(type: 'boolean')]
private bool $isVerified = false;
#[ORM\Column(type: 'boolean')]
private bool $isEnabled = true;
#[ORM\Column(type: 'string', length: 30)]
#[Groups(['user:read'])]
private ?string $gender;
#[ORM\Column(type: 'string', length: 255)]
#[Groups(['user:read', 'membre:read', 'meetParticipant:read', 'task:read'])]
private ?string $firstname;
#[ORM\Column(type: 'string', length: 255)]
#[Groups(['user:read', 'membre:read','meetParticipant:read', 'task:read'])]
private ?string $lastname;
#[ORM\Column(type: 'string', length: 30)]
#[Groups(['user:read', 'membre:read', 'meetParticipant:read','task:read'])]
private ?string $phone;
#[ORM\Column(type: 'datetime_immutable', nullable: true)]
private ?DateTimeImmutable $lastLoginAt;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private ?string $createdBy;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private ?string $updatedBy;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private ?string $address;
#[ORM\Column(type: 'string', length: 45, nullable: true)]
private ?string $district;
/*
#[ORM\ManyToOne(targetEntity: Municipality::class, inversedBy: 'users')]
#[ORM\JoinColumn(nullable: true)]
private mixed $municipality;
*/
#[ORM\ManyToOne]
#[ORM\JoinColumn(nullable: true)]
private ?Municipality $municipality = null;
#[ORM\ManyToOne]
#[Groups(['user:read', 'membre:read', 'meetParticipant:read'])]
private ?Structure $structure = null;
#[ORM\Column]
private ?DateTimeImmutable $createdAt = null;
#[ORM\Column(nullable: true)]
private ?DateTimeImmutable $updatedAt = null;
#[ORM\ManyToOne(inversedBy: 'user')]
private ?Sectoral $sectoral = null;
#[ORM\Column(length: 255, nullable: true)]
#[Groups(['user:read', 'membre:read', 'meetParticipant:read'])]
private ?string $fonction = null;
private string $plainPassword;
#[ORM\ManyToMany(targetEntity: Decision::class, mappedBy: 'monitoringOfficer')]
private Collection $decisions;
#[ORM\Column(length: 255, nullable: true)]
#[Groups(['user:read', 'membre:read', 'meetParticipant:read'])]
private ?string $avatar = null;
#[ORM\Column(nullable: true)]
private ?\DateTimeImmutable $mailSentAt = null;
#[ORM\OneToMany(mappedBy: 'participants', targetEntity: MeetParticipant::class)]
private Collection $meetParticipants;
#[ORM\OneToMany(mappedBy: 'gestionnaire', targetEntity: Projet::class)]
private Collection $projets;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: ProjetMembre::class)]
private Collection $projetMembres;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: TaskAssign::class)]
private Collection $taskAssigns;
#[ORM\OneToMany(mappedBy: 'author', targetEntity: Comment::class)]
private Collection $comments;
#[ORM\OneToMany(mappedBy: 'createdBy', targetEntity: Bailleur::class)]
private Collection $bailleurs;
#[ORM\OneToMany(mappedBy: 'createdBy', targetEntity: CategorieProjet::class)]
private Collection $categorieProjets;
#[ORM\OneToMany(mappedBy: 'createdBy', targetEntity: ModeFinance::class)]
private Collection $modeFinances;
#[ORM\OneToMany(mappedBy: 'createdBy', targetEntity: Priority::class)]
private Collection $priorities;
#[ORM\OneToMany(mappedBy: 'createdBy', targetEntity: Structure::class)]
private Collection $structures;
#[ORM\OneToMany(mappedBy: 'author', targetEntity: RateOfProgress::class)]
private Collection $rateOfProgress;
#[ORM\OneToMany(mappedBy: 'author', targetEntity: RejectEvaluation::class)]
private Collection $rejectEvaluations;
#[ORM\OneToMany(mappedBy: 'author', targetEntity: Document::class)]
private Collection $documents;
#[ORM\OneToMany(mappedBy: 'createdBy', targetEntity: Pao::class)]
private Collection $paos;
#[ORM\OneToMany(mappedBy: 'createdBy', targetEntity: Objectif::class)]
private Collection $objectifs;
#[ORM\OneToMany(mappedBy: 'createdBy', targetEntity: Activity::class)]
private Collection $activities;
#[ORM\OneToMany(mappedBy: 'createdBy', targetEntity: Evaluation::class)]
private Collection $evaluations;
#[ORM\OneToMany(mappedBy: 'createdBy', targetEntity: EvaluationCritere::class)]
private Collection $evaluationCriteres;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: Meeting::class)]
private Collection $meetings;
public function __construct()
{
$this->createdAt = new DateTimeImmutable();
$this->updatedAt = new DateTimeImmutable();
$this->decisions = new ArrayCollection();
$this->meetParticipants = new ArrayCollection();
$this->projets = new ArrayCollection();
$this->projetMembres = new ArrayCollection();
$this->taskAssigns = new ArrayCollection();
$this->comments = new ArrayCollection();
$this->bailleurs = new ArrayCollection();
$this->categorieProjets = new ArrayCollection();
$this->modeFinances = new ArrayCollection();
$this->priorities = new ArrayCollection();
$this->structures = new ArrayCollection();
$this->rateOfProgress = new ArrayCollection();
$this->rejectEvaluations = new ArrayCollection();
$this->documents = new ArrayCollection();
$this->paos = new ArrayCollection();
$this->objectifs = new ArrayCollection();
$this->activities = new ArrayCollection();
$this->evaluations = new ArrayCollection();
$this->evaluationCriteres = new ArrayCollection();
$this->meetings = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getMeetings(): Collection
{
return $this->meetings;
}
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
{
foreach ($roles as $role)
{
if(!str_starts_with($role, 'ROLE_') ||
!in_array($role, ['ROLE_AGENT_MANAGER', 'ROLE_FONCTIONNAIRE', 'ROLE_MANAGER', 'ROLE_SUPERVISEUR']))
{
throw new InvalidArgumentException("Le rôle doit être 'ROLE_FONCTIONNAIRE' ou 'ROLE_MANAGER' ou 'ROLE_SUPERVISEUR' ou commencé par ROLE_");
}
}
$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->isVerified;
}
public function setIsVerified(bool $isVerified): self
{
$this->isVerified = $isVerified;
return $this;
}
public function isIsEnabled(): ?bool
{
return $this->isEnabled;
}
public function setIsEnabled(bool $isEnabled): self
{
$this->isEnabled = $isEnabled;
return $this;
}
public function getGender(): ?string
{
return $this->gender;
}
public function setGender(string $gender): self
{
$this->gender = $gender;
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 getPhone(): ?string
{
return $this->phone;
}
public function setPhone(string $phone): self
{
$this->phone = $phone;
return $this;
}
public function getLastLoginAt(): ?DateTimeImmutable
{
return $this->lastLoginAt;
}
public function setLastLoginAt(?DateTimeImmutable $lastLoginAt): self
{
$this->lastLoginAt = $lastLoginAt;
return $this;
}
public function getCreatedBy(): ?string
{
return $this->createdBy;
}
public function setCreatedBy(?string $createdBy): self
{
$this->createdBy = $createdBy;
return $this;
}
public function getUpdatedBy(): ?string
{
return $this->updatedBy;
}
public function setUpdatedBy(?string $updatedBy): self
{
$this->updatedBy = $updatedBy;
return $this;
}
public function isIsVerified(): ?bool
{
return $this->isVerified;
}
public function getAddress(): ?string
{
return $this->address;
}
public function setAddress(string $address): self
{
$this->address = $address;
return $this;
}
public function getDistrict(): ?string
{
return $this->district;
}
public function setDistrict(?string $district): self
{
$this->district = $district;
return $this;
}
/**
* @return mixed
*/
public function getMunicipality(): mixed
{
return $this->municipality;
}
/**
* @param mixed $municipality
*/
public function setMunicipality($municipality)
{
$this->municipality = $municipality;
}
public function getStructure(): ?Structure
{
return $this->structure;
}
public function setStructure(?Structure $structure): self
{
$this->structure = $structure;
return $this;
}
public function getCreatedAt(): ?DateTimeImmutable
{
return $this->createdAt;
}
public function setCreatedAt(DateTimeImmutable $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getUpdatedAt(): ?DateTimeImmutable
{
return $this->updatedAt;
}
public function setUpdatedAt(?DateTimeImmutable $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
public function getSectoral(): ?Sectoral
{
return $this->sectoral;
}
public function setSectoral(?Sectoral $sectoral): self
{
$this->sectoral = $sectoral;
return $this;
}
public function getFonction(): ?string
{
return $this->fonction;
}
public function setFonction(?string $fonction): self
{
$this->fonction = $fonction;
return $this;
}
/**
* @return string
*/
public function getPlainPassword(): string
{
return $this->plainPassword;
}
/**
* @param string $plainPassword
*/
public function setPlainPassword(string $plainPassword): void
{
$this->plainPassword = $plainPassword;
}
/**
* @return Collection<int, Decision>
*/
public function getDecisions(): Collection
{
return $this->decisions;
}
public function addDecision(Decision $decision): self
{
if (!$this->decisions->contains($decision)) {
$this->decisions->add($decision);
$decision->addMonitoringOfficer($this);
}
return $this;
}
public function removeDecision(Decision $decision): self
{
if ($this->decisions->removeElement($decision)) {
$decision->removeMonitoringOfficer($this);
}
return $this;
}
public function getAvatar(): ?string
{
return $this->avatar;
}
public function setAvatar(?string $avatar): self
{
$this->avatar = $avatar;
return $this;
}
public function getMailSentAt(): ?\DateTimeImmutable
{
return $this->mailSentAt;
}
public function setMailSentAt(?\DateTimeImmutable $mailSentAt): self
{
$this->mailSentAt = $mailSentAt;
return $this;
}
/**
* @return Collection<int, MeetParticipant>
*/
public function getMeetParticipants(): Collection
{
return $this->meetParticipants;
}
public function addMeetParticipant(MeetParticipant $meetParticipant): self
{
if (!$this->meetParticipants->contains($meetParticipant)) {
$this->meetParticipants->add($meetParticipant);
$meetParticipant->setParticipants($this);
}
return $this;
}
public function removeMeetParticipant(MeetParticipant $meetParticipant): self
{
if ($this->meetParticipants->removeElement($meetParticipant)) {
// set the owning side to null (unless already changed)
if ($meetParticipant->getParticipants() === $this) {
$meetParticipant->setParticipants(null);
}
}
return $this;
}
public function __toString(): string
{
return $this->firstname." ".$this->lastname." (".$this->phone.")";
}
/**
* @return Collection<int, Projet>
*/
public function getProjets(): Collection
{
return $this->projets;
}
public function addProjet(Projet $projet): self
{
if (!$this->projets->contains($projet)) {
$this->projets->add($projet);
$projet->setGestionnaire($this);
}
return $this;
}
public function removeProjet(Projet $projet): self
{
if ($this->projets->removeElement($projet)) {
// set the owning side to null (unless already changed)
if ($projet->getGestionnaire() === $this) {
$projet->setGestionnaire(null);
}
}
return $this;
}
/**
* @return Collection<int, ProjetMembre>
*/
public function getProjetMembres(): Collection
{
return $this->projetMembres;
}
public function addProjetMembre(ProjetMembre $projetMembre): self
{
if (!$this->projetMembres->contains($projetMembre)) {
$this->projetMembres->add($projetMembre);
$projetMembre->setUser($this);
}
return $this;
}
public function removeProjetMembre(ProjetMembre $projetMembre): self
{
if ($this->projetMembres->removeElement($projetMembre)) {
// set the owning side to null (unless already changed)
if ($projetMembre->getUser() === $this) {
$projetMembre->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, TaskAssign>
*/
public function getTaskAssigns(): Collection
{
return $this->taskAssigns;
}
public function addTaskAssign(TaskAssign $taskAssign): self
{
if (!$this->taskAssigns->contains($taskAssign)) {
$this->taskAssigns->add($taskAssign);
$taskAssign->setUser($this);
}
return $this;
}
public function removeTaskAssign(TaskAssign $taskAssign): self
{
if ($this->taskAssigns->removeElement($taskAssign)) {
// set the owning side to null (unless already changed)
if ($taskAssign->getUser() === $this) {
$taskAssign->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, Comment>
*/
public function getComments(): Collection
{
return $this->comments;
}
public function addComment(Comment $comment): static
{
if (!$this->comments->contains($comment)) {
$this->comments->add($comment);
$comment->setAuthor($this);
}
return $this;
}
public function removeComment(Comment $comment): static
{
if ($this->comments->removeElement($comment)) {
// set the owning side to null (unless already changed)
if ($comment->getAuthor() === $this) {
$comment->setAuthor(null);
}
}
return $this;
}
/**
* @return Collection<int, Bailleur>
*/
public function getBailleurs(): Collection
{
return $this->bailleurs;
}
public function addBailleur(Bailleur $bailleur): static
{
if (!$this->bailleurs->contains($bailleur)) {
$this->bailleurs->add($bailleur);
$bailleur->setCreatedBy($this);
}
return $this;
}
public function removeBailleur(Bailleur $bailleur): static
{
if ($this->bailleurs->removeElement($bailleur)) {
// set the owning side to null (unless already changed)
if ($bailleur->getCreatedBy() === $this) {
$bailleur->setCreatedBy(null);
}
}
return $this;
}
/**
* @return Collection<int, CategorieProjet>
*/
public function getCategorieProjets(): Collection
{
return $this->categorieProjets;
}
public function addCategorieProjet(CategorieProjet $categorieProjet): static
{
if (!$this->categorieProjets->contains($categorieProjet)) {
$this->categorieProjets->add($categorieProjet);
$categorieProjet->setCreatedBy($this);
}
return $this;
}
public function removeCategorieProjet(CategorieProjet $categorieProjet): static
{
if ($this->categorieProjets->removeElement($categorieProjet)) {
// set the owning side to null (unless already changed)
if ($categorieProjet->getCreatedBy() === $this) {
$categorieProjet->setCreatedBy(null);
}
}
return $this;
}
/**
* @return Collection<int, ModeFinance>
*/
public function getModeFinances(): Collection
{
return $this->modeFinances;
}
public function addModeFinance(ModeFinance $modeFinance): static
{
if (!$this->modeFinances->contains($modeFinance)) {
$this->modeFinances->add($modeFinance);
$modeFinance->setCreatedBy($this);
}
return $this;
}
public function removeModeFinance(ModeFinance $modeFinance): static
{
if ($this->modeFinances->removeElement($modeFinance)) {
// set the owning side to null (unless already changed)
if ($modeFinance->getCreatedBy() === $this) {
$modeFinance->setCreatedBy(null);
}
}
return $this;
}
/**
* @return Collection<int, Priority>
*/
public function getPriorities(): Collection
{
return $this->priorities;
}
public function addPriority(Priority $priority): static
{
if (!$this->priorities->contains($priority)) {
$this->priorities->add($priority);
$priority->setCreatedBy($this);
}
return $this;
}
public function removePriority(Priority $priority): static
{
if ($this->priorities->removeElement($priority)) {
// set the owning side to null (unless already changed)
if ($priority->getCreatedBy() === $this) {
$priority->setCreatedBy(null);
}
}
return $this;
}
/**
* @return Collection<int, Structure>
*/
public function getStructures(): Collection
{
return $this->structures;
}
public function addStructure(Structure $structure): static
{
if (!$this->structures->contains($structure)) {
$this->structures->add($structure);
$structure->setCreatedBy($this);
}
return $this;
}
public function removeStructure(Structure $structure): static
{
if ($this->structures->removeElement($structure)) {
// set the owning side to null (unless already changed)
if ($structure->getCreatedBy() === $this) {
$structure->setCreatedBy(null);
}
}
return $this;
}
/**
* @return Collection<int, RateOfProgress>
*/
public function getRateOfProgress(): Collection
{
return $this->rateOfProgress;
}
public function addRateOfProgress(RateOfProgress $rateOfProgress): static
{
if (!$this->rateOfProgress->contains($rateOfProgress)) {
$this->rateOfProgress->add($rateOfProgress);
$rateOfProgress->setAuthor($this);
}
return $this;
}
public function removeRateOfProgress(RateOfProgress $rateOfProgress): static
{
if ($this->rateOfProgress->removeElement($rateOfProgress)) {
// set the owning side to null (unless already changed)
if ($rateOfProgress->getAuthor() === $this) {
$rateOfProgress->setAuthor(null);
}
}
return $this;
}
/**
* @return Collection<int, RejectEvaluation>
*/
public function getRejectEvaluations(): Collection
{
return $this->rejectEvaluations;
}
public function addRejectEvaluation(RejectEvaluation $rejectEvaluation): static
{
if (!$this->rejectEvaluations->contains($rejectEvaluation)) {
$this->rejectEvaluations->add($rejectEvaluation);
$rejectEvaluation->setAuthor($this);
}
return $this;
}
public function removeRejectEvaluation(RejectEvaluation $rejectEvaluation): static
{
if ($this->rejectEvaluations->removeElement($rejectEvaluation)) {
// set the owning side to null (unless already changed)
if ($rejectEvaluation->getAuthor() === $this) {
$rejectEvaluation->setAuthor(null);
}
}
return $this;
}
/**
* @return Collection<int, Document>
*/
public function getDocuments(): Collection
{
return $this->documents;
}
public function addDocument(Document $document): static
{
if (!$this->documents->contains($document)) {
$this->documents->add($document);
$document->setAuthor($this);
}
return $this;
}
public function removeDocument(Document $document): static
{
if ($this->documents->removeElement($document)) {
// set the owning side to null (unless already changed)
if ($document->getAuthor() === $this) {
$document->setAuthor(null);
}
}
return $this;
}
/**
* @return Collection<int, Pao>
*/
public function getPaos(): Collection
{
return $this->paos;
}
public function addPao(Pao $pao): static
{
if (!$this->paos->contains($pao)) {
$this->paos->add($pao);
$pao->setCreatedBy($this);
}
return $this;
}
public function removePao(Pao $pao): static
{
if ($this->paos->removeElement($pao)) {
// set the owning side to null (unless already changed)
if ($pao->getCreatedBy() === $this) {
$pao->setCreatedBy(null);
}
}
return $this;
}
/**
* @return Collection<int, Objectif>
*/
public function getObjectifs(): Collection
{
return $this->objectifs;
}
public function addObjectif(Objectif $objectif): static
{
if (!$this->objectifs->contains($objectif)) {
$this->objectifs->add($objectif);
$objectif->setCreatedBy($this);
}
return $this;
}
public function removeObjectif(Objectif $objectif): static
{
if ($this->objectifs->removeElement($objectif)) {
// set the owning side to null (unless already changed)
if ($objectif->getCreatedBy() === $this) {
$objectif->setCreatedBy(null);
}
}
return $this;
}
/**
* @return Collection<int, Activity>
*/
public function getActivities(): Collection
{
return $this->activities;
}
public function addActivity(Activity $activity): static
{
if (!$this->activities->contains($activity)) {
$this->activities->add($activity);
$activity->setCreatedBy($this);
}
return $this;
}
public function removeActivity(Activity $activity): static
{
if ($this->activities->removeElement($activity)) {
// set the owning side to null (unless already changed)
if ($activity->getCreatedBy() === $this) {
$activity->setCreatedBy(null);
}
}
return $this;
}
/**
* @return Collection<int, Evaluation>
*/
public function getEvaluations(): Collection
{
return $this->evaluations;
}
public function addEvaluation(Evaluation $evaluation): static
{
if (!$this->evaluations->contains($evaluation)) {
$this->evaluations->add($evaluation);
$evaluation->setCreatedBy($this);
}
return $this;
}
public function removeEvaluation(Evaluation $evaluation): static
{
if ($this->evaluations->removeElement($evaluation)) {
// set the owning side to null (unless already changed)
if ($evaluation->getCreatedBy() === $this) {
$evaluation->setCreatedBy(null);
}
}
return $this;
}
/**
* @return Collection<int, EvaluationCritere>
*/
public function getEvaluationCriteres(): Collection
{
return $this->evaluationCriteres;
}
public function addEvaluationCritere(EvaluationCritere $evaluationCritere): static
{
if (!$this->evaluationCriteres->contains($evaluationCritere)) {
$this->evaluationCriteres->add($evaluationCritere);
$evaluationCritere->setCreatedBy($this);
}
return $this;
}
public function removeEvaluationCritere(EvaluationCritere $evaluationCritere): static
{
if ($this->evaluationCriteres->removeElement($evaluationCritere)) {
// set the owning side to null (unless already changed)
if ($evaluationCritere->getCreatedBy() === $this) {
$evaluationCritere->setCreatedBy(null);
}
}
return $this;
}
// Méthode pour ajouter une réunion
public function addMeeting(Meeting $meeting): void
{
if (!$this->meetings->contains($meeting)) {
$this->meetings[] = $meeting;
$meeting->setUser($this); // Associer l'utilisateur à la réunion
}
}
// Méthode pour supprimer une réunion
public function removeMeeting(Meeting $meeting): void
{
if ($this->meetings->contains($meeting)) {
$this->meetings->removeElement($meeting);
// Dissocier l'utilisateur de la réunion
if ($meeting->getUser() === $this) {
$meeting->setUser(null);
}
}
}
}