diff --git a/module/Application/src/Application/Controller/ServiceController.php b/module/Application/src/Application/Controller/ServiceController.php index 69a6063ca00429cb8a645186f0297a0e44c3ba2d..3a70c498de0eb7b3aa9b206845c581d81d3c5602 100755 --- a/module/Application/src/Application/Controller/ServiceController.php +++ b/module/Application/src/Application/Controller/ServiceController.php @@ -443,7 +443,7 @@ class ServiceController extends AbstractController } catch (\Exception $e) { $this->flashMessenger()->addErrorMessage($this->translate($e)); } - $this->getProcessusPlafond()->endTransaction($service->getIntervenant(), $typeVolumeHoraire); + $this->getProcessusPlafond()->endTransaction($service->getIntervenant(), $typeVolumeHoraire, true); } return new MessengerViewModel; @@ -492,7 +492,7 @@ class ServiceController extends AbstractController $form->get('service')->setIntervenant($intervenant); $form->get('service')->removeUnusedElements(); - + $hDeb = $entity->getVolumeHoraireListe()->getHeures(); $request = $this->getRequest(); if ($request->isPost()) { $form->setData($request->getPost()); @@ -508,8 +508,11 @@ class ServiceController extends AbstractController } catch (\Exception $e) { $this->flashMessenger()->addErrorMessage($this->translate($e)); } - $this->getProcessusPlafond()->endTransaction($entity->getIntervenant(), $typeVolumeHoraire); + $hFin = $entity->getVolumeHoraireListe()->getHeures(); $this->updateTableauxBord($entity->getIntervenant()); + if (!$this->getProcessusPlafond()->endTransaction($entity->getIntervenant(), $typeVolumeHoraire, $hFin < $hDeb)) { + $this->updateTableauxBord($entity->getIntervenant()); + } } } else { $this->flashMessenger()->addErrorMessage('La validation du formulaire a échoué. L\'enregistrement des données n\'a donc pas été fait.'); diff --git a/module/Application/src/Application/Controller/ServiceReferentielController.php b/module/Application/src/Application/Controller/ServiceReferentielController.php index 2a896f2779e3853c9026a3767317c78ec775c232..c245e5db1be495bbf9a0416025d229ba625c3082 100755 --- a/module/Application/src/Application/Controller/ServiceReferentielController.php +++ b/module/Application/src/Application/Controller/ServiceReferentielController.php @@ -141,7 +141,7 @@ class ServiceReferentielController extends AbstractController if (!$this->isAllowed($assertionEntity, Privileges::REFERENTIEL_EDITION)) { throw new \LogicException("Cette opération n'est pas autorisée."); } - + $hDeb = $entity->getVolumeHoraireReferentielListe()->getHeures(); $request = $this->getRequest(); if ($request->isPost()) { $form->setData($request->getPost()); @@ -155,8 +155,11 @@ class ServiceReferentielController extends AbstractController } catch (\Exception $e) { $this->flashMessenger()->addErrorMessage($this->translate($e)); } - $this->getProcessusPlafond()->endTransaction($intervenant, $typeVolumeHoraire); + $hFin = $entity->getVolumeHoraireReferentielListe()->getHeures(); $this->updateTableauxBord($intervenant); + if (!$this->getProcessusPlafond()->endTransaction($intervenant, $typeVolumeHoraire, $hFin < $hDeb)) { + $this->updateTableauxBord($intervenant); + } } else { $this->flashMessenger()->addErrorMessage('La validation du formulaire a échoué. L\'enregistrement des données n\'a donc pas été fait.'); } @@ -219,7 +222,6 @@ class ServiceReferentielController extends AbstractController $this->getProcessusPlafond()->endTransaction($service->getIntervenant(), $typeVolumeHoraire); } } - } return new MessengerViewModel; @@ -255,7 +257,7 @@ class ServiceReferentielController extends AbstractController } catch (\Exception $e) { $this->flashMessenger()->addErrorMessage($this->translate($e)); } - $this->getProcessusPlafond()->endTransaction($service->getIntervenant(), $typeVolumeHoraire); + $this->getProcessusPlafond()->endTransaction($service->getIntervenant(), $typeVolumeHoraire, true); } return new MessengerViewModel; @@ -273,7 +275,7 @@ class ServiceReferentielController extends AbstractController $intervenant = $this->getEvent()->getParam('intervenant'); /* @var $intervenant Intervenant */ - if (!$intervenant){ + if (!$intervenant) { throw new \LogicException('Intervenant non précisé ou inexistant'); } @@ -342,7 +344,7 @@ class ServiceReferentielController extends AbstractController if ($this->getRequest()->isPost()) { try { $this->getProcessusValidationReferentiel()->enregistrer($typeVolumeHoraire, $validation); - $this->updateTableauxBord($intervenant,true); + $this->updateTableauxBord($intervenant, true); $this->flashMessenger()->addSuccessMessage( "Validation effectuée avec succès." ); @@ -370,7 +372,7 @@ class ServiceReferentielController extends AbstractController if ($this->getRequest()->isPost()) { try { $this->getProcessusValidationReferentiel()->supprimer($validation); - $this->updateTableauxBord($validation->getIntervenant(),true); + $this->updateTableauxBord($validation->getIntervenant(), true); $this->flashMessenger()->addSuccessMessage( "Dévalidation effectuée avec succès." ); @@ -387,11 +389,11 @@ class ServiceReferentielController extends AbstractController - private function updateTableauxBord(Intervenant $intervenant, $validation=false) + private function updateTableauxBord(Intervenant $intervenant, $validation = false) { - $this->getServiceWorkflow()->calculerTableauxBord(['formule','validation_referentiel','service_referentiel'], $intervenant); - if (!$validation){ - $this->getServiceWorkflow()->calculerTableauxBord(['service_saisie','piece_jointe_fournie'], $intervenant); + $this->getServiceWorkflow()->calculerTableauxBord(['formule', 'validation_referentiel', 'service_referentiel'], $intervenant); + if (!$validation) { + $this->getServiceWorkflow()->calculerTableauxBord(['service_saisie', 'piece_jointe_fournie'], $intervenant); } } diff --git a/module/Application/src/Application/Controller/VolumeHoraireController.php b/module/Application/src/Application/Controller/VolumeHoraireController.php index 082082668685cd58e0eeeefe0feac2742ab290ae..a03f6d6a575fb479e5c770651bc36f031e2fd160 100755 --- a/module/Application/src/Application/Controller/VolumeHoraireController.php +++ b/module/Application/src/Application/Controller/VolumeHoraireController.php @@ -86,6 +86,7 @@ class VolumeHoraireController extends AbstractController } $volumeHoraireListe = new VolumeHoraireListe($service); + $hDeb = $volumeHoraireListe->getHeures(); $vhlph = new ListeFilterHydrator(); $vhlph->setEntityManager($this->em()); $vhlph->hydrate($this->params()->fromQuery() + $this->params()->fromPost(), $volumeHoraireListe); @@ -97,17 +98,20 @@ class VolumeHoraireController extends AbstractController $form->setViewMNP($canViewMNP); $form->setEditMNP($canEditMNP); $form->build(); - $form->bindRequestSave($volumeHoraireListe, $this->getRequest(), function (VolumeHoraireListe $vhl) { + $form->bindRequestSave($volumeHoraireListe, $this->getRequest(), function (VolumeHoraireListe $vhl) use ($hDeb) { try { $service = $vhl->getService(); $this->getProcessusPlafond()->beginTransaction(); $this->getServiceService()->save($service); - $this->getProcessusPlafond()->endTransaction($service->getIntervenant(), $vhl->getTypeVolumeHoraire()); + $hFin = $vhl->getHeures(); + $this->updateTableauxBord($service->getIntervenant()); + if (!$this->getProcessusPlafond()->endTransaction($service->getIntervenant(), $vhl->getTypeVolumeHoraire(), $hFin < $hDeb)) { + $this->updateTableauxBord($service->getIntervenant()); + } $this->flashMessenger()->addSuccessMessage('Enregistrement effectué'); } catch (\Exception $e) { $this->flashMessenger()->addErrorMessage($this->translate($e)); } - $this->updateTableauxBord($service->getIntervenant()); }); return compact('form'); @@ -136,7 +140,7 @@ class VolumeHoraireController extends AbstractController $this->getProcessusPlafond()->beginTransaction(); $this->getServiceService()->save($service); $this->updateTableauxBord($service->getIntervenant()); - $this->getProcessusPlafond()->endTransaction($service->getIntervenant(), $volumeHoraireListe->getTypeVolumeHoraire()); + $this->getProcessusPlafond()->endTransaction($service->getIntervenant(), $volumeHoraireListe->getTypeVolumeHoraire(), true); $this->flashMessenger()->addSuccessMessage('Enregistrement effectué'); } catch (\Exception $e) { $this->flashMessenger()->addErrorMessage($this->translate($e)); diff --git a/module/Application/src/Application/Processus/PlafondProcessus.php b/module/Application/src/Application/Processus/PlafondProcessus.php index 6622203a0851d79a1ad799b9313f81d640dc4cb8..2511096d9e6a8d7853dbef2e7dc09f60a04b191e 100755 --- a/module/Application/src/Application/Processus/PlafondProcessus.php +++ b/module/Application/src/Application/Processus/PlafondProcessus.php @@ -55,16 +55,19 @@ class PlafondProcessus implements EntityManagerAwareInterface * * @return bool */ - public function endTransaction(Intervenant $intervenant, TypeVolumeHoraire $typeVolumeHoraire): bool + public function endTransaction(Intervenant $intervenant, TypeVolumeHoraire $typeVolumeHoraire, bool $isDiminution = false): bool { - $hasBloquant = $this->controle($intervenant, $typeVolumeHoraire, true); - if ($hasBloquant) { + $this->getEntityManager()->flush(); + $hasBloquant = $this->controle($intervenant, $typeVolumeHoraire, !$isDiminution); + if ($hasBloquant && !$isDiminution) { $this->getEntityManager()->rollback(); + + return false; } else { $this->getEntityManager()->commit(); - } - return $hasBloquant; + return true; + } } diff --git a/module/Application/src/Application/Service/ServiceService.php b/module/Application/src/Application/Service/ServiceService.php index fca03c0b847ea55b0b3d2595f299d4d3ca988f63..76c82e9511c512a16bb12bd5614f4211fa2e83ae 100755 --- a/module/Application/src/Application/Service/ServiceService.php +++ b/module/Application/src/Application/Service/ServiceService.php @@ -204,7 +204,7 @@ class ServiceService extends AbstractEntityService /** * Retourne un service unique selon ses critères précis * - * @param Intervenant $intervenant + * @param Intervenant $intervenant * @param ElementPedagogique $elementPedagogique * @param Etablissement $etablissement * @@ -243,8 +243,8 @@ class ServiceService extends AbstractEntityService * * @param Service $entity * - * @throws Exception * @return Service + * @throws Exception */ public function save($entity) { @@ -254,7 +254,7 @@ class ServiceService extends AbstractEntityService if (!$entity->getEtablissement()) { $entity->setEtablissement($this->getServiceContext()->getEtablissement()); - if (!$entity->getEtablissement()){ + if (!$entity->getEtablissement()) { throw new \LogicException('L\'établissement n\'est pas renseigné dans les paramétrages généraux de OSE'); } } @@ -278,17 +278,17 @@ class ServiceService extends AbstractEntityService } else { if ($entity->hasChanged()) { $sourceOse = $this->getServiceSource()->getOse(); - if (!$entity->getSource()){ + if (!$entity->getSource()) { $entity->setSource($sourceOse); } - if (!$entity->getSourceCode()){ + if (!$entity->getSourceCode()) { $entity->setSourceCode(uniqid('ose-')); } - foreach( $entity->getVolumeHoraire() as $vh ){ - if (!$vh->getSource()){ + foreach ($entity->getVolumeHoraire() as $vh) { + if (!$vh->getSource()) { $vh->setSource($sourceOse); } - if (!$vh->getSourceCode()){ + if (!$vh->getSourceCode()) { $vh->setSourceCode(uniqid('ose-')); } } @@ -334,8 +334,8 @@ class ServiceService extends AbstractEntityService { if ($softDelete) { $vhListe = $entity->getVolumeHoraireListe(); - $listes = $vhListe->getSousListes([$vhListe::FILTRE_PERIODE,$vhListe::FILTRE_TYPE_INTERVENTION, $vhListe::FILTRE_HORAIRE_DEBUT, $vhListe::FILTRE_HORAIRE_FIN]); - foreach ($listes as $liste){ + $listes = $vhListe->getSousListes([$vhListe::FILTRE_PERIODE, $vhListe::FILTRE_TYPE_INTERVENTION, $vhListe::FILTRE_HORAIRE_DEBUT, $vhListe::FILTRE_HORAIRE_FIN]); + foreach ($listes as $liste) { $liste->setHeures(0); } } @@ -366,7 +366,7 @@ class ServiceService extends AbstractEntityService /** * Retourne la liste des services selon l'étape donnée * - * @param Etape $etape + * @param Etape $etape * @param QueryBuilder|null $queryBuilder * * @return QueryBuilder @@ -375,7 +375,7 @@ class ServiceService extends AbstractEntityService { $serviceElement = $this->getServiceElementPedagogique(); - list($qb, $alias) = $this->initQuery($qb, $alias); + [$qb, $alias] = $this->initQuery($qb, $alias); $this->leftJoin($serviceElement, $qb, 'elementPedagogique'); $serviceElement->finderByEtape($etape, $qb); @@ -387,14 +387,14 @@ class ServiceService extends AbstractEntityService /** * Retourne la liste des services selon l'étape donnée * - * @param Etape $etape + * @param Etape $etape * @param QueryBuilder|null $queryBuilder * * @return QueryBuilder */ public function finderByNiveauEtape(NiveauEtape $niveauEtape, QueryBuilder $qb = null, $alias = null) { - list($qb, $alias) = $this->initQuery($qb, $alias); + [$qb, $alias] = $this->initQuery($qb, $alias); if ($niveauEtape && $niveauEtape->getId() !== '-') { $serviceElement = $this->getServiceElementPedagogique(); $serviceEtape = $this->getServiceEtape(); @@ -419,7 +419,7 @@ class ServiceService extends AbstractEntityService */ public function finderByTypeVolumeHoraire(TypeVolumeHoraire $typeVolumeHoraire, QueryBuilder $qb = null, $alias = null) { - list($qb, $alias) = $this->initQuery($qb, $alias); + [$qb, $alias] = $this->initQuery($qb, $alias); if ($typeVolumeHoraire) { $serviceVolumeHoraire = $this->getServiceVolumeHoraire(); @@ -442,7 +442,7 @@ class ServiceService extends AbstractEntityService */ public function finderByEtatVolumeHoraire(EtatVolumeHoraire $etatVolumeHoraire, QueryBuilder $qb = null, $alias = null) { - list($qb, $alias) = $this->initQuery($qb, $alias); + [$qb, $alias] = $this->initQuery($qb, $alias); if ($etatVolumeHoraire) { $serviceVolumeHoraire = $this->getServiceVolumeHoraire(); @@ -470,7 +470,7 @@ class ServiceService extends AbstractEntityService */ public function finderByComposante(Structure $structure, QueryBuilder $qb = null, $alias = null) { - list($qb, $alias) = $this->initQuery($qb, $alias); + [$qb, $alias] = $this->initQuery($qb, $alias); $serviceStructure = $this->getServiceStructure(); $serviceIntervenant = $this->getServiceIntervenant(); @@ -503,7 +503,7 @@ class ServiceService extends AbstractEntityService */ public function finderByStructureAff(Structure $structure, QueryBuilder $qb = null, $alias = null) { - list($qb, $alias) = $this->initQuery($qb, $alias); + [$qb, $alias] = $this->initQuery($qb, $alias); $serviceIntervenant = $this->getServiceIntervenant(); @@ -526,7 +526,7 @@ class ServiceService extends AbstractEntityService */ public function finderByStructureEns(Structure $structure, QueryBuilder $qb = null, $alias = null) { - list($qb, $alias) = $this->initQuery($qb, $alias); + [$qb, $alias] = $this->initQuery($qb, $alias); $serviceElementPedagogique = $this->getServiceElementPedagogique(); $this->join($serviceElementPedagogique, $qb, 'elementPedagogique', false, $alias); @@ -549,7 +549,7 @@ class ServiceService extends AbstractEntityService { $role = $this->getServiceContext()->getSelectedIdentityRole(); - list($qb, $alias) = $this->initQuery($qb, $alias); + [$qb, $alias] = $this->initQuery($qb, $alias); $this->join($this->getServiceIntervenant(), $qb, 'intervenant', false, $alias); $this->getServiceIntervenant()->finderByAnnee($this->getServiceContext()->getAnnee(), $qb); @@ -573,7 +573,7 @@ class ServiceService extends AbstractEntityService */ public function finderByTypeIntervenant(TypeIntervenant $typeIntervenant = null, QueryBuilder $qb = null, $alias = null) { - list($qb, $alias) = $this->initQuery($qb, $alias); + [$qb, $alias] = $this->initQuery($qb, $alias); if ($typeIntervenant) { $this->join($this->getServiceIntervenant(), $qb, 'intervenant', false, $alias); $this->getServiceIntervenant()->finderByType($typeIntervenant, $qb); @@ -1176,7 +1176,7 @@ class ServiceService extends AbstractEntityService /** * - * @param Service[] $services + * @param Service[] $services * @param TypeVolumeHoraire $typeVolumehoraire */ public function setTypeVolumehoraire($services, TypeVolumeHoraire $typeVolumeHoraire)