src/Entity/Gestiform/Users/Formateur.php line 25

  1. <?php
  2. namespace App\Entity\Gestiform\Users;
  3. use App\Entity\Gestiform\Admin\Entretien\Entretien;
  4. use DateTime;
  5. use JsonException;
  6. use App\Entity\Common\Adresse;
  7. use App\Entity\Common\Upload;
  8. use App\Entity\Gestiform\Admin\MasterListe\Masterlistelg;
  9. use App\Entity\Gestiform\Formations\Catalogue\Parcours\Parcours;
  10. use App\Entity\Gestiform\Formations\Dossier\HistoriqueComment;
  11. use App\Entity\Gestiform\Formations\Entreprise\Contrat;
  12. use App\Entity\Gestiform\Formations\Entreprise\Entreprise;
  13. use App\Entity\Gestiform\Formations\Entreprise\FormateurEntreprise;
  14. use App\Entity\Gestiform\Formations\Formateur\FormateurModule;
  15. use App\Entity\Gestiform\Formations\Session\FormateurEvent;
  16. use App\Entity\Gestiform\Formations\Session\Planning\ApprenantLivrable;
  17. use App\Entity\Gestiform\Formations\Session\Planning\LignePrestation;
  18. use App\Repository\Gestiform\Users\FormateurRepository;
  19. use Doctrine\Common\Collections\ArrayCollection;
  20. use Doctrine\Common\Collections\Collection;
  21. use Doctrine\ORM\Mapping as ORM;
  22. #[ORM\Entity(repositoryClassFormateurRepository::class)]
  23. class Formateur extends Personne
  24. {
  25.     #[ORM\Column(type'string'length255nullabletrue)]
  26.     private ?string $prefecture null;
  27.     #[ORM\Column(type'string'length255nullabletrue)]
  28.     private ?string $numeroActivite null;
  29.     #[ORM\Column(type'string'length255nullabletrue)]
  30.     private ?string $numeroActivite2 null;
  31.     #[ORM\Column(type'string'nullabletrue)]
  32.     private ?string $listeCompetences null;
  33.     #[ORM\Column(type'datetime'nullabletrue)]
  34.     private ?DateTime $debutHabilitation null;
  35.     #[ORM\Column(type'datetime'nullabletrue)]
  36.     private ?DateTime $finHabilitation null;
  37.     #[ORM\Column(type'boolean'nullabletrue)]
  38.     private ?bool $juryUniquement null;
  39.     #[ORM\JoinColumn(nullabletrue)]
  40.     #[ORM\ManyToOne(targetEntityMasterlistelg::class)]
  41.     private ?Masterlistelg $statut null;
  42.     #[ORM\OneToMany(targetEntityFormateurModule::class, mappedBy'formateur'cascade: ['persist'])]
  43.     private Collection $formateurModules;
  44.     #[ORM\ManyToMany(targetEntityParcours::class, inversedBy'formateurs')]
  45.     #[ORM\JoinTable(name'formateur_parcours')]
  46.     private Collection $parcoursRNCP;
  47.     #[ORM\OneToMany(targetEntityFormateurEntreprise::class, mappedBy'formateur'cascade: ['persist'])]
  48.     private Collection $formateurEntreprises;
  49.     #[ORM\ManyToMany(targetEntityContrat::class, mappedBy'formateurs'cascade: ['persist'])]
  50.     private Collection $contrats;
  51.     #[ORM\ManyToMany(targetEntityLignePrestation::class, mappedBy'formateurs'cascade: ['all'])]
  52.     private Collection $lignePrestations;
  53.     #[ORM\OneToMany(targetEntityFormateurEvent::class, mappedBy'formateur'cascade: ['all'])]
  54.     private Collection $formateurEvents;
  55.     #[ORM\Column(type'text'nullabletrue)]
  56.     private ?string $missionProposee null;
  57.     #[ORM\OneToMany(targetEntityApprenantLivrable::class, mappedBy'formateur'cascade: ['persist'])]
  58.     private Collection $apprenantLivrables;
  59.     #[ORM\OneToMany(targetEntityHistoriqueComment::class, mappedBy'formateur'cascade: ['all'])]
  60.     private Collection $historiqueComments;
  61.     public function __construct()
  62.     {
  63.         parent::__construct();
  64.         $this->formateurModules = new ArrayCollection();
  65.         $this->formateurEntreprises = new ArrayCollection();
  66.         $this->formateurEvents = new ArrayCollection();
  67.         $this->contrats = new ArrayCollection();
  68.         $this->lignePrestations = new ArrayCollection();
  69.         $this->apprenantLivrables = new ArrayCollection();
  70.         $this->historiqueComments = new ArrayCollection();
  71.         $this->parcoursRNCP = new ArrayCollection();
  72.     }
  73.     public function getJuryUniquement(): ?bool
  74.     {
  75.         return $this->juryUniquement;
  76.     }
  77.     public function setJuryUniquement(?bool $juryUniquement): self
  78.     {
  79.         $this->juryUniquement $juryUniquement;
  80.         return $this;
  81.     }
  82.     public function getListeCompetences(): ?string
  83.     {
  84.         return $this->listeCompetences;
  85.     }
  86.     public function setListeCompetences(?string $listeCompetences): self
  87.     {
  88.         $this->listeCompetences $listeCompetences;
  89.         return $this;
  90.     }
  91.     public function getStatut(): ?Masterlistelg
  92.     {
  93.         return $this->statut;
  94.     }
  95.     public function setStatut(?Masterlistelg $statut): self
  96.     {
  97.         $this->statut $statut;
  98.         return $this;
  99.     }
  100.     /**
  101.      * @return Collection<int, FormateurModule>
  102.      */
  103.     public function getFormateurModules(): Collection
  104.     {
  105.         return $this->formateurModules;
  106.     }
  107.     public function addFormateurModule(FormateurModule $formateurModule): self
  108.     {
  109.         if (!$this->formateurModules->contains($formateurModule)) {
  110.             $this->formateurModules->add($formateurModule);
  111.             $formateurModule->setFormateur($this);
  112.         }
  113.         return $this;
  114.     }
  115.     public function removeFormateurModule(FormateurModule $formateurModule): self
  116.     {
  117.         // set the owning side to null (unless already changed)
  118.         if ($this->formateurModules->removeElement($formateurModule) && $formateurModule->getFormateur() === $this) {
  119.             $formateurModule->setFormateur(null);
  120.         }
  121.         return $this;
  122.     }
  123.     /**
  124.      * @return Collection<int, FormateurEntreprise>
  125.      */
  126.     public function getFormateurEntreprises(): Collection
  127.     {
  128.         return $this->formateurEntreprises;
  129.     }
  130.     public function addFormateurEntreprise(FormateurEntreprise $formateurEntreprise): self
  131.     {
  132.         if (!$this->formateurEntreprises->contains($formateurEntreprise)) {
  133.             $this->formateurEntreprises->add($formateurEntreprise);
  134.             $formateurEntreprise->setFormateur($this);
  135.         }
  136.         return $this;
  137.     }
  138.     public function removeFormateurEntreprise(FormateurEntreprise $formateurEntreprise): self
  139.     {
  140.         // set the owning side to null (unless already changed)
  141.         if ($this->formateurEntreprises->removeElement($formateurEntreprise) && $formateurEntreprise->getFormateur() === $this) {
  142.             $formateurEntreprise->setFormateur(null);
  143.         }
  144.         return $this;
  145.     }
  146.     public function getEntreprise(): ?Entreprise
  147.     {
  148.         $formateurEntreprises $this->getFormateurEntreprises();
  149.         if ($formateurEntreprises->isEmpty()) {
  150.             return null;
  151.         }
  152.         $firstRelation $formateurEntreprises->first();
  153.         return $firstRelation $firstRelation->getEntreprise() : null;
  154.     }
  155.     public function getPrefecture(): ?string
  156.     {
  157.         return $this->prefecture;
  158.     }
  159.     public function setPrefecture(?string $prefecture): self
  160.     {
  161.         $this->prefecture $prefecture;
  162.         return $this;
  163.     }
  164.     public function getNumeroActivite(): ?string
  165.     {
  166.         return $this->numeroActivite;
  167.     }
  168.     public function setNumeroActivite(?string $numeroActivite): self
  169.     {
  170.         $this->numeroActivite $numeroActivite;
  171.         return $this;
  172.     }
  173.     public function getNumeroActivite2(): ?string
  174.     {
  175.         return $this->numeroActivite2;
  176.     }
  177.     public function setNumeroActivite2(?string $numeroActivite2): Formateur
  178.     {
  179.         $this->numeroActivite2 $numeroActivite2;
  180.         return $this;
  181.     }
  182.     /**
  183.      * @return Collection<int, FormateurEvent>
  184.      */
  185.     public function getFormateurEvents(): Collection
  186.     {
  187.         return $this->formateurEvents;
  188.     }
  189.     public function addFormateurEvent(FormateurEvent $formateurEvent): self
  190.     {
  191.         if (!$this->formateurEvents->contains($formateurEvent)) {
  192.             $this->formateurEvents->add($formateurEvent);
  193.             $formateurEvent->setFormateur($this);
  194.         }
  195.         return $this;
  196.     }
  197.     public function removeFormateurEvent(FormateurEvent $formateurEvent): self
  198.     {
  199.         // set the owning side to null (unless already changed)
  200.         if ($this->formateurEvents->removeElement($formateurEvent) && $formateurEvent->getFormateur() === $this) {
  201.             $formateurEvent->setFormateur(null);
  202.         }
  203.         return $this;
  204.     }
  205.     public function getMissionProposee()
  206.     {
  207.         if ($this->missionProposee === null) {
  208.             return [];
  209.         }
  210.         return json_decode($this->missionProposeetrue512JSON_THROW_ON_ERROR);
  211.     }
  212.     /**
  213.      * @throws JsonException
  214.      */
  215.     public function addMissionProposee(string $idstring $title$state null$sevent = []): self
  216.     {
  217.         $missionProposee = [];
  218.         if (!empty($this->missionProposee)) {
  219.             try {
  220.                 $missionProposee json_decode($this->missionProposeetrue512JSON_THROW_ON_ERROR);
  221.             } catch (\JsonException $e) {
  222.                 dump($e->getMessage());
  223.                 $missionProposee = [];
  224.             }
  225.         }
  226.         $exist false;
  227.         foreach ($missionProposee as &$item) {
  228.             if ($item['id'] === $id) {
  229.                 $item['title'] = $title;
  230.                 $item['state'] = $state;
  231.                 $exist true;
  232.                 break;
  233.             }
  234.         }
  235.         if (!$exist) {
  236.             $missionProposee[] = [
  237.                 'id'    => $id,
  238.                 'title' => $title,
  239.                 'state' => $state,
  240.                 'week'  => $sevent['week'] ?? null,
  241.                 'start' => $sevent['start'] ?? null,
  242.                 'end'   => $sevent['end'] ?? null,
  243.             ];
  244.         }
  245.         $this->missionProposee json_encode($missionProposeeJSON_THROW_ON_ERROR);
  246.         return $this;
  247.     }
  248.     /**
  249.      * @throws JsonException
  250.      */
  251.     public function removeMissionProposee(string $idEvent): self
  252.     {
  253.         $missionProposee = [];
  254.         if (!empty($this->missionProposee)) {
  255.             try {
  256.                 $missionProposee json_decode($this->missionProposeetrue512JSON_THROW_ON_ERROR);
  257.             } catch (\JsonException $e) {
  258.                 dump($e->getMessage());
  259.                 $missionProposee = [];
  260.             }
  261.         }
  262.         foreach ($missionProposee as $key => $item) {
  263.             if (($item['id'] ?? null) === $idEvent) {
  264.                 unset($missionProposee[$key]);
  265.             }
  266.         }
  267.         // Réindexation du tableau
  268.         $this->missionProposee json_encode(array_values($missionProposee), JSON_THROW_ON_ERROR);
  269.         return $this;
  270.     }
  271.     public function setMissionProposee(?string $missionProposee): self
  272.     {
  273.         $this->missionProposee $missionProposee;
  274.         return $this;
  275.     }
  276.     /**
  277.      * @throws JsonException
  278.      */
  279.     public function getMissionProposeeById(string $id)
  280.     {
  281.         $missionProposee json_decode((string) $this->missionProposeetrue512JSON_THROW_ON_ERROR) ?? [];
  282.         foreach ($missionProposee as $item) {
  283.             if ($item['id'] === $id) {
  284.                 return $item;
  285.             }
  286.         }
  287.         return null;
  288.     }
  289.     /**
  290.      * @return Collection<int, Contrat>
  291.      */
  292.     public function getContrats(): Collection
  293.     {
  294.         return $this->contrats;
  295.     }
  296.     public function addContrat(Contrat $contrat): self
  297.     {
  298.         if (!$this->contrats->contains($contrat)) {
  299.             $this->contrats->add($contrat);
  300.             $contrat->addFormateur($this);
  301.         }
  302.         return $this;
  303.     }
  304.     public function removeContrat(Contrat $contrat): self
  305.     {
  306.         if ($this->contrats->removeElement($contrat)) {
  307.             $contrat->removeFormateur($this);
  308.         }
  309.         return $this;
  310.     }
  311.     /**
  312.      * @return Collection<int, LignePrestation>
  313.      */
  314.     public function getLignePrestations(): Collection
  315.     {
  316.         return $this->lignePrestations;
  317.     }
  318.     public function addLignePrestation(LignePrestation $lignePrestation): self
  319.     {
  320.         if (!$this->lignePrestations->contains($lignePrestation)) {
  321.             $this->lignePrestations->add($lignePrestation);
  322.             $lignePrestation->addFormateur($this);
  323.         }
  324.         return $this;
  325.     }
  326.     public function removeLignePrestation(LignePrestation $lignePrestation): self
  327.     {
  328.         if ($this->lignePrestations->removeElement($lignePrestation)) {
  329.             $lignePrestation->removeFormateur($this);
  330.         }
  331.         return $this;
  332.     }
  333.     /**
  334.      * @throws JsonException
  335.      */
  336.     public function verifMissionProposee(string $id): bool
  337.     {
  338.         // Si aucun JSON stocké, aucune mission proposée
  339.         if (empty($this->missionProposee)) {
  340.             return false;
  341.         }
  342.         // Tolérer un JSON éventuellement corrompu
  343.         try {
  344.             $missionProposee json_decode((string) $this->missionProposeetrue512JSON_THROW_ON_ERROR) ?? [];
  345.         } catch (JsonException $e) {
  346.             // En cas de JSON invalide, on considère qu'il n'y a pas de mission correspondante
  347.             return false;
  348.         }
  349.         $exist false;
  350.         foreach ($missionProposee as &$item) {
  351.             if ($item['id'] === $id) {
  352.                 $exist true;
  353.             }
  354.         }
  355.         return $exist;
  356.     }
  357.     /**
  358.      * @return Collection<int, ApprenantLivrable>
  359.      */
  360.     public function getApprenantLivrables(): Collection
  361.     {
  362.         return $this->apprenantLivrables;
  363.     }
  364.     public function addApprenantLivrable(ApprenantLivrable $apprenantLivrable): self
  365.     {
  366.         if (!$this->apprenantLivrables->contains($apprenantLivrable)) {
  367.             $this->apprenantLivrables->add($apprenantLivrable);
  368.             $apprenantLivrable->setFormateur($this);
  369.         }
  370.         return $this;
  371.     }
  372.     public function removeApprenantLivrable(ApprenantLivrable $apprenantLivrable): self
  373.     {
  374.         // set the owning side to null (unless already changed)
  375.         if ($this->apprenantLivrables->removeElement($apprenantLivrable) && $apprenantLivrable->getFormateur() === $this) {
  376.             $apprenantLivrable->setFormateur(null);
  377.         }
  378.         return $this;
  379.     }
  380.     /**
  381.      * @return Collection<int, HistoriqueComment>
  382.      */
  383.     public function getHistoriqueComments(): Collection
  384.     {
  385.         return $this->historiqueComments;
  386.     }
  387.     public function addHistoriqueComment(HistoriqueComment $historiqueComment): self
  388.     {
  389.         if (!$this->historiqueComments->contains($historiqueComment)) {
  390.             $this->historiqueComments->add($historiqueComment);
  391.             $historiqueComment->setFormateur($this);
  392.         }
  393.         return $this;
  394.     }
  395.     public function removeHistoriqueComment(HistoriqueComment $historiqueComment): self
  396.     {
  397.         // set the owning side to null (unless already changed)
  398.         if ($this->historiqueComments->removeElement($historiqueComment) && $historiqueComment->getFormateur() === $this) {
  399.             $historiqueComment->setFormateur($this);
  400.         }
  401.         return $this;
  402.     }
  403.     public function getDebutHabilitation(): ?DateTime
  404.     {
  405.         return $this->debutHabilitation;
  406.     }
  407.     public function setDebutHabilitation(?DateTime $debutHabilitation): self
  408.     {
  409.         $this->debutHabilitation $debutHabilitation;
  410.         return $this;
  411.     }
  412.     public function getFinHabilitation(): ?DateTime
  413.     {
  414.         return $this->finHabilitation;
  415.     }
  416.     public function setFinHabilitation(?DateTime $finHabilitation): self
  417.     {
  418.         $this->finHabilitation $finHabilitation;
  419.         return $this;
  420.     }
  421.     public function isJuryUniquement(): ?bool
  422.     {
  423.         return $this->juryUniquement;
  424.     }
  425.     /**
  426.      * @return Collection<int, Parcours>
  427.      */
  428.     public function getParcoursRNCP(): Collection
  429.     {
  430.         return $this->parcoursRNCP;
  431.     }
  432.     public function addParcoursRNCP(Parcours $parcoursRNCP): self
  433.     {
  434.         if (!$this->parcoursRNCP->contains($parcoursRNCP)) {
  435.             $this->parcoursRNCP->add($parcoursRNCP);
  436.             $parcoursRNCP->setFormateur($this);
  437.         }
  438.         return $this;
  439.     }
  440.     public function removeParcoursRNCP(Parcours $parcoursRNCP): self
  441.     {
  442.         // set the owning side to null (unless already changed)
  443.         if ($this->parcoursRNCP->removeElement($parcoursRNCP) && $parcoursRNCP->getFormateur() === $this) {
  444.             $parcoursRNCP->setFormateur(null);
  445.         }
  446.         return $this;
  447.     }
  448.     public function getEntretienValider(): ?Entretien
  449.     {
  450.         $entretiens $this->getEntretiens()->toArray();
  451.         return array_reduce($entretiens,
  452.             static fn(?Entretien $carryEntretien $e) =>
  453.             $e->isStatut() && (!$carry || $e->getId() > $carry->getId()) ? $e $carry,
  454.             null
  455.         );
  456.     }
  457. }