src/Entity/Utilisateur.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\UtilisateurRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  8. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  9. use Symfony\Component\Security\Core\User\UserInterface;
  10. /**
  11.  * @ORM\Entity(repositoryClass=UtilisateurRepository::class)
  12.  * @UniqueEntity(
  13.  *     fields={"email"},
  14.  *     message="Cet email est déjà utilisé."
  15.  * )
  16.  */
  17. class Utilisateur implements UserInterfacePasswordAuthenticatedUserInterface
  18. {
  19.     /**
  20.      * @ORM\Id
  21.      * @ORM\GeneratedValue
  22.      * @ORM\Column(type="integer")
  23.      */
  24.     private $id;
  25.     /**
  26.      * @ORM\Column(type="string", length=180, unique=true)
  27.      */
  28.     private $email;
  29.     /**
  30.      * @ORM\Column(type="json")
  31.      */
  32.     private $roles = [];
  33.     /**
  34.      * @var string The hashed password
  35.      * @ORM\Column(type="string")
  36.      */
  37.     private $password;
  38.     /**
  39.      * @ORM\Column(type="boolean")
  40.      */
  41.     private $notification;
  42.     /**
  43.      * @ORM\Column(type="boolean")
  44.      */
  45.     private $hideAccount;
  46.     /**
  47.      * @ORM\Column(type="boolean")
  48.      */
  49.     private $hideEntreprise;
  50.     /**
  51.      * @ORM\Column(type="boolean")
  52.      */
  53.     private $allProgrammes;
  54.     /**
  55.      * @ORM\Column(type="string", length=7, nullable=true)
  56.      */
  57.     private $couleur;
  58.     /**
  59.      * @ORM\OneToMany(targetEntity=Historique::class, mappedBy="expediteur")
  60.      */
  61.     private $historiques;
  62.     /**
  63.      * @ORM\Column(type="string", length=255)
  64.      */
  65.     private $telephone;
  66.     /**
  67.      * @ORM\Column(type="string", length=255)
  68.      */
  69.     private $nom;
  70.     /**
  71.      * @ORM\Column(type="string", length=255)
  72.      */
  73.     private $prenom;
  74.     /**
  75.      * @ORM\OneToMany(targetEntity=Prospect::class, mappedBy="auteur")
  76.      */
  77.     private $prospects;
  78.     /**
  79.      * @ORM\ManyToOne(targetEntity=Entreprise::class, inversedBy="utilisateurs")
  80.      */
  81.     private $entreprise;
  82.     /**
  83.      * @ORM\OneToMany(targetEntity=Programme::class, mappedBy="prescripteur")
  84.      */
  85.     private $prescripteurProgrammes;
  86.     /**
  87.      * @ORM\Column(type="text", nullable=true)
  88.      */
  89.     private $prescripteurCoordonneesResponsable;
  90.     /**
  91.      * @ORM\OneToMany(targetEntity=InfosSuivi::class, mappedBy="utilisateur", cascade={"remove"})
  92.      */
  93.     private $infosSuivis;
  94.     /**
  95.      * @ORM\OneToMany(targetEntity=ActionTrace::class, mappedBy="user")
  96.      */
  97.     private $actionTraces;
  98.     /**
  99.      * @ORM\Column(type="boolean", options={"default":false})
  100.      */
  101.     private $peutModifier false;
  102.     /**
  103.      * @ORM\Column(type="boolean", options={"default": false})
  104.      */
  105.     private $rapportQuotidien false;
  106.     /**
  107.      * @ORM\Column(type="string", length=255, nullable=true)
  108.      */
  109.     private $smtpEmail;
  110.     /**
  111.      * @ORM\Column(type="string", length=255, nullable=true)
  112.      */
  113.     private $smtpPassword;
  114.     /**
  115.      * @ORM\Column(type="string", length=255, nullable=true)
  116.      */
  117.     private $smtpDisplayName;
  118.     public const ROLES = [];
  119.     public const SUPERADMIN_ROLES = [
  120.         'SUPER ADMIN' => 'ROLE_SUPERADMIN',
  121.         'ADMIN' => 'ROLE_ADMIN',
  122.         'Directeur/trice Commercial(e)' => 'ROLE_DIRECTEUR',
  123.         'Responsable Prescription' => 'ROLE_RESPONSABLE',
  124.         'Négociateur/Négociatrice ' => 'ROLE_COMMERCIAL',
  125.         'Partenaire/Prescripteur' => 'ROLE_PARTENAIRE',
  126.         'Opérateur/trice de Saisie' => 'ROLE_SAISIE',
  127.     ];
  128.     public const ADMIN_ROLES = [
  129.         'ADMIN' => 'ROLE_ADMIN',
  130.         'Directeur/trice Commercial(e)' => 'ROLE_DIRECTEUR',
  131.         'Responsable Prescription' => 'ROLE_RESPONSABLE',
  132.         'Négociateur/Négociatrice ' => 'ROLE_COMMERCIAL',
  133.         'Partenaire/Prescripteur' => 'ROLE_PARTENAIRE',
  134.         'Opérateur/trice de Saisie' => 'ROLE_SAISIE',
  135.     ];
  136.     public const DIRECTEUR_ROLES = [
  137.         'Négociateur/Négociatrice ' => 'ROLE_COMMERCIAL',
  138.         'Opérateur/trice de Saisie' => 'ROLE_SAISIE',
  139.     ];
  140.     public const RESPONSABLE_ROLES = [
  141.         'Partenaire/Prescripteur' => 'ROLE_PARTENAIRE',
  142.         'Opérateur/trice de Saisie' => 'ROLE_SAISIE',
  143.     ];
  144.     public function __construct()
  145.     {
  146.         $this->historiques = new ArrayCollection();
  147.         $this->prospects = new ArrayCollection();
  148.         if ($this->couleur === null) {
  149.             $this->couleur '#F7F7F7';
  150.         }
  151.         $this->prescripteurProgrammes = new ArrayCollection();
  152.         $this->infosSuivis = new ArrayCollection();
  153.         $this->allProgrammes false;
  154.         $this->actionTraces = new ArrayCollection();
  155.     }
  156.     public function __toString() {
  157.         return $this->getId() == null 'Nouvel utilisateur' $this->getEmail();
  158.     }
  159.     public function getId(): ?int
  160.     {
  161.         return $this->id;
  162.     }
  163.     public function getEmail(): ?string
  164.     {
  165.         return $this->email;
  166.     }
  167.     public function setEmail(string $email): self
  168.     {
  169.         $this->email $email;
  170.         return $this;
  171.     }
  172.     /**
  173.      * A visual identifier that represents this user.
  174.      *
  175.      * @see UserInterface
  176.      */
  177.     public function getUserIdentifier(): string
  178.     {
  179.         return (string) $this->email;
  180.     }
  181.     /**
  182.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  183.      */
  184.     public function getUsername(): string
  185.     {
  186.         return (string) $this->email;
  187.     }
  188.     public function getRole() {
  189.         if(!count($this->getRoles())) return null;
  190.         return $this->getRoles()[0];
  191.     }
  192.     public function setRole($role) {
  193.         return $this->setRoles([$role]);
  194.     }
  195.     /**
  196.      * @see UserInterface
  197.      */
  198.     public function getRoles(): array
  199.     {
  200.         $roles $this->roles;
  201.         // guarantee every user at least has ROLE_USER
  202.         $roles[] = 'ROLE_USER';
  203.         return array_unique($roles);
  204.     }
  205.     public function setRoles(array $roles): self
  206.     {
  207.         $this->roles $roles;
  208.         return $this;
  209.     }
  210.     /**
  211.      * @see PasswordAuthenticatedUserInterface
  212.      */
  213.     public function getPassword(): string
  214.     {
  215.         return $this->password;
  216.     }
  217.     public function setPassword(string $password): self
  218.     {
  219.         $this->password $password;
  220.         return $this;
  221.     }
  222.     /**
  223.      * Returning a salt is only needed, if you are not using a modern
  224.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  225.      *
  226.      * @see UserInterface
  227.      */
  228.     public function getSalt(): ?string
  229.     {
  230.         return null;
  231.     }
  232.     /**
  233.      * @see UserInterface
  234.      */
  235.     public function eraseCredentials()
  236.     {
  237.         // If you store any temporary, sensitive data on the user, clear it here
  238.         // $this->plainPassword = null;
  239.     }
  240.     public function getNotification(): ?bool
  241.     {
  242.         return $this->notification;
  243.     }
  244.     public function setNotification(bool $notification): self
  245.     {
  246.         $this->notification $notification;
  247.         return $this;
  248.     }
  249.     public function getSmtpEmail(): ?string
  250.     {
  251.         return $this->smtpEmail;
  252.     }
  253.     public function setSmtpEmail(?string $smtpEmail): self
  254.     {
  255.         $this->smtpEmail $smtpEmail;
  256.         return $this;
  257.     }
  258.     public function getSmtpPassword(): ?string
  259.     {
  260.         return $this->smtpPassword;
  261.     }
  262.     public function setSmtpPassword(?string $smtpPassword): self
  263.     {
  264.         if ($smtpPassword === null || $smtpPassword === '') {
  265.             return $this;
  266.         }
  267.         $this->smtpPassword $smtpPassword;
  268.         return $this;
  269.     }
  270.     public function getSmtpDisplayName(): ?string
  271.     {
  272.         return $this->smtpDisplayName;
  273.     }
  274.     public function setSmtpDisplayName(?string $smtpDisplayName): self
  275.     {
  276.         $this->smtpDisplayName $smtpDisplayName;
  277.         return $this;
  278.     }
  279.     public function getHideAccount(): ?bool
  280.     {
  281.         return $this->hideAccount;
  282.     }
  283.     public function setHideAccount(bool $hideAccount): self
  284.     {
  285.         $this->hideAccount $hideAccount;
  286.         return $this;
  287.     }
  288.     public function getHideEntreprise(): ?bool
  289.     {
  290.         return $this->hideEntreprise;
  291.     }
  292.     public function setHideEntreprise(bool $hideEntreprise): self
  293.     {
  294.         $this->hideEntreprise $hideEntreprise;
  295.         return $this;
  296.     }
  297.     public function getallProgrammes(): ?bool
  298.     {
  299.         return $this->allProgrammes;
  300.     }
  301.     public function setallProgrammes(bool $allProgrammes): self
  302.     {
  303.         $this->allProgrammes $allProgrammes;
  304.         return $this;
  305.     }
  306.     /**
  307.      * @return Collection|Historique[]
  308.      */
  309.     public function getHistoriques(): Collection
  310.     {
  311.         return $this->historiques;
  312.     }
  313.     public function addHistorique(Historique $historique): self
  314.     {
  315.         if (!$this->historiques->contains($historique)) {
  316.             $historique->setExpediteur($this);
  317.             $historique->setEntreprise($this->getEntreprise());
  318.             $this->historiques[] = $historique;
  319.         }
  320.         return $this;
  321.     }
  322.     public function removeHistorique(Historique $historique): self
  323.     {
  324.         if ($this->historiques->removeElement($historique)) {
  325.             // set the owning side to null (unless already changed)
  326.             if ($historique->getExpediteur() === $this) {
  327.                 $historique->setExpediteur(null);
  328.             }
  329.         }
  330.         return $this;
  331.     }
  332.     public function isRapportQuotidien(): bool
  333.     {
  334.         return (bool) $this->rapportQuotidien;
  335.     }
  336.     public function setRapportQuotidien(bool $rapportQuotidien): self
  337.     {
  338.         $this->rapportQuotidien $rapportQuotidien;
  339.         return $this;
  340.     }
  341.     public function getTelephone(): ?string
  342.     {
  343.         return $this->telephone;
  344.     }
  345.     public function setTelephone(string $telephone): self
  346.     {
  347.         $this->telephone $telephone;
  348.         return $this;
  349.     }
  350.     public function getNom(): ?string
  351.     {
  352.         return $this->nom;
  353.     }
  354.     public function setNom(string $nom): self
  355.     {
  356.         $this->nom $nom;
  357.         return $this;
  358.     }
  359.     public function getPrenom(): ?string
  360.     {
  361.         return $this->prenom;
  362.     }
  363.     public function setPrenom(string $prenom): self
  364.     {
  365.         $this->prenom $prenom;
  366.         return $this;
  367.     }
  368.     public function getNomEtPrenom()
  369.     {
  370.         return $this->getPrenom() . ' ' $this->getNom();
  371.     }
  372.     /**
  373.      * @return Collection<int, Prospect>
  374.      */
  375.     public function getProspects(): Collection
  376.     {
  377.         return $this->prospects;
  378.     }
  379.     public function addProspect(Prospect $prospect): self
  380.     {
  381.         if (!$this->prospects->contains($prospect)) {
  382.             $this->prospects[] = $prospect;
  383.             $prospect->setAuteur($this);
  384.         }
  385.         return $this;
  386.     }
  387.     public function removeProspect(Prospect $prospect): self
  388.     {
  389.         if ($this->prospects->removeElement($prospect)) {
  390.             // set the owning side to null (unless already changed)
  391.             if ($prospect->getAuteur() === $this) {
  392.                 $prospect->setAuteur(null);
  393.             }
  394.         }
  395.         return $this;
  396.     }
  397.     public function getEntreprise(): ?Entreprise
  398.     {
  399.         return $this->entreprise;
  400.     }
  401.     public function setEntreprise(?Entreprise $entreprise): self
  402.     {
  403.         $this->entreprise $entreprise;
  404.         return $this;
  405.     }
  406.     public function isNotification(): ?bool
  407.     {
  408.         return $this->notification;
  409.     }
  410.     public function isHideAccount(): ?bool
  411.     {
  412.         return $this->hideAccount;
  413.     }
  414.     public function isHideEntreprise(): ?bool
  415.     {
  416.         return $this->hideEntreprise;
  417.     }
  418.     public function isallProgrammes(): ?bool
  419.     {
  420.         return $this->allProgrammes;
  421.     }
  422.     public function getCouleur(): ?string
  423.     {
  424.         return $this->couleur;
  425.     }
  426.     public function setCouleur(?string $couleur): self
  427.     {
  428.         $this->couleur $couleur;
  429.         return $this;
  430.     }
  431.     public function getAvailableRoles(): array
  432.     {
  433.         $roles self::ROLES;
  434.         if (in_array('ROLE_MASTER'$this->getRoles()) || in_array('ROLE_SUPERADMIN'$this->getRoles())) {
  435.             $roles array_merge(self::SUPERADMIN_ROLES$roles);
  436.         }
  437.         if (in_array('ROLE_ADMIN'$this->getRoles())) {
  438.             $roles array_merge(self::ADMIN_ROLES$roles);
  439.         }
  440.         if (in_array('ROLE_DIRECTEUR'$this->getRoles())) {
  441.             $roles array_merge(self::DIRECTEUR_ROLES$roles);
  442.         }
  443.         if (in_array('ROLE_RESPONSABLE'$this->getRoles())) {
  444.             $roles array_merge(self::RESPONSABLE_ROLES$roles);
  445.         }
  446.         return $roles;
  447.     }
  448.     /**
  449.      * @return Collection<int, Programme>
  450.      */
  451.     public function getPrescripteurProgrammes(): Collection
  452.     {
  453.         return $this->prescripteurProgrammes;
  454.     }
  455.     public function addPrescripteurProgramme(Programme $prescripteurProgramme): self
  456.     {
  457.         if (!$this->prescripteurProgrammes->contains($prescripteurProgramme)) {
  458.             $this->prescripteurProgrammes[] = $prescripteurProgramme;
  459.             $prescripteurProgramme->setPrescripteur($this);
  460.         }
  461.         return $this;
  462.     }
  463.     public function removePrescripteurProgramme(Programme $prescripteurProgramme): self
  464.     {
  465.         if ($this->prescripteurProgrammes->removeElement($prescripteurProgramme)) {
  466.             // set the owning side to null (unless already changed)
  467.             if ($prescripteurProgramme->getPrescripteur() === $this) {
  468.                 $prescripteurProgramme->setPrescripteur(null);
  469.             }
  470.         }
  471.         return $this;
  472.     }
  473.     public function getPrescripteurCoordonneesResponsable(): ?string
  474.     {
  475.         return $this->prescripteurCoordonneesResponsable;
  476.     }
  477.     public function setPrescripteurCoordonneesResponsable(?string $prescripteurCoordonneesResponsable): self
  478.     {
  479.         $this->prescripteurCoordonneesResponsable $prescripteurCoordonneesResponsable;
  480.         return $this;
  481.     }
  482.     /**
  483.      * @return Collection<int, InfosSuivi>
  484.      */
  485.     public function getInfosSuivis(): Collection
  486.     {
  487.         return $this->infosSuivis;
  488.     }
  489.     public function addInfosSuivi(InfosSuivi $infosSuivi): self
  490.     {
  491.         if (!$this->infosSuivis->contains($infosSuivi)) {
  492.             $this->infosSuivis[] = $infosSuivi;
  493.             $infosSuivi->setUtilisateur($this);
  494.         }
  495.         return $this;
  496.     }
  497.     public function removeInfosSuivi(InfosSuivi $infosSuivi): self
  498.     {
  499.         if ($this->infosSuivis->removeElement($infosSuivi)) {
  500.             // set the owning side to null (unless already changed)
  501.             if ($infosSuivi->getUtilisateur() === $this) {
  502.                 $infosSuivi->setUtilisateur(null);
  503.             }
  504.         }
  505.         return $this;
  506.     }
  507.     /**
  508.      * @return Collection<int, ActionTrace>
  509.      */
  510.     public function getActionTraces(): Collection
  511.     {
  512.         return $this->actionTraces;
  513.     }
  514.     public function addActionTrace(ActionTrace $actionTrace): self
  515.     {
  516.         if (!$this->actionTraces->contains($actionTrace)) {
  517.             $this->actionTraces[] = $actionTrace;
  518.             $actionTrace->setUser($this);
  519.         }
  520.         return $this;
  521.     }
  522.     public function removeActionTrace(ActionTrace $actionTrace): self
  523.     {
  524.         if ($this->actionTraces->removeElement($actionTrace)) {
  525.             // set the owning side to null (unless already changed)
  526.             if ($actionTrace->getUser() === $this) {
  527.                 $actionTrace->setUser(null);
  528.             }
  529.         }
  530.         return $this;
  531.     }
  532.     public function getPeutModifier(): ?bool
  533.     {
  534.         return $this->peutModifier;
  535.     }
  536.     public function setPeutModifier(bool $peutModifier): self
  537.     {
  538.         $this->peutModifier $peutModifier;
  539.         return $this;
  540.     }
  541.     public function isPeutModifier(): ?bool
  542.     {
  543.         return $this->peutModifier;
  544.     }
  545.     /**
  546.      * Méthode pour vérifier si l'utilisateur peut modifier les lots et programmes
  547.      */
  548.     public function peutModifierContenu(): bool
  549.     {
  550.         if (in_array('ROLE_SUPERADMIN'$this->getRoles()) ||
  551.             in_array('ROLE_ADMIN'$this->getRoles()) ||
  552.             in_array('ROLE_DIRECTEUR'$this->getRoles()) ||
  553.             in_array('ROLE_SAISIE'$this->getRoles())) {
  554.             return true;
  555.         }
  556.         if (in_array('ROLE_COMMERCIAL'$this->getRoles()) ||
  557.             in_array('ROLE_PARTENAIRE'$this->getRoles())) {
  558.             return $this->getPeutModifier();
  559.         }
  560.         return false;
  561.     }
  562. }