<?php
namespace App\Entity;
use App\Entity\Dae;
use App\Entity\Autres;
use App\Entity\Adresse;
use App\Entity\Commande;
use App\Entity\Entreprise;
use App\Entity\Partenaire;
use App\Entity\Particulier;
use App\Entity\AgentInterne;
use Doctrine\ORM\Mapping as ORM;
use App\Repository\UserRepository;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
#[ORM\Entity(repositoryClass: UserRepository::class)]
#[ORM\InheritanceType(value: 'JOINED')]
#[ORM\DiscriminatorColumn(name: 'type', type: 'string')]
#[ORM\DiscriminatorMap(value: ['User' => User::class,'Particulier' => Particulier::class, 'Partenaire' => Partenaire::class, 'Entreprise' => Entreprise::class, 'Dae' => Dae::class, 'ChargeAssistance' => ChargeAssistance::class, 'AgentInterne' => AgentInterne::class,'Autres' => Autres::class])]
#[UniqueEntity(fields: ['email'], message: 'There is already an account with this email', entityClass: User::class)]
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
public const PARTIICULIER = 'Particulier';
public const ENTREPRISE = 'Entreprise';
public const AUTRES = 'Autres';
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
#[ORM\Column(type: 'string', length: 255, unique: true)]
#[Assert\Email]
private $email;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $username;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $password;
#[ORM\Column(type: 'json', length: 255)]
private $roles = [];
#[ORM\Column(type: 'boolean')]
private $isVerified = false;
#[ORM\ManyToMany(targetEntity: GroupePermission::class, inversedBy: 'users')]
private $group_permission;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: Adresse::class, cascade: ['persist', 'remove'])]
private $adresses;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: Commande::class, cascade: ['persist', 'remove'])]
private $commande;
#[ORM\Column(type: 'string', length: 1000, nullable: true)]
private $TokenReset;
#[ORM\Column(type: 'boolean')]
private $isDeleted = false;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: QuizReponse::class)]
private Collection $quizReponses;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: Ressources::class, cascade: ['persist', 'remove'])]
private Collection $ressources;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: DocDemandeService::class, cascade: ['persist', 'remove'])]
private Collection $docDemande;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: InscriptionSessionFormation::class, cascade: ['persist', 'remove'])]
private Collection $inscriptionSessionFormations;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: ForumReponse::class, cascade: ['persist', 'remove'])]
private ?Collection $forumResponses;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: Sujetforum::class, cascade: ['persist', 'remove'])]
private ?Collection $sujetForums;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: UserFicheSatisfaction::class, orphanRemoval: true)]
private Collection $userFicheSatisfactions;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: Notification::class)]
private Collection $notifications;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: DemandeService::class)]
private Collection $demandeServices;
public function __construct()
{
$this->group_permission = new ArrayCollection();
$this->adresses = new ArrayCollection();
$this->quizReponses = new ArrayCollection();
$this->ressources = new ArrayCollection();
$this->forumResponses = new ArrayCollection();
$this->sujetForums = new ArrayCollection();
$this->inscriptionSessionFormations = new ArrayCollection();
$this->commande = new ArrayCollection();
$this->docDemande = new ArrayCollection();
$this->userFicheSatisfactions = new ArrayCollection();
$this->notifications = new ArrayCollection();
$this->demandeServices = 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 getUsername(): ?string
{
return $this->username;
}
public function setUsername(string $username): self
{
$this->username = $username;
return $this;
}
public function getPassword(): ?string
{
return $this->password;
}
public function setPassword(?string $password): self
{
$this->password = $password;
return $this;
}
/**
* 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 getRoles(): array
{
$roles = [];
// guarantee every user at least has ROLE_USER$roles[] = 'ROLE_USER';
if ($this->isVerified() == 1) {
$roles = $this->roles;
return array_unique($roles);
}
//dd($roles);
return $roles;
}
public function setRoles(array $roles): self
{
$this->roles = $roles;
return $this;
}
/**
* Returning a salt is only needed, if you are not using a modern
* hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
*
* @see UserInterface
*/
public function getSalt(): ?string
{
return null;
}
/**
* @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 getTokenReset(): ?string
{
return $this->TokenReset;
}
public function setTokenReset(?string $TokenReset): self
{
$this->TokenReset = $TokenReset;
return $this;
}
public function isDeleted(): bool
{
return $this->isDeleted;
}
public function setIsDeleted(bool $isDeleted): void
{
$this->isDeleted = $isDeleted;
}
/**
* @return Collection<int, GroupePermission>
*/
public function getGroupPermission(): Collection
{
return $this->group_permission;
}
public function addGroupPermission(GroupePermission $groupPermission): self
{
if (!$this->group_permission->contains($groupPermission)) {
$this->group_permission[] = $groupPermission;
}
return $this;
}
public function removeGroupPermission(GroupePermission $groupPermission): self
{
$this->group_permission->removeElement($groupPermission);
return $this;
}
/**
* @return Collection<int, Adresse>
*/
public function getAdresses(): Collection
{
return $this->adresses;
}
public function addAdress(Adresse $adress): self
{
if (!$this->adresses->contains($adress)) {
$this->adresses[] = $adress;
$adress->setUser($this);
}
return $this;
}
public function removeAdress(Adresse $adress): self
{
if ($this->adresses->removeElement($adress)) {
// set the owning side to null (unless already changed)
if ($adress->getUser() === $this) {
$adress->setUser(null);
}
}
return $this;
}
public function isIsVerified(): ?bool
{
return $this->isVerified;
}
public function __toString()
{
return $this->username ?? $this->email ?? '';
}
/**
* @return Collection<int, QuizReponse>
*/
public function getQuizReponses(): Collection
{
return $this->quizReponses;
}
public function addQuizReponse(QuizReponse $quizReponse): self
{
if (!$this->quizReponses->contains($quizReponse)) {
$this->quizReponses->add($quizReponse);
$quizReponse->setUser($this);
}
return $this;
}
public function removeQuizReponse(QuizReponse $quizReponse): self
{
if ($this->quizReponses->removeElement($quizReponse)) {
// set the owning side to null (unless already changed)
if ($quizReponse->getUser() === $this) {
$quizReponse->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, Ressources>
*/
public function getRessources(): Collection
{
return $this->ressources;
}
public function addRessource(Ressources $ressource): self
{
if (!$this->ressources->contains($ressource)) {
$this->ressources->add($ressource);
$ressource->setUser($this);
}
return $this;
}
public function removeRessource(Ressources $ressource): self
{
if ($this->ressources->removeElement($ressource)) {
// set the owning side to null (unless already changed)
if ($ressource->getUser() === $this) {
$ressource->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, InscriptionSessionFormation>
*/
public function getInscriptionSessionFormations(): Collection
{
return $this->inscriptionSessionFormations;
}
public function addInscriptionSessionFormation(InscriptionSessionFormation $inscriptionSessionFormation): self
{
if (!$this->inscriptionSessionFormations->contains($inscriptionSessionFormation)) {
$this->inscriptionSessionFormations->add($inscriptionSessionFormation);
$inscriptionSessionFormation->setUser($this);
}
return $this;
}
public function removeInscriptionSessionFormation(InscriptionSessionFormation $inscriptionSessionFormation): self
{
if ($this->inscriptionSessionFormations->removeElement($inscriptionSessionFormation)) {
// set the owning side to null (unless already changed)
if ($inscriptionSessionFormation->getUser() === $this) {
$inscriptionSessionFormation->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, forumResponse>
*/
public function getForumResponses(): Collection
{
return $this->forumResponses;
}
public function addForumResponses(ForumReponse $forumResponses): self
{
if (!$this->forumResponses->contains($forumResponses)) {
$this->forumResponses[] = $forumResponses;
$forumResponses->setUser($this);
}
return $this;
}
public function removeForumResponses(ForumReponse $forumResponses): self
{
if ($this->forumResponses->removeElement($forumResponses)) {
// set the owning side to null (unless already changed)
if ($forumResponses->getUser() === $this) {
$forumResponses->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, sujetForum>
*/
public function getSujetResponses(): Collection
{
return $this->sujetForums;
}
public function addSujetResponses(Sujetforum $sujetForum): self
{
if (!$this->sujetForums->contains($sujetForum)) {
$this->sujetForums[] = $sujetForum;
$sujetForum->setUser($this);
}
return $this;
}
public function removeSujetForums(Sujetforum $sujetForum): self
{
if ($this->sujetForums->removeElement($sujetForum)) {
// set the owning side to null (unless already changed)
if ($sujetForum->getUser() === $this) {
$sujetForum->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, Commande>
*/
public function getCommande(): Collection
{
return $this->commande;
}
public function addCommande(Commande $commande): self
{
if (!$this->commande->contains($commande)) {
$this->commande->add($commande);
$commande->setUser($this);
}
return $this;
}
public function removeCommande(Commande $commande): self
{
if ($this->commande->removeElement($commande)) {
// set the owning side to null (unless already changed)
if ($commande->getUser() === $this) {
$commande->setUser(null);
}
}
return $this;
}
public function addForumResponse(ForumReponse $forumResponse): self
{
if (!$this->forumResponses->contains($forumResponse)) {
$this->forumResponses->add($forumResponse);
$forumResponse->setUser($this);
}
return $this;
}
public function removeForumResponse(ForumReponse $forumResponse): self
{
if ($this->forumResponses->removeElement($forumResponse)) {
// set the owning side to null (unless already changed)
if ($forumResponse->getUser() === $this) {
$forumResponse->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, Sujetforum>
*/
public function getSujetForums(): Collection
{
return $this->sujetForums;
}
public function addSujetForum(Sujetforum $sujetForum): self
{
if (!$this->sujetForums->contains($sujetForum)) {
$this->sujetForums->add($sujetForum);
$sujetForum->setUser($this);
}
return $this;
}
public function removeSujetForum(Sujetforum $sujetForum): self
{
if ($this->sujetForums->removeElement($sujetForum)) {
// set the owning side to null (unless already changed)
if ($sujetForum->getUser() === $this) {
$sujetForum->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, DocDemandeService>
*/
public function getDocDemande(): Collection
{
return $this->docDemande;
}
public function addDocDemande(DocDemandeService $docDemande): self
{
if (!$this->docDemande->contains($docDemande)) {
$this->docDemande->add($docDemande);
$docDemande->setUser($this);
}
return $this;
}
public function removeDocDemande(DocDemandeService $docDemande): self
{
if ($this->docDemande->removeElement($docDemande)) {
// set the owning side to null (unless already changed)
if ($docDemande->getUser() === $this) {
$docDemande->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, UserFicheSatisfaction>
*/
public function getUserFicheSatisfactions(): Collection
{
return $this->userFicheSatisfactions;
}
public function addUserFicheSatisfaction(UserFicheSatisfaction $userFicheSatisfaction): self
{
if (!$this->userFicheSatisfactions->contains($userFicheSatisfaction)) {
$this->userFicheSatisfactions->add($userFicheSatisfaction);
$userFicheSatisfaction->setUser($this);
}
return $this;
}
public function removeUserFicheSatisfaction(UserFicheSatisfaction $userFicheSatisfaction): self
{
if ($this->userFicheSatisfactions->removeElement($userFicheSatisfaction)) {
// set the owning side to null (unless already changed)
if ($userFicheSatisfaction->getUser() === $this) {
$userFicheSatisfaction->setUser(null);
}
}
return $this;
}
public function isIsDeleted(): ?bool
{
return $this->isDeleted;
}
/**
* @return Collection<int, Notification>
*/
public function getNotifications(): Collection
{
return $this->notifications;
}
public function addNotification(Notification $notification): self
{
if (!$this->notifications->contains($notification)) {
$this->notifications->add($notification);
$notification->setUser($this);
}
return $this;
}
public function removeNotification(Notification $notification): self
{
if ($this->notifications->removeElement($notification)) {
// set the owning side to null (unless already changed)
if ($notification->getUser() === $this) {
$notification->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, DemandeService>
*/
public function getDemandeServices(): Collection
{
return $this->demandeServices;
}
public function addDemandeService(DemandeService $demandeService): self
{
if (!$this->demandeServices->contains($demandeService)) {
$this->demandeServices->add($demandeService);
$demandeService->setUser($this);
}
return $this;
}
public function removeDemandeService(DemandeService $demandeService): self
{
if ($this->demandeServices->removeElement($demandeService)) {
// set the owning side to null (unless already changed)
if ($demandeService->getUser() === $this) {
$demandeService->setUser(null);
}
}
return $this;
}
}