<?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 Knp\DoctrineBehaviors\Contract\Entity\BlameableInterface;
use Knp\DoctrineBehaviors\Model\Blameable\BlameableTrait;
use Knp\DoctrineBehaviors\Contract\Entity\TimestampableInterface;
use Knp\DoctrineBehaviors\Model\Timestampable\TimestampableTrait;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Validator\Constraints as Assert;
#[ORM\Entity(repositoryClass: UserRepository::class)]
#[ORM\Table(name: '`user`')]
#[UniqueEntity(fields: ['email'], message: 'There is already an account with this email')]
class User implements UserInterface, BlameableInterface, TimestampableInterface
{
use BlameableTrait;
use TimestampableTrait;
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
#[ORM\Column(type: 'string', length: 180, unique: true)]
private $email;
#[ORM\Column(type: 'json')]
private $roles = [];
#[ORM\Column(type: 'string')]
#[Assert\Length(min: 8)]
#[Assert\Regex(
pattern: '^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]{1,}$^',
message: 'Le mot de passe doit comporter au moins une lettre majuscule, une minuscule et un chiffre !',
)]
private $password;
#[ORM\Column(type: 'boolean')]
private $isVerified = false;
#[ORM\OneToMany(mappedBy: 'User', targetEntity: Demande::class)]
private $demandes;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $nom;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $prenom;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $IntituleDuPoste;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $Institution;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $Resume;
#[ORM\Column(type: 'string', length: 180, nullable: true)]
private $Telephone;
#[ORM\Column(type: 'string', length: 180, nullable: true)]
private $Mobile;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $NomUtilisateurGoogle;
#[ORM\Column(type: 'boolean', options:["default" => 0])]
private $Completed = 0;
#[ORM\Column(type: 'string', length: 1000, nullable: true)]
private $TokenReset;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $nomOgranisme;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $Adresse1;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $Adresse2;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $Adresse3;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $Photo;
#[ORM\ManyToOne(targetEntity: Ville::class, inversedBy: 'users')]
private $Ville;
#[ORM\Column(type: 'integer', nullable: true)]
private $TelephoneOrganisme;
#[ORM\Column(type: 'integer', nullable: true)]
private $FaxOrganisme;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $emailContact;
#[ORM\OneToMany(mappedBy: 'User', targetEntity: FormUser::class)]
private $formUsers;
#[ORM\OneToMany(mappedBy: 'User', targetEntity: Reclamation::class)]
private $reclamations;
#[ORM\OneToMany(mappedBy: 'User', targetEntity: ReclamationReponse::class)]
private $reclamationReponses;
#[ORM\OneToMany(mappedBy: 'User', targetEntity: FormUserNote::class)]
private $formUserNotes;
#[ORM\ManyToMany(targetEntity: Demande::class, mappedBy: 'responsables')]
private $demandeResponsable;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: FormUserNote::class)]
private $demandeNotes;
#[ORM\ManyToMany(targetEntity: FormUser::class, mappedBy: 'Responsables')]
private $formUsersResponsable;
#[ORM\Column(type: 'boolean', options:['default' => 1])]
private $Active = 1;
#[ORM\ManyToMany(targetEntity: Reclamation::class, mappedBy: 'responsables')]
private $reclamationsResponsable;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: Notification::class, orphanRemoval: true)]
private $notifications;
#[ORM\ManyToMany(targetEntity: Form::class, mappedBy: 'responsables')]
#[ORM\JoinTable(name: "form_responsable")]
private $formResponsables;
public function __construct()
{
$this->demandes = new ArrayCollection();
$this->formUsers = new ArrayCollection();
$this->reclamations = new ArrayCollection();
$this->reclamationReponses = new ArrayCollection();
$this->formUserNotes = new ArrayCollection();
$this->demandeResponsable = new ArrayCollection();
$this->demandeNotes = new ArrayCollection();
$this->formUsersResponsable = new ArrayCollection();
$this->reclamationsResponsable = new ArrayCollection();
$this->notifications = new ArrayCollection();
$this->formResponsables = 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;
}
/**
* @deprecated since Symfony 5.3, use getUserIdentifier instead
*/
public function getUsername(): 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 PasswordAuthenticatedUserInterface
*/
public function getPassword(): string
{
return $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
public function setAllRoles($roles): self
{
$this->setRoles([$roles]);
return $this;
}
public function getAllRoles(): string
{
return "";
}
/**
* 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;
}
/**
* @return Collection<int, Demande>
*/
public function getDemandes(): Collection
{
return $this->demandes;
}
public function addDemande(Demande $demande): self
{
if (!$this->demandes->contains($demande)) {
$this->demandes[] = $demande;
$demande->setUser($this);
}
return $this;
}
public function removeDemande(Demande $demande): self
{
if ($this->demandes->removeElement($demande)) {
// set the owning side to null (unless already changed)
if ($demande->getUser() === $this) {
$demande->setUser(null);
}
}
return $this;
}
public function getNom(): ?string
{
return $this->nom;
}
public function setNom(string $nom): self
{
$this->nom = $nom;
return $this;
}
public function getPrenom(): ?string
{
return $this->prenom;
}
public function setPrenom(string $prenom): self
{
$this->prenom = $prenom;
return $this;
}
public function getIntituleDuPoste(): ?string
{
return $this->IntituleDuPoste;
}
public function setIntituleDuPoste(string $IntituleDuPoste): self
{
$this->IntituleDuPoste = $IntituleDuPoste;
return $this;
}
public function getInstitution(): ?string
{
return $this->Institution;
}
public function setInstitution(string $Institution): self
{
$this->Institution = $Institution;
return $this;
}
public function getResume(): ?string
{
return $this->Resume;
}
public function setResume(?string $Resume): self
{
$this->Resume = $Resume;
return $this;
}
public function getTelephone(): ?string
{
return $this->Telephone;
}
public function setTelephone($Telephone): self
{
$this->Telephone = $Telephone;
return $this;
}
public function getMobile(): ?string
{
return $this->Mobile;
}
public function setMobile($Mobile): self
{
$this->Mobile = $Mobile;
return $this;
}
public function getNomUtilisateurGoogle(): ?string
{
return $this->NomUtilisateurGoogle;
}
public function setNomUtilisateurGoogle(?string $NomUtilisateurGoogle): self
{
$this->NomUtilisateurGoogle = $NomUtilisateurGoogle;
return $this;
}
public function getCompleted(): ?bool
{
return $this->Completed;
}
public function setCompleted(bool $Completed): self
{
$this->Completed = $Completed;
return $this;
}
public function getTokenReset(): ?string
{
return $this->TokenReset;
}
public function setTokenReset(?string $TokenReset): self
{
$this->TokenReset = $TokenReset;
return $this;
}
public function getNomOgranisme(): ?string
{
return $this->nomOgranisme;
}
public function setNomOgranisme(?string $nomOgranisme): self
{
$this->nomOgranisme = $nomOgranisme;
return $this;
}
public function getAdresse1(): ?string
{
return $this->Adresse1;
}
public function setAdresse1(?string $Adresse1): self
{
$this->Adresse1 = $Adresse1;
return $this;
}
public function getAdresse2(): ?string
{
return $this->Adresse2;
}
public function setAdresse2(string $Adresse2): self
{
$this->Adresse2 = $Adresse2;
return $this;
}
public function getAdresse3(): ?string
{
return $this->Adresse3;
}
public function setAdresse3(?string $Adresse3): self
{
$this->Adresse3 = $Adresse3;
return $this;
}
public function getPhoto(): ?string
{
return $this->Photo;
}
public function setPhoto(string $Photo): self
{
$this->Photo = $Photo;
return $this;
}
public function getVille(): ?Ville
{
return $this->Ville;
}
public function setVille(?Ville $Ville): self
{
$this->Ville = $Ville;
return $this;
}
public function getTelephoneOrganisme(): ?int
{
return $this->TelephoneOrganisme;
}
public function setTelephoneOrganisme($TelephoneOrganisme): self
{
$this->TelephoneOrganisme = $TelephoneOrganisme;
return $this;
}
public function getFaxOrganisme(): ?int
{
return $this->FaxOrganisme;
}
public function setFaxOrganisme($FaxOrganisme): self
{
$this->FaxOrganisme = $FaxOrganisme;
return $this;
}
public function getEmailContact(): ?string
{
return $this->emailContact;
}
public function setEmailContact(string $emailContact): self
{
$this->emailContact = $emailContact;
return $this;
}
/**
* @return Collection<int, FormUser>
*/
public function getFormUsers(): Collection
{
return $this->formUsers;
}
public function addFormUser(FormUser $formUser): self
{
if (!$this->formUsers->contains($formUser)) {
$this->formUsers[] = $formUser;
$formUser->setUser($this);
}
return $this;
}
public function removeFormUser(FormUser $formUser): self
{
if ($this->formUsers->removeElement($formUser)) {
// set the owning side to null (unless already changed)
if ($formUser->getUser() === $this) {
$formUser->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, Reclamation>
*/
public function getReclamations(): Collection
{
return $this->reclamations;
}
public function addReclamation(Reclamation $reclamation): self
{
if (!$this->reclamations->contains($reclamation)) {
$this->reclamations[] = $reclamation;
$reclamation->setUser($this);
}
return $this;
}
public function removeReclamation(Reclamation $reclamation): self
{
if ($this->reclamations->removeElement($reclamation)) {
// set the owning side to null (unless already changed)
if ($reclamation->getUser() === $this) {
$reclamation->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, ReclamationReponse>
*/
public function getReclamationReponses(): Collection
{
return $this->reclamationReponses;
}
public function addReclamationReponse(ReclamationReponse $reclamationReponse): self
{
if (!$this->reclamationReponses->contains($reclamationReponse)) {
$this->reclamationReponses[] = $reclamationReponse;
$reclamationReponse->setUser($this);
}
return $this;
}
public function removeReclamationReponse(ReclamationReponse $reclamationReponse): self
{
if ($this->reclamationReponses->removeElement($reclamationReponse)) {
// set the owning side to null (unless already changed)
if ($reclamationReponse->getUser() === $this) {
$reclamationReponse->setUser(null);
}
}
return $this;
}
public function getExportData()
{
return \array_merge([
'id' => $this->getId(),
'Nom' => $this->getNom(),
'Prénom' => $this->getPrenom(),
'Teléphone' => $this->getTelephoneOrganisme(),
'Mobile' => $this->getMobile() ?? '',
'Ville' => $this->getVille() ?? '',
'Email' => $this->getEmailContact() ?? '',
'Date de creation' => $this->getCreatedAt() ? $this->getCreatedAt()->format('Y-m-d') : '',
'Poste' => $this->getIntituleDuPoste() ?? '',
'Active' => $this->isActive() ?? '',
]);
}
public function __toString()
{
return $this->getEmail();
}
/**
* @return Collection<int, FormUserNote>
*/
public function getFormUserNotes(): Collection
{
return $this->formUserNotes;
}
public function addFormUserNote(FormUserNote $formUserNote): self
{
if (!$this->formUserNotes->contains($formUserNote)) {
$this->formUserNotes[] = $formUserNote;
$formUserNote->setUser($this);
}
return $this;
}
public function removeFormUserNote(FormUserNote $formUserNote): self
{
if ($this->formUserNotes->removeElement($formUserNote)) {
// set the owning side to null (unless already changed)
if ($formUserNote->getUser() === $this) {
$formUserNote->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, DemandeNote>
*/
public function getDemandeNotes(): Collection
{
return $this->demandeNotes;
}
public function addDemandeNote(DemandeNote $demandeNote): self
{
if (!$this->demandeNotes->contains($demandeNote)) {
$this->demandeNotes[] = $demandeNote;
$demandeNote->setUser($this);
}
return $this;
}
public function removeDemandeNote(DemandeNote $demandeNote): self
{
if ($this->demandeNotes->removeElement($demandeNote)) {
// set the owning side to null (unless already changed)
if ($demandeNote->getUser() === $this) {
$demandeNote->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, Demande>
*/
public function getDemandeResponsable(): Collection
{
return $this->demandeResponsable;
}
public function addDemandeResponsable(Demande $demandeResponsable): self
{
if (!$this->demandeResponsable->contains($demandeResponsable)) {
$this->demandeResponsable[] = $demandeResponsable;
$demandeResponsable->addResponsable($this);
}
return $this;
}
public function removeDemandeResponsable(Demande $demandeResponsable): self
{
if ($this->demandeResponsable->removeElement($demandeResponsable)) {
$demandeResponsable->removeResponsable($this);
}
return $this;
}
/**
* @return Collection<int, FormUser>
*/
public function getFormUsersResponsable(): Collection
{
return $this->formUsersResponsable;
}
public function addFormUsersResponsable(FormUser $formUsersResponsable): self
{
if (!$this->formUsersResponsable->contains($formUsersResponsable)) {
$this->formUsersResponsable[] = $formUsersResponsable;
$formUsersResponsable->addResponsable($this);
}
return $this;
}
public function removeFormUsersResponsable(FormUser $formUsersResponsable): self
{
if ($this->formUsersResponsable->removeElement($formUsersResponsable)) {
$formUsersResponsable->removeResponsable($this);
}
return $this;
}
public function isActive(): ?bool
{
return $this->Active;
}
public function setActive(bool $Active): self
{
$this->Active = $Active;
return $this;
}
/**
* @return Collection<int, Reclamation>
*/
public function getReclamationsResponsable(): Collection
{
return $this->reclamationsResponsable;
}
public function addReclamationsResponsable(Reclamation $reclamationsResponsable): self
{
if (!$this->reclamationsResponsable->contains($reclamationsResponsable)) {
$this->reclamationsResponsable[] = $reclamationsResponsable;
$reclamationsResponsable->addResponsable($this);
}
return $this;
}
public function removeReclamationsResponsable(Reclamation $reclamationsResponsable): self
{
if ($this->reclamationsResponsable->removeElement($reclamationsResponsable)) {
$reclamationsResponsable->removeResponsable($this);
}
return $this;
}
/**
* @return Collection<int, Notification>
*/
public function getNotifications(): Collection
{
return $this->notifications;
}
public function addNotification(Notification $notification): self
{
if (!$this->notifications->contains($notification)) {
$this->notifications[] = $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, Form>
*/
public function getFormResponsables(): Collection
{
return $this->formResponsables;
}
public function addFormResponsable(Form $formResponsable): self
{
if (!$this->formResponsables->contains($formResponsable)) {
$this->formResponsables[] = $formResponsable;
$formResponsable->addResponsable($this);
}
return $this;
}
public function removeFormResponsable(Form $formResponsable): self
{
if ($this->formResponsables->removeElement($formResponsable)) {
$formResponsable->removeResponsable($this);
}
return $this;
}
}