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