Skip to content
Snippets Groups Projects
Commit 7f8caf03 authored by Laurent Lecluse's avatar Laurent Lecluse
Browse files

Correction du problème de MAJ des valeurs des plafonds

parent 3c495ecc
No related branches found
No related tags found
No related merge requests found
...@@ -72,17 +72,14 @@ class StatutController extends AbstractController ...@@ -72,17 +72,14 @@ class StatutController extends AbstractController
$title = $statut->getLibelle(); $title = $statut->getLibelle();
} }
$plafonds = $this->getServicePlafond()->getPlafondsConfig($statut);
$canEdit = $this->isAllowed($statut, Privileges::INTERVENANT_STATUT_EDITION); $canEdit = $this->isAllowed($statut, Privileges::INTERVENANT_STATUT_EDITION);
if ($canEdit) { if ($canEdit) {
$request = $this->getRequest(); $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(); $isNew = !$si->getId();
$this->getServiceStatut()->save($si); $this->getServiceStatut()->save($si);
$this->getFormPlafondConfig()->requestSaveConfigs($plafonds, $request); $this->getFormPlafondConfig()->requestSaveConfigs($si, $request);
unset($this->getCacheContainer(RoleProvider::class)->statutsInfo); unset($this->getCacheContainer(RoleProvider::class)->statutsInfo);
$plafonds = $this->getServicePlafond()->getPlafondsConfig($si);
$this->flashMessenger()->addSuccessMessage('Enregistrement effectué'); $this->flashMessenger()->addSuccessMessage('Enregistrement effectué');
if ($isNew) { if ($isNew) {
$this->redirect()->toRoute('statut/saisie', ['statut' => $si->getId()]); $this->redirect()->toRoute('statut/saisie', ['statut' => $si->getId()]);
...@@ -95,7 +92,7 @@ class StatutController extends AbstractController ...@@ -95,7 +92,7 @@ class StatutController extends AbstractController
$vm = new ViewModel(); $vm = new ViewModel();
$vm->setTemplate('intervenant/statut/saisie'); $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; return $vm;
} }
......
...@@ -9,7 +9,6 @@ use Application\Provider\Privilege\Privileges; ...@@ -9,7 +9,6 @@ use Application\Provider\Privilege\Privileges;
* @var $statuts \Intervenant\Entity\Db\Statut[] * @var $statuts \Intervenant\Entity\Db\Statut[]
* @var $statut \Intervenant\Entity\Db\Statut * @var $statut \Intervenant\Entity\Db\Statut
* @var $form \Intervenant\Form\StatutSaisieForm * @var $form \Intervenant\Form\StatutSaisieForm
* @var $plafonds \Plafond\Interfaces\PlafondConfigInterface[]
* @var $title string * @var $title string
*/ */
......
...@@ -4,6 +4,7 @@ namespace Plafond\Entity\Db; ...@@ -4,6 +4,7 @@ namespace Plafond\Entity\Db;
use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\Collection;
use Plafond\Interfaces\PlafondConfigInterface;
/** /**
* Plafond * Plafond
...@@ -154,6 +155,25 @@ class 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. * The __toString method allows a class to decide how it will react when it is converted to a string.
* *
......
...@@ -2,7 +2,10 @@ ...@@ -2,7 +2,10 @@
namespace Plafond\Form; namespace Plafond\Form;
use Application\Entity\Db\FonctionReferentiel;
use Application\Entity\Db\Structure;
use Application\Form\AbstractForm; use Application\Form\AbstractForm;
use Intervenant\Entity\Db\Statut;
use Laminas\Form\Element; use Laminas\Form\Element;
use Laminas\Http\Request; use Laminas\Http\Request;
use Plafond\Entity\Db\Plafond; use Plafond\Entity\Db\Plafond;
...@@ -126,12 +129,14 @@ class PlafondConfigForm extends AbstractForm ...@@ -126,12 +129,14 @@ class PlafondConfigForm extends AbstractForm
* *
* @return void * @return void
*/ */
public function requestSaveConfigs(array $plafondConfigs, Request $request) public function requestSaveConfigs(Statut|Structure|FonctionReferentiel $entity, Request $request)
{ {
$heures = $request->getPost('heures', []); $heures = $request->getPost('heures', []);
$etatPrevu = $request->getPost('plafondEtatPrevu', []); $etatPrevu = $request->getPost('plafondEtatPrevu', []);
$etatRealise = $request->getPost('plafondEtatRealise', []); $etatRealise = $request->getPost('plafondEtatRealise', []);
$plafondConfigs = $this->getServicePlafond()->getPlafondsConfig($entity);
foreach ($plafondConfigs as $plafondConfig) { foreach ($plafondConfigs as $plafondConfig) {
if (isset($heures[$plafondConfig->getPlafond()->getId()])) { if (isset($heures[$plafondConfig->getPlafond()->getId()])) {
$v = stringToFloat($heures[$plafondConfig->getPlafond()->getId()]); $v = stringToFloat($heures[$plafondConfig->getPlafond()->getId()]);
......
...@@ -614,7 +614,7 @@ class PlafondService extends AbstractEntityService ...@@ -614,7 +614,7 @@ class PlafondService extends AbstractEntityService
if ($entity instanceof FonctionReferentiel) { if ($entity instanceof FonctionReferentiel) {
return PlafondReferentiel::class; 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 ...@@ -734,6 +734,9 @@ class PlafondService extends AbstractEntityService
$plafondConfig->setEtatRealise($this->getEtat(PlafondEtat::DESACTIVE)); $plafondConfig->setEtatRealise($this->getEtat(PlafondEtat::DESACTIVE));
} }
if (!$plafondConfig->getId()) {
$plafondConfig->getPlafond()->addConfig($plafondConfig);
}
$this->getEntityManager()->persist($plafondConfig); $this->getEntityManager()->persist($plafondConfig);
$this->getEntityManager()->flush($plafondConfig); $this->getEntityManager()->flush($plafondConfig);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment