diff --git a/module/Application/config/modulateur.config.php b/module/Application/config/modulateur.config.php index bcd95aec5098bf8367962a3430f517dc49f13f6f..ff697272ed243fb4a10f1876837e5e63768e22e1 100644 --- a/module/Application/config/modulateur.config.php +++ b/module/Application/config/modulateur.config.php @@ -76,9 +76,10 @@ return [ 'type-modulateur-structure-saisie' => [ 'type' => 'Segment', 'options' => [ - 'route' => '/type-modulateur-structure-saisie/:typeModulateur', + 'route' => '/type-modulateur-structure-saisie/:typeModulateur[/:typeModulateurStructure]', 'constraints' => [ 'typeModulateur' => '[0-9]*', + 'typeModulateurStructure' => '[0-9]*', ], 'defaults' => [ 'action' => 'type-modulateur-structure-saisie', diff --git a/module/Application/src/Application/Controller/ModulateurController.php b/module/Application/src/Application/Controller/ModulateurController.php index b2d800cf3cce800c4dd5c79cb07a36802b327773..f48fe7b03405e22f04c9369253cddde8bd3d10a9 100755 --- a/module/Application/src/Application/Controller/ModulateurController.php +++ b/module/Application/src/Application/Controller/ModulateurController.php @@ -42,15 +42,16 @@ class modulateurController extends AbstractController $this->em()->getFilters()->enable('historique')->init([ TypeModulateurStructure::class, ]); - $modulateurs = $this->getServiceModulateur()->getList(); - $typeModulateurs = $this->getServiceTypeModulateur()->getList(); + $anneeId = $this->getServiceContext()->getAnnee()->getId(); + $modulateurs = $this->getServiceModulateur()->getList(); + $typeModulateurs = $this->getServiceTypeModulateur()->getList(); $typeModulateurStructures = $this->getServiceTypeModulateurStructure()->getList(); - $role = $this->getServiceContext()->getSelectedIdentityRole(); - $structure = $role->getStructure(); + $role = $this->getServiceContext()->getSelectedIdentityRole(); + $structure = $role->getStructure(); - return compact('modulateurs', 'typeModulateurs','typeModulateurStructures','structure'); + return compact('modulateurs', 'typeModulateurs', 'typeModulateurStructures', 'structure', 'anneeId'); } @@ -142,47 +143,54 @@ class modulateurController extends AbstractController return new MessengerViewModel(compact('typeModulateur')); } + + + public function typeModulateurStructureSaisieAction() { /* @var $typeModulateurStructure typeModulateurStructure */ /* @var $typeModulateur typeModulateur */ $typeModulateur = $this->getEvent()->getParam('typeModulateur'); + $typeModulateurStructure = $this->getEvent()->getParam('typeModulateurStructure'); - $form = $this->getFormTypeModulateurStructureSaisie(); - // if (empty($typeModulateurStructure)) { - $title = 'Création d\'un nouveau Type de Modulateur de Structure'; + $form = $this->getFormTypeModulateurStructureSaisie(); + if (empty($typeModulateurStructure)) { + $title = 'Ajout d\'une structure pour le type de modulateur'; $typeModulateurStructure = $this->getServiceTypeModulateurStructure()->newEntity() ->setTypeModulateur($typeModulateur); - // } else { - //$title = 'Édition d\'un Type de Modulateur pour une structure'; - //} + } else { + $title = 'Édition d\'une sructure pour le type de modulateur'; + } $form->bindRequestSave($typeModulateurStructure, $this->getRequest(), function (typeModulateurStructure $tms) { - try { - $this->getServiceTypeModulateurStructure()->save($tms); - $this->flashMessenger()->addSuccessMessage('Enregistrement effectué'); - } catch (\Exception $e) { - $e = DbException::translate($e); - $this->flashMessenger()->addErrorMessage($e->getMessage() . ':' . $tms->getId().':'.$tms->getTypeModulateur()); - } + try{ + $this->getServiceTypeModulateurStructure()->save($tms); + $this->flashMessenger()->addSuccessMessage('Enregistrement effectué'); + } catch (\Exception $e) { + $e = DbException::translate($e); + $this->flashMessenger()->addErrorMessage($e->getMessage() . ':' . $tms->getId() . ':' . $tms->getTypeModulateur()); + } }); - return compact('form', 'title'); - } +return compact('form', 'title'); +} - public function typeModulateurStructureDeleteAction() - { - /* @var $typeModulateurStructure typeModulateurStructure */ - $typeModulateurStructure = $this->getEvent()->getParam('typeModulateurStructure'); - try { - $this->getServiceTypeModulateurStructure()->delete($typeModulateurStructure); - $this->flashMessenger()->addSuccessMessage("Type de Modulateur de structure supprimé avec succès."); - } catch (\Exception $e) { - $this->flashMessenger()->addErrorMessage(DbException::translate($e)->getMessage()); - } - return new MessengerViewModel(compact('typeModulateur')); + +public +function typeModulateurStructureDeleteAction() +{ + /* @var $typeModulateurStructure typeModulateurStructure */ + $typeModulateurStructure = $this->getEvent()->getParam('typeModulateurStructure'); + try { + $this->getServiceTypeModulateurStructure()->delete($typeModulateurStructure); + $this->flashMessenger()->addSuccessMessage("Type de Modulateur de structure supprimé avec succès."); + } catch (\Exception $e) { + $this->flashMessenger()->addErrorMessage(DbException::translate($e)->getMessage()); } + + return new MessengerViewModel(compact('typeModulateur')); +} } \ No newline at end of file diff --git a/module/Application/src/Application/Service/TypeModulateurStructureService.php b/module/Application/src/Application/Service/TypeModulateurStructureService.php index a555d31aec60742913a25b8e39cf580668b24897..2fcd6ebdfb469133b9f5513274e0fa262df34434 100644 --- a/module/Application/src/Application/Service/TypeModulateurStructureService.php +++ b/module/Application/src/Application/Service/TypeModulateurStructureService.php @@ -4,13 +4,14 @@ namespace Application\Service; use Application\Entity\Db\TypeModulateurStructure; use Application\Service\Traits\TypeModulateurStructureServiceAwareTrait; - +use Doctrine\ORM\QueryBuilder; /** * Description of TypeModulateurStructureService */ class TypeModulateurStructureService extends AbstractEntityService { -use TypeModulateurStructureServiceAwareTrait; + use TypeModulateurStructureServiceAwareTrait; + /** * Liste des types de modulateur par structure * @@ -43,4 +44,75 @@ use TypeModulateurStructureServiceAwareTrait; return 'tmd'; } + + + public function existe(TypeModulateurStructure $tms) + { + /* @var $tbltms typeModulateurStructure[] */ + /* @var $elt typeModulateurStructure */ + if (!$tms->getId()) { + $dql = " + SELECT + m + FROM + Application\Entity\Db\TypeModulateurStructure m + WHERE + m.histoDestruction IS NULL + AND m.typeModulateur = :typemodulateur + AND m.structure = :structure"; + + $query = $this->getEntityManager()->createQuery($dql); + } else { + $dql = " + SELECT + m + FROM + Application\Entity\Db\TypeModulateurStructure m + WHERE + m.histoDestruction IS NULL + AND m.id != :id + AND m.typeModulateur = :typemodulateur + AND m.structure = :structure"; + + $query = $this->getEntityManager()->createQuery($dql); + $query->setParameter('id', $tms->getId()); + } + $query->setParameter('typemodulateur', $tms->getTypeModulateur()); + $query->setParameter('structure', $tms->getStructure()); + $tbltms = $query->getResult(); + // recherche de doublon + $ok = true; + foreach ($tbltms as $elt) { + if (((!$elt->getAnneeDebut()) or (!$tms->getAnneeFin()) or ($elt->getAnneeDebut()->getId() <= $tms->getAnneeFin()->getId())) and ((!$elt->getAnneeFin()) + or (!$tms->getAnneeDebut()) or ($elt->getAnneeFin()->getId() >= $tms->getAnneeDebut()->getId()))) { + $ok = false; + } + } + + return $ok; + } + + + + /** + * @param TypeModulateurStructure $entity + * + * @return TypeModulateurStructure + */ + public function save($entity) + { + if (!$this->existe($entity)) { + throw new \Exception('Une règle existe déjà pour cet intervalle d\'années choisi dans cette composante!'); + } + + return parent::save($entity); + } + + public function getList( QueryBuilder $qb=null, $alias=null ) + { + list($qb,$alias) = $this->initQuery($qb, $alias); + $qb->addOrderBy("$alias.structure"); + $qb->addOrderBy("$alias.anneeDebut"); + return parent::getList($qb, $alias); + } } \ No newline at end of file diff --git a/module/Application/view/application/modulateur/index.phtml b/module/Application/view/application/modulateur/index.phtml index 40a921fd53d0cb1184b54b6551c40db94886de97..2d8d777a0e49569259c0d22efa3eb7c5e8cc3ed1 100644 --- a/module/Application/view/application/modulateur/index.phtml +++ b/module/Application/view/application/modulateur/index.phtml @@ -1,4 +1,6 @@ headTitle()->append("Modulateurs des taux horaires"); $canEdit = $this->isAllowed(Privileges::getResourceId(Privileges::MODULATEUR_EDITION)); ?> -

Modulateurs des taux horaires

+

Modulateurs des taux horaires +

isAllowed($tm, Privileges::MODULATEUR_VISUALISATION)) { ?> @@ -31,12 +34,11 @@ foreach ($typeModulateurs as $tm) { - + - @@ -54,6 +56,7 @@ foreach ($typeModulateurs as $tm) { +
@@ -70,47 +73,53 @@ foreach ($typeModulateurs as $tm) {
Saisie par ens:
getSaisieParEnseignant()) ?>
- - - getId() == $tms->getTypeModulateur()->getId()) { ?> - - - - +
- getAnneeDebut()) || ($tms->getAnneeFin())) { - if (!$tms->getAnneeDebut()) { - $infoBulle = ' à ' . $tms->getAnneeFin(); - } else { - if (!$tms->getAnneeFin()) { - $infoBulle = ' de ' . $tms->getAnneeDebut(); - } else $infoBulle = ' de ' . $tms->getAnneeDebut() . ' à ' . $tms->getAnneeFin(); - } - } else $infoBulle = ''; ?> - ' : '') . $tms->getStructure()->getLibelleCourt(); - echo($infoBulle ? '' : ''); - if ($canEdit) { ?> - - - - -
+ + getId() == $tms->getTypeModulateur()->getId()) && ((!$tms->getAnneeDebut()) || ($tms->getAnneeDebut()->getId() <= $anneeId)) && ((!$tms->getAnneeFin()) || ($tms->getAnneeFin()->getId() >= $anneeId))) { ?> + + + +
+ getAnneeDebut()) || ($tms->getAnneeFin())) { + if (!$tms->getAnneeDebut()) { + $infoBulle = ' à ' . $tms->getAnneeFin(); + } else { + if (!$tms->getAnneeFin()) { + $infoBulle = ' de ' . $tms->getAnneeDebut(); + } else $infoBulle = ' de ' . $tms->getAnneeDebut() . ' à ' . $tms->getAnneeFin(); + } + } else $infoBulle = ''; ?> + ' : '') . $tms->getStructure()->getLibelleCourt(); + echo($infoBulle ? '' : ''); + if ($canEdit) { ?> + + + + + + + +
- - + href="url('modulateur/type-modulateur-structure-saisie', ['typeModulateur' => $tm->getId()]) ?>" + title="Ajouter un type de modulateur pour une structure"> + +