diff --git a/module/Application/src/Application/Controller/FichePosteController.php b/module/Application/src/Application/Controller/FichePosteController.php index 06e4384a1fc312423c47681e75bf521041a98717..903b8ba0676fc521e7e644a02bff3106797cc088 100644 --- a/module/Application/src/Application/Controller/FichePosteController.php +++ b/module/Application/src/Application/Controller/FichePosteController.php @@ -127,7 +127,8 @@ class FichePosteController extends AbstractActionController { $structures = $this->getStructureService()->getStructuresFilles($structure); $structures[] = $structure; - $fiches = $this->getFichePosteService()->getFichesPostesByStructures($structures, true); +// $fiches = $this->getFichePosteService()->getFichesPostesByStructures($structures, true); + $fiches = $this->getFichePosteService()->getFichesPostesByStructuresAndAgent($structures, true, $agent); /** @var Request $request */ $request = $this->getRequest(); @@ -404,12 +405,15 @@ class FichePosteController extends AbstractActionController { public function ajouterFicheMetierAction() { $fiche = $this->getFichePosteService()->getRequestedFichePoste($this, 'fiche-poste'); + $agent = $fiche->getAgent(); $ficheTypeExterne = new FicheTypeExterne(); $form = $this->getAjouterFicheTypeForm(); $form->setAttribute('action', $this->url()->fromRoute('fiche-poste/ajouter-fiche-metier', ['fiche-poste' => $fiche->getId()], [], true)); $form->bind($ficheTypeExterne); + if ($agent AND ! empty($agent->getGradesActifs())) $form->reinitWithAgent($agent); + /** @var Request $request */ $request = $this->getRequest(); if ($request->isPost()) { diff --git a/module/Application/src/Application/Entity/Db/Agent.php b/module/Application/src/Application/Entity/Db/Agent.php index add3114d508bab48b869c8ca1cee84a90ae96a5d..e818dca9f97cfd7d731ae432bd2930cf14a0a314 100644 --- a/module/Application/src/Application/Entity/Db/Agent.php +++ b/module/Application/src/Application/Entity/Db/Agent.php @@ -440,4 +440,19 @@ class Agent implements ResourceInterface return false; } + + /** + * @return int + */ + public function getMeilleurNiveau() + { + $niveau = 999; + $grades = $this->getGradesActifs(); + foreach ($grades as $grade) { + $level = $grade->getCorps()->getNiveau(); + if ($level !== null and $level <= $niveau) $niveau = $level; + } + return $niveau; + + } } \ No newline at end of file diff --git a/module/Application/src/Application/Form/AjouterFicheMetier/AjouterFicheMetierForm.php b/module/Application/src/Application/Form/AjouterFicheMetier/AjouterFicheMetierForm.php index 4f706dc13b1cd92da6e17f2538de16813d78293f..a7378eb4ad0341ee6b67c853e7b800f2bf46e088 100644 --- a/module/Application/src/Application/Form/AjouterFicheMetier/AjouterFicheMetierForm.php +++ b/module/Application/src/Application/Form/AjouterFicheMetier/AjouterFicheMetierForm.php @@ -2,6 +2,7 @@ namespace Application\Form\AjouterFicheMetier; +use Application\Entity\Db\Agent; use Application\Entity\Db\FicheMetier; use Application\Entity\Db\MetierReference; use Application\Service\Domaine\DomaineServiceAwareTrait; @@ -156,4 +157,49 @@ class AjouterFicheMetierForm extends Form { return $options; } + + /** + * @param Agent $agent + */ + public function reinitWithAgent(Agent $agent) + { + /** @var Select $ficheSelect */ + $ficheSelect = $this->get('fiche_type'); + + $niveau = $agent->getMeilleurNiveau(); + + /** @var array $fiches */ + $fiches = $this->getFicheMetierService()->getFichesMetiersWithNiveau($niveau - 1); + + $options = []; + $dictionnaire = []; + foreach ($fiches as $ficheMetier) { + $domaines = $ficheMetier->getMetier()->getDomaines(); + foreach ($domaines as $domaine) { + $dictionnaire[($domaine) ? $domaine->getLibelle() : "Sans domaine"][] = $ficheMetier; + } + } + + ksort($dictionnaire); + foreach ($dictionnaire as $clef => $listing) { + $optionsoptions = []; + /** @var FicheMetier $fiche */ + foreach ($listing as $fiche) { + $references = []; + /** @var MetierReference $reference */ + foreach ($fiche->getMetier()->getReferences() as $reference) { + $references[] = $reference->getTitre(); + } + $str_references = implode(", ", $references); + $optionsoptions[$fiche->getId()] = $fiche->getMetier()->getLibelle() . (!empty($references)?" (".$str_references.")":"") ; + } + $array = [ + 'label' => $clef, + 'options' => $optionsoptions, + ]; + $options[] = $array; + } + + $ficheSelect->setValueOptions($options); + } } \ No newline at end of file diff --git a/module/Application/src/Application/Service/FicheMetier/FicheMetierService.php b/module/Application/src/Application/Service/FicheMetier/FicheMetierService.php index e353bc8fa4e29976a4271d79f745cd396e0b55c6..48ba24d9dd9d79e0323de9eba78c3acc30333fab 100644 --- a/module/Application/src/Application/Service/FicheMetier/FicheMetierService.php +++ b/module/Application/src/Application/Service/FicheMetier/FicheMetierService.php @@ -114,6 +114,21 @@ class FicheMetierService { return $result; } + /** + * @param int $niveau + * @return FicheMetier[] + */ + public function getFichesMetiersWithNiveau($niveau) + { + $qb = $this->createQueryBuilder() + ->andWhere('metier.niveau IS NULL or metier.niveau >= :niveau') + ->setParameter('niveau', $niveau) + ; + + $result = $qb->getQuery()->getResult(); + return $result; + } + /** * @param string $order an attribute use to sort * @return FicheMetier[] @@ -212,11 +227,12 @@ class FicheMetierService { } /** + * @param int $niveau * @return array */ - public function getFichesMetiersAsOptions() + public function getFichesMetiersAsOptions($niveau =0) { - $fiches = $this->getFichesMetiers(); + $fiches = $this->getFichesMetiersWithNiveau($niveau); $array = []; foreach ($fiches as $fiche) { $array[$fiche->getId()] = $fiche->getMetier()->getLibelle(); diff --git a/module/Application/src/Application/Service/FichePoste/FichePosteService.php b/module/Application/src/Application/Service/FichePoste/FichePosteService.php index d34e737fc4a6b9be8e4ab210bc67c38e23b40140..1827623486173b17d1f64335289f57c9e89d44a5 100644 --- a/module/Application/src/Application/Service/FichePoste/FichePosteService.php +++ b/module/Application/src/Application/Service/FichePoste/FichePosteService.php @@ -333,6 +333,27 @@ class FichePosteService { return $result; } + /** + * @param Structure[] $structures + * @param boolean $sousstructure + * @param Agent $agent + * @return FichePoste[] + */ + public function getFichesPostesByStructuresAndAgent($structures = [], $sousstructure = false, $agent = null) + { + $fiches = $this->getFichesPostesByStructures($structures, $sousstructure); + $niveau = $agent->getMeilleurNiveau(); + + if ($niveau === 999) return $fiches; + + $result = []; + foreach ($fiches as $fiche) { + if ($fiche->isComplete() AND $fiche->getAgent()->getMeilleurNiveau() >= ($niveau - 1)) $result[] = $fiche; + } + + return $result; + } + /** * @param Structure $structure * @param boolean $sousstructure