<?php
namespace App\Entity;
use App\Repository\UtilisateurRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* @ORM\Entity(repositoryClass=UtilisateurRepository::class)
* @UniqueEntity(
* fields={"email"},
* message="Cet email est déjà utilisé."
* )
*/
class Utilisateur implements UserInterface, PasswordAuthenticatedUserInterface
{
/**
* @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 = [];
/**
* @var string The hashed password
* @ORM\Column(type="string")
*/
private $password;
/**
* @ORM\Column(type="boolean")
*/
private $notification;
/**
* @ORM\Column(type="boolean")
*/
private $hideAccount;
/**
* @ORM\Column(type="boolean")
*/
private $hideEntreprise;
/**
* @ORM\Column(type="boolean")
*/
private $allProgrammes;
/**
* @ORM\Column(type="string", length=7, nullable=true)
*/
private $couleur;
/**
* @ORM\OneToMany(targetEntity=Historique::class, mappedBy="expediteur")
*/
private $historiques;
/**
* @ORM\Column(type="string", length=255)
*/
private $telephone;
/**
* @ORM\Column(type="string", length=255)
*/
private $nom;
/**
* @ORM\Column(type="string", length=255)
*/
private $prenom;
/**
* @ORM\OneToMany(targetEntity=Prospect::class, mappedBy="auteur")
*/
private $prospects;
/**
* @ORM\ManyToOne(targetEntity=Entreprise::class, inversedBy="utilisateurs")
*/
private $entreprise;
/**
* @ORM\OneToMany(targetEntity=Programme::class, mappedBy="prescripteur")
*/
private $prescripteurProgrammes;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $prescripteurCoordonneesResponsable;
/**
* @ORM\OneToMany(targetEntity=InfosSuivi::class, mappedBy="utilisateur", cascade={"remove"})
*/
private $infosSuivis;
/**
* @ORM\OneToMany(targetEntity=ActionTrace::class, mappedBy="user")
*/
private $actionTraces;
/**
* @ORM\Column(type="boolean", options={"default":false})
*/
private $peutModifier = false;
/**
* @ORM\Column(type="boolean", options={"default": false})
*/
private $rapportQuotidien = false;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $smtpEmail;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $smtpPassword;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $smtpDisplayName;
public const ROLES = [];
public const SUPERADMIN_ROLES = [
'SUPER ADMIN' => 'ROLE_SUPERADMIN',
'ADMIN' => 'ROLE_ADMIN',
'Directeur/trice Commercial(e)' => 'ROLE_DIRECTEUR',
'Responsable Prescription' => 'ROLE_RESPONSABLE',
'Négociateur/Négociatrice ' => 'ROLE_COMMERCIAL',
'Partenaire/Prescripteur' => 'ROLE_PARTENAIRE',
'Opérateur/trice de Saisie' => 'ROLE_SAISIE',
];
public const ADMIN_ROLES = [
'ADMIN' => 'ROLE_ADMIN',
'Directeur/trice Commercial(e)' => 'ROLE_DIRECTEUR',
'Responsable Prescription' => 'ROLE_RESPONSABLE',
'Négociateur/Négociatrice ' => 'ROLE_COMMERCIAL',
'Partenaire/Prescripteur' => 'ROLE_PARTENAIRE',
'Opérateur/trice de Saisie' => 'ROLE_SAISIE',
];
public const DIRECTEUR_ROLES = [
'Négociateur/Négociatrice ' => 'ROLE_COMMERCIAL',
'Opérateur/trice de Saisie' => 'ROLE_SAISIE',
];
public const RESPONSABLE_ROLES = [
'Partenaire/Prescripteur' => 'ROLE_PARTENAIRE',
'Opérateur/trice de Saisie' => 'ROLE_SAISIE',
];
public function __construct()
{
$this->historiques = new ArrayCollection();
$this->prospects = new ArrayCollection();
if ($this->couleur === null) {
$this->couleur = '#F7F7F7';
}
$this->prescripteurProgrammes = new ArrayCollection();
$this->infosSuivis = new ArrayCollection();
$this->allProgrammes = false;
$this->actionTraces = new ArrayCollection();
}
public function __toString() {
return $this->getId() == null ? 'Nouvel utilisateur' : $this->getEmail();
}
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;
}
public function getRole() {
if(!count($this->getRoles())) return null;
return $this->getRoles()[0];
}
public function setRole($role) {
return $this->setRoles([$role]);
}
/**
* @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;
}
/**
* 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 getNotification(): ?bool
{
return $this->notification;
}
public function setNotification(bool $notification): self
{
$this->notification = $notification;
return $this;
}
public function getSmtpEmail(): ?string
{
return $this->smtpEmail;
}
public function setSmtpEmail(?string $smtpEmail): self
{
$this->smtpEmail = $smtpEmail;
return $this;
}
public function getSmtpPassword(): ?string
{
return $this->smtpPassword;
}
public function setSmtpPassword(?string $smtpPassword): self
{
if ($smtpPassword === null || $smtpPassword === '') {
return $this;
}
$this->smtpPassword = $smtpPassword;
return $this;
}
public function getSmtpDisplayName(): ?string
{
return $this->smtpDisplayName;
}
public function setSmtpDisplayName(?string $smtpDisplayName): self
{
$this->smtpDisplayName = $smtpDisplayName;
return $this;
}
public function getHideAccount(): ?bool
{
return $this->hideAccount;
}
public function setHideAccount(bool $hideAccount): self
{
$this->hideAccount = $hideAccount;
return $this;
}
public function getHideEntreprise(): ?bool
{
return $this->hideEntreprise;
}
public function setHideEntreprise(bool $hideEntreprise): self
{
$this->hideEntreprise = $hideEntreprise;
return $this;
}
public function getallProgrammes(): ?bool
{
return $this->allProgrammes;
}
public function setallProgrammes(bool $allProgrammes): self
{
$this->allProgrammes = $allProgrammes;
return $this;
}
/**
* @return Collection|Historique[]
*/
public function getHistoriques(): Collection
{
return $this->historiques;
}
public function addHistorique(Historique $historique): self
{
if (!$this->historiques->contains($historique)) {
$historique->setExpediteur($this);
$historique->setEntreprise($this->getEntreprise());
$this->historiques[] = $historique;
}
return $this;
}
public function removeHistorique(Historique $historique): self
{
if ($this->historiques->removeElement($historique)) {
// set the owning side to null (unless already changed)
if ($historique->getExpediteur() === $this) {
$historique->setExpediteur(null);
}
}
return $this;
}
public function isRapportQuotidien(): bool
{
return (bool) $this->rapportQuotidien;
}
public function setRapportQuotidien(bool $rapportQuotidien): self
{
$this->rapportQuotidien = $rapportQuotidien;
return $this;
}
public function getTelephone(): ?string
{
return $this->telephone;
}
public function setTelephone(string $telephone): self
{
$this->telephone = $telephone;
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 getNomEtPrenom()
{
return $this->getPrenom() . ' ' . $this->getNom();
}
/**
* @return Collection<int, Prospect>
*/
public function getProspects(): Collection
{
return $this->prospects;
}
public function addProspect(Prospect $prospect): self
{
if (!$this->prospects->contains($prospect)) {
$this->prospects[] = $prospect;
$prospect->setAuteur($this);
}
return $this;
}
public function removeProspect(Prospect $prospect): self
{
if ($this->prospects->removeElement($prospect)) {
// set the owning side to null (unless already changed)
if ($prospect->getAuteur() === $this) {
$prospect->setAuteur(null);
}
}
return $this;
}
public function getEntreprise(): ?Entreprise
{
return $this->entreprise;
}
public function setEntreprise(?Entreprise $entreprise): self
{
$this->entreprise = $entreprise;
return $this;
}
public function isNotification(): ?bool
{
return $this->notification;
}
public function isHideAccount(): ?bool
{
return $this->hideAccount;
}
public function isHideEntreprise(): ?bool
{
return $this->hideEntreprise;
}
public function isallProgrammes(): ?bool
{
return $this->allProgrammes;
}
public function getCouleur(): ?string
{
return $this->couleur;
}
public function setCouleur(?string $couleur): self
{
$this->couleur = $couleur;
return $this;
}
public function getAvailableRoles(): array
{
$roles = self::ROLES;
if (in_array('ROLE_MASTER', $this->getRoles()) || in_array('ROLE_SUPERADMIN', $this->getRoles())) {
$roles = array_merge(self::SUPERADMIN_ROLES, $roles);
}
if (in_array('ROLE_ADMIN', $this->getRoles())) {
$roles = array_merge(self::ADMIN_ROLES, $roles);
}
if (in_array('ROLE_DIRECTEUR', $this->getRoles())) {
$roles = array_merge(self::DIRECTEUR_ROLES, $roles);
}
if (in_array('ROLE_RESPONSABLE', $this->getRoles())) {
$roles = array_merge(self::RESPONSABLE_ROLES, $roles);
}
return $roles;
}
/**
* @return Collection<int, Programme>
*/
public function getPrescripteurProgrammes(): Collection
{
return $this->prescripteurProgrammes;
}
public function addPrescripteurProgramme(Programme $prescripteurProgramme): self
{
if (!$this->prescripteurProgrammes->contains($prescripteurProgramme)) {
$this->prescripteurProgrammes[] = $prescripteurProgramme;
$prescripteurProgramme->setPrescripteur($this);
}
return $this;
}
public function removePrescripteurProgramme(Programme $prescripteurProgramme): self
{
if ($this->prescripteurProgrammes->removeElement($prescripteurProgramme)) {
// set the owning side to null (unless already changed)
if ($prescripteurProgramme->getPrescripteur() === $this) {
$prescripteurProgramme->setPrescripteur(null);
}
}
return $this;
}
public function getPrescripteurCoordonneesResponsable(): ?string
{
return $this->prescripteurCoordonneesResponsable;
}
public function setPrescripteurCoordonneesResponsable(?string $prescripteurCoordonneesResponsable): self
{
$this->prescripteurCoordonneesResponsable = $prescripteurCoordonneesResponsable;
return $this;
}
/**
* @return Collection<int, InfosSuivi>
*/
public function getInfosSuivis(): Collection
{
return $this->infosSuivis;
}
public function addInfosSuivi(InfosSuivi $infosSuivi): self
{
if (!$this->infosSuivis->contains($infosSuivi)) {
$this->infosSuivis[] = $infosSuivi;
$infosSuivi->setUtilisateur($this);
}
return $this;
}
public function removeInfosSuivi(InfosSuivi $infosSuivi): self
{
if ($this->infosSuivis->removeElement($infosSuivi)) {
// set the owning side to null (unless already changed)
if ($infosSuivi->getUtilisateur() === $this) {
$infosSuivi->setUtilisateur(null);
}
}
return $this;
}
/**
* @return Collection<int, ActionTrace>
*/
public function getActionTraces(): Collection
{
return $this->actionTraces;
}
public function addActionTrace(ActionTrace $actionTrace): self
{
if (!$this->actionTraces->contains($actionTrace)) {
$this->actionTraces[] = $actionTrace;
$actionTrace->setUser($this);
}
return $this;
}
public function removeActionTrace(ActionTrace $actionTrace): self
{
if ($this->actionTraces->removeElement($actionTrace)) {
// set the owning side to null (unless already changed)
if ($actionTrace->getUser() === $this) {
$actionTrace->setUser(null);
}
}
return $this;
}
public function getPeutModifier(): ?bool
{
return $this->peutModifier;
}
public function setPeutModifier(bool $peutModifier): self
{
$this->peutModifier = $peutModifier;
return $this;
}
public function isPeutModifier(): ?bool
{
return $this->peutModifier;
}
/**
* Méthode pour vérifier si l'utilisateur peut modifier les lots et programmes
*/
public function peutModifierContenu(): bool
{
if (in_array('ROLE_SUPERADMIN', $this->getRoles()) ||
in_array('ROLE_ADMIN', $this->getRoles()) ||
in_array('ROLE_DIRECTEUR', $this->getRoles()) ||
in_array('ROLE_SAISIE', $this->getRoles())) {
return true;
}
if (in_array('ROLE_COMMERCIAL', $this->getRoles()) ||
in_array('ROLE_PARTENAIRE', $this->getRoles())) {
return $this->getPeutModifier();
}
return false;
}
}