diff --git a/module/Intervenant/src/Controller/StatutController.php b/module/Intervenant/src/Controller/StatutController.php index ceb0db5666c4591b09b3a4db5842acbeff6d1e1a..083aab5e2dba7becb294906dc26bd3d9840a3206 100755 --- a/module/Intervenant/src/Controller/StatutController.php +++ b/module/Intervenant/src/Controller/StatutController.php @@ -72,17 +72,14 @@ class StatutController extends AbstractController $title = $statut->getLibelle(); } - $plafonds = $this->getServicePlafond()->getPlafondsConfig($statut); - $canEdit = $this->isAllowed($statut, Privileges::INTERVENANT_STATUT_EDITION); if ($canEdit) { $request = $this->getRequest(); - $form->bindRequestSave($statut, $request, function (Statut $si) use ($plafonds, $request) { + $form->bindRequestSave($statut, $request, function (Statut $si) use ($request) { $isNew = !$si->getId(); $this->getServiceStatut()->save($si); - $this->getFormPlafondConfig()->requestSaveConfigs($plafonds, $request); + $this->getFormPlafondConfig()->requestSaveConfigs($si, $request); unset($this->getCacheContainer(RoleProvider::class)->statutsInfo); - $plafonds = $this->getServicePlafond()->getPlafondsConfig($si); $this->flashMessenger()->addSuccessMessage('Enregistrement effectué'); if ($isNew) { $this->redirect()->toRoute('statut/saisie', ['statut' => $si->getId()]); @@ -95,7 +92,7 @@ class StatutController extends AbstractController $vm = new ViewModel(); $vm->setTemplate('intervenant/statut/saisie'); - $vm->setVariables(compact('typesIntervenants', 'canEdit', 'statut', 'statuts', 'form', 'title', 'plafonds')); + $vm->setVariables(compact('typesIntervenants', 'canEdit', 'statut', 'statuts', 'form', 'title')); return $vm; } diff --git a/module/Intervenant/view/intervenant/statut/saisie.phtml b/module/Intervenant/view/intervenant/statut/saisie.phtml index 89213f7aed35cd97441f33ab901553b6cbb942db..df67aef4387c81d06143e34bac38073a2dac5dd2 100755 --- a/module/Intervenant/view/intervenant/statut/saisie.phtml +++ b/module/Intervenant/view/intervenant/statut/saisie.phtml @@ -9,7 +9,6 @@ use Application\Provider\Privilege\Privileges; * @var $statuts \Intervenant\Entity\Db\Statut[] * @var $statut \Intervenant\Entity\Db\Statut * @var $form \Intervenant\Form\StatutSaisieForm - * @var $plafonds \Plafond\Interfaces\PlafondConfigInterface[] * @var $title string */ diff --git a/module/Plafond/src/Entity/Db/Plafond.php b/module/Plafond/src/Entity/Db/Plafond.php index accf3ef64d41118ee66cc7bcd256958924f608fd..cd56c408df9ee4a3b1b27a77866019f0597321d4 100755 --- a/module/Plafond/src/Entity/Db/Plafond.php +++ b/module/Plafond/src/Entity/Db/Plafond.php @@ -4,6 +4,7 @@ namespace Plafond\Entity\Db; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; +use Plafond\Interfaces\PlafondConfigInterface; /** * Plafond @@ -154,6 +155,25 @@ class Plafond + public function addConfig(PlafondConfigInterface $plafondConfig): self + { + if ($plafondConfig->getPlafond() !== $this) { + throw new \Exception('Mauvais plafond transmis'); + } + + if ($plafondConfig instanceof PlafondStatut) { + $this->plafondStatut->add($plafondConfig); + } elseif ($plafondConfig instanceof PlafondStructure) { + $this->plafondStructure->add($plafondConfig); + } elseif ($plafondConfig instanceof PlafondReferentiel) { + $this->plafondReferentiel->add($plafondConfig); + } + + return $this; + } + + + /** * The __toString method allows a class to decide how it will react when it is converted to a string. * diff --git a/module/Plafond/src/Form/PlafondConfigForm.php b/module/Plafond/src/Form/PlafondConfigForm.php index 20df24fc21968e6d5ace7a71f714524a38b896b3..e211adb4420c409c70d24d291a2cfe05ede3a756 100755 --- a/module/Plafond/src/Form/PlafondConfigForm.php +++ b/module/Plafond/src/Form/PlafondConfigForm.php @@ -2,7 +2,10 @@ namespace Plafond\Form; +use Application\Entity\Db\FonctionReferentiel; +use Application\Entity\Db\Structure; use Application\Form\AbstractForm; +use Intervenant\Entity\Db\Statut; use Laminas\Form\Element; use Laminas\Http\Request; use Plafond\Entity\Db\Plafond; @@ -126,12 +129,14 @@ class PlafondConfigForm extends AbstractForm * * @return void */ - public function requestSaveConfigs(array $plafondConfigs, Request $request) + public function requestSaveConfigs(Statut|Structure|FonctionReferentiel $entity, Request $request) { $heures = $request->getPost('heures', []); $etatPrevu = $request->getPost('plafondEtatPrevu', []); $etatRealise = $request->getPost('plafondEtatRealise', []); + $plafondConfigs = $this->getServicePlafond()->getPlafondsConfig($entity); + foreach ($plafondConfigs as $plafondConfig) { if (isset($heures[$plafondConfig->getPlafond()->getId()])) { $v = stringToFloat($heures[$plafondConfig->getPlafond()->getId()]); diff --git a/module/Plafond/src/Service/PlafondService.php b/module/Plafond/src/Service/PlafondService.php index 0df9cb206c0c9aeab8dd0f9843b902e25ac88ef5..bf97a66db653a49bc231ee5d3e2e03c43a0d0ace 100755 --- a/module/Plafond/src/Service/PlafondService.php +++ b/module/Plafond/src/Service/PlafondService.php @@ -614,7 +614,7 @@ class PlafondService extends AbstractEntityService if ($entity instanceof FonctionReferentiel) { return PlafondReferentiel::class; } - throw new \Exception("L'entité fournie ne permet pas e récupérer une configuration de plafond"); + throw new \Exception("L'entité fournie ne permet pas de récupérer une configuration de plafond"); } @@ -734,6 +734,9 @@ class PlafondService extends AbstractEntityService $plafondConfig->setEtatRealise($this->getEtat(PlafondEtat::DESACTIVE)); } + if (!$plafondConfig->getId()) { + $plafondConfig->getPlafond()->addConfig($plafondConfig); + } $this->getEntityManager()->persist($plafondConfig); $this->getEntityManager()->flush($plafondConfig);