From d10cea53124b0183be7d6e0fc960483ebc488d4c Mon Sep 17 00:00:00 2001 From: Jean-Philippe Metivier <jean-philippe.metivier@unicaen.fr> Date: Mon, 18 Nov 2024 11:20:06 +0100 Subject: [PATCH] Revoquer remonter SI --- .../config/merged/agent-validateur.config.php | 24 +++ .../Agent/src/Controller/AgentController.php | 2 +- .../src/Controller/ValidateurController.php | 20 +++ .../AgentValidateurService.php | 7 +- module/Agent/view/agent/agent/afficher.phtml | 148 ++++++++++-------- 5 files changed, 135 insertions(+), 66 deletions(-) diff --git a/module/Agent/config/merged/agent-validateur.config.php b/module/Agent/config/merged/agent-validateur.config.php index f086b9e0..050fea43 100644 --- a/module/Agent/config/merged/agent-validateur.config.php +++ b/module/Agent/config/merged/agent-validateur.config.php @@ -35,6 +35,8 @@ return [ 'ajouter', 'modifier', 'supprimer', + 'historiser', + 'restaurer', ], 'privilege' => [ AgentPrivileges::getResourceId(AgentPrivileges::AGENT_MODIFIER), @@ -99,6 +101,28 @@ return [ ], ], ], + 'historiser' => [ + 'type' => Segment::class, + 'options' => [ + 'route' => '/historiser/:agent-validateur', + 'defaults' => [ + /** @see ValidateurController::historiserAction() */ + 'controller' => ValidateurController::class, + 'action' => 'historiser', + ], + ], + ], + 'restaurer' => [ + 'type' => Segment::class, + 'options' => [ + 'route' => '/restaurer/:agent-validateur', + 'defaults' => [ + /** @see ValidateurController::restaurerAction() */ + 'controller' => ValidateurController::class, + 'action' => 'restaurer', + ], + ], + ], ], ], ], diff --git a/module/Agent/src/Controller/AgentController.php b/module/Agent/src/Controller/AgentController.php index 044fef29..dca49009 100644 --- a/module/Agent/src/Controller/AgentController.php +++ b/module/Agent/src/Controller/AgentController.php @@ -63,7 +63,7 @@ class AgentController extends AbstractActionController $agentAffectations = $this->getAgentAffectationService()->getAgentAffectationsByAgent($agent); $agentGrades = $this->getAgentGradeService()->getAgentGradesByAgent($agent); $agentStatuts = $this->getAgentStatutService()->getAgentStatutsByAgent($agent); - $validateurs = $this->getAgentValidateurService()->getAgentsValidateursByAgent($agent); + $validateurs = $this->getAgentValidateurService()->getAgentsValidateursByAgent($agent, true); $formations = $this->getInscriptionService()->getInscriptionsByAgent($agent); $inscriptions = $this->getInscriptionService()->getInscriptionsByAgent($agent); diff --git a/module/Agent/src/Controller/ValidateurController.php b/module/Agent/src/Controller/ValidateurController.php index e78a6b8c..6fc34d1c 100644 --- a/module/Agent/src/Controller/ValidateurController.php +++ b/module/Agent/src/Controller/ValidateurController.php @@ -6,6 +6,7 @@ use Agent\Entity\Db\AgentValidateur; use Agent\Form\Validateur\ValidateurFormAwareTrait; use Agent\Service\Agent\AgentServiceAwareTrait; use Agent\Service\AgentValidateur\AgentValidateurServiceAwareTrait; +use Laminas\Http\Response; use Laminas\Mvc\Controller\AbstractActionController; use Laminas\View\Model\ViewModel; @@ -100,4 +101,23 @@ class ValidateurController extends AbstractActionController return $vm; } + public function historiserAction(): Response + { + $validateur = $this->getAgentValidateurService()->getRequestedAgentValidateur($this); + $this->getAgentValidateurService()->historise($validateur); + + $retour = $this->params()->fromQuery('retour'); + if ($retour) return $this->redirect()->toUrl($retour); + return $this->redirect()->toRoute('agent/afficher', ["agent" => $validateur->getAgent()->getId()], [], true); + } + + public function restaurerAction(): Response + { + $validateur = $this->getAgentValidateurService()->getRequestedAgentValidateur($this); + $this->getAgentValidateurService()->restore($validateur); + + $retour = $this->params()->fromQuery('retour'); + if ($retour) return $this->redirect()->toUrl($retour); + return $this->redirect()->toRoute('agent/afficher', ["agent" => $validateur->getAgent()->getId()], [], true); + } } \ No newline at end of file diff --git a/module/Agent/src/Service/AgentValidateur/AgentValidateurService.php b/module/Agent/src/Service/AgentValidateur/AgentValidateurService.php index 4d6f6714..1f066dc8 100644 --- a/module/Agent/src/Service/AgentValidateur/AgentValidateurService.php +++ b/module/Agent/src/Service/AgentValidateur/AgentValidateurService.php @@ -67,7 +67,7 @@ class AgentValidateurService return $qb; } - public function getAgentValidateur(?int $id) : ?AgentValidateur + public function getAgentValidateur(?string $id) : ?AgentValidateur { $qb = $this->createQueryBuilder() ->andWhere('AgentValidateur.id = :id')->setParameter('id', $id); @@ -103,6 +103,7 @@ class AgentValidateurService $qb = $this->createQueryBuilder() ->andWhere('AgentValidateur.agent = :agent')->setParameter('agent', $agent) ->andWhere('agent.deleted_on IS NULL') + ->andWhere('AgentValidateur.deletedOn IS NULL') ->orderBy('AgentValidateur.' . $champ, $ordre); if ($histo === false) $qb = $qb->andWhere('AgentValidateur.histoDestruction IS NULL'); @@ -115,6 +116,7 @@ class AgentValidateurService { $qb = $this->createQueryBuilder() ->andWhere('AgentValidateur.validateur = :validateur')->setParameter('validateur', $validateur) + ->andWhere('AgentValidateur.deletedOn IS NULL') ->orderBy('AgentValidateur.' . $champ, $ordre); if ($histo === false) $qb = $qb->andWhere('AgentValidateur.histoDestruction IS NULL'); @@ -213,6 +215,7 @@ class AgentValidateurService $qb = $this->getObjectManager()->getRepository(AgentValidateur::class)->createQueryBuilder('avalidateur') ->join('avalidateur.validateur', 'agent') ->join('agent.utilisateur', 'utilisateur') + ->andWhere('avalidateur.deletedOn IS NULL') ->orderBy('agent.nomUsuel, agent.prenom', 'ASC') ; $result = $qb->getQuery()->getResult(); @@ -239,6 +242,7 @@ class AgentValidateurService ->andWhere('avalidateur.histoDestruction IS NULL') ->andWhere('avalidateur.dateDebut <= :now') ->andWhere('avalidateur.dateFin IS NULL OR avalidateur.dateFin >= :now') + ->andWhere('avalidateur.deletedOn IS NULL') ->setParameter('user', $user) ->setParameter('now', new DateTime()) ; @@ -252,6 +256,7 @@ class AgentValidateurService ->andWhere('avalidateur.histoDestruction IS NULL') ->andWhere('avalidateur.dateDebut <= :now') ->andWhere('avalidateur.dateFin IS NULL OR avalidateur.dateFin >= :now') + ->andWhere('avalidateur.deletedOn IS NULL') ->setParameter('now', new DateTime()) ->andWhere('avalidateur.agent = :agent')->setParameter('agent', $agent) ->andWhere('avalidateur.validateur = :validateur')->setParameter('validateur', $validateur) diff --git a/module/Agent/view/agent/agent/afficher.phtml b/module/Agent/view/agent/agent/afficher.phtml index 794aa9cb..1480d87d 100644 --- a/module/Agent/view/agent/agent/afficher.phtml +++ b/module/Agent/view/agent/agent/afficher.phtml @@ -42,28 +42,28 @@ $canModifier = $this->isAllowed(AgentPrivileges::getResourceId(AgentPrivileges:: <div class="row"> <div class="col-md-6"> <dl class="row"> - <dt class="col-md-4"> Dénomination </dt> + <dt class="col-md-4"> Dénomination</dt> <dd class="col-md-8"> <?php echo $agent->getDenomination(); ?> </dd> - <dt class="col-md-4"> Affectation·s </dt> + <dt class="col-md-4"> Affectation·s</dt> <dd class="col-m"> <ul> - <?php foreach ($agentAffectations as $agentAffectation) : ?> - <li> - <?php - $structure = $agentAffectation->getStructure(); - $niveau2 = $structure?$structure->getNiv2():null; - ?> - <?php if ($structure) : ?> - <?php echo $structure->getLibelleLong(); ?> - <?php if ($niveau2 AND $niveau2 !== $structure) : ?> - <br/> Rattaché·e à <?php echo $niveau2->getLibelleLong(); ?> - <?php endif; ?> - <?php endif; ?> - <?php if ($agentAffectation->isPrincipale()) : ?> - <br/> <em>Affectation principale</em> - <?php endif; ?> - </li> - <?php endforeach; ?> + <?php foreach ($agentAffectations as $agentAffectation) : ?> + <li> + <?php + $structure = $agentAffectation->getStructure(); + $niveau2 = $structure ? $structure->getNiv2() : null; + ?> + <?php if ($structure) : ?> + <?php echo $structure->getLibelleLong(); ?> + <?php if ($niveau2 and $niveau2 !== $structure) : ?> + <br/> Rattaché·e à <?php echo $niveau2->getLibelleLong(); ?> + <?php endif; ?> + <?php endif; ?> + <?php if ($agentAffectation->isPrincipale()) : ?> + <br/> <em>Affectation principale</em> + <?php endif; ?> + </li> + <?php endforeach; ?> </ul> </dd> </dl> @@ -71,7 +71,7 @@ $canModifier = $this->isAllowed(AgentPrivileges::getResourceId(AgentPrivileges:: <div class="col-md-6"> <dl class="row"> - <dt class="col-md-4"> Statut·s </dt> + <dt class="col-md-4"> Statut·s</dt> <dd class="col-md-8"> <ul> <?php foreach ($statuts as $statut) : ?> @@ -81,7 +81,7 @@ $canModifier = $this->isAllowed(AgentPrivileges::getResourceId(AgentPrivileges:: <?php endforeach; ?> </ul> </dd> - <dt class="col-md-4"> Informations supplémentaires </dt> + <dt class="col-md-4"> Informations supplémentaires</dt> <dd class="col-md-8"> <ul> <?php foreach ($agentGrades as $agentGrade) : ?> @@ -89,9 +89,9 @@ $canModifier = $this->isAllowed(AgentPrivileges::getResourceId(AgentPrivileges:: <?php $corps = $agentGrade->getCorps(); ?> <?php $correspondance = $agentGrade->getCorrespondance(); ?> <li> - <?php echo ($grade)?$grade->getLibelleLong():"Grade non renseigné"; ?> <br/> - <?php echo ($corps)?$corps->getLibelleLong():"Corps non renseigné"; ?> <br/> - <?php echo ($correspondance)?$correspondance->getLibelleLong():"Correspondance non renseignée"; ?> + <?php echo ($grade) ? $grade->getLibelleLong() : "Grade non renseigné"; ?> <br/> + <?php echo ($corps) ? $corps->getLibelleLong() : "Corps non renseigné"; ?> <br/> + <?php echo ($correspondance) ? $correspondance->getLibelleLong() : "Correspondance non renseignée"; ?> </li> <?php endforeach; ?> </ul> @@ -102,63 +102,81 @@ $canModifier = $this->isAllowed(AgentPrivileges::getResourceId(AgentPrivileges:: <dl class="row"> <?php if ($charteActive) : ?> - <dt class="col-md-4"> Charte - </dt> - <dd class="col-md-8"> - <?php if ($validation = $agent->getValidationActiveByTypeCode(CharteValidations::CHARTE_SIGNEE)) : ?> - Charte visée le - <?php echo $validation->getHistoCreation()->format('d/m/Y'); ?> - <?php else : ?> - <span class="text-danger"> + <dt class="col-md-4"> Charte + </dt> + <dd class="col-md-8"> + <?php if ($validation = $agent->getValidationActiveByTypeCode(CharteValidations::CHARTE_SIGNEE)) : ?> + Charte visée le + <?php echo $validation->getHistoCreation()->format('d/m/Y'); ?> + <?php else : ?> + <span class="text-danger"> <span class="icon icon-attention"></span> Charte non visée </span> - <?php endif; ?> - </dd> + <?php endif; ?> + </dd> <?php endif; ?> <dt class="col-md-4"> Validateur·trices<br> <?php if ($canModifier) : ?> <?php /** @see \Agent\Controller\ValidateurController::ajouterAction() */ ?> - <a href="<?php echo $this->url('agent/validateur/ajouter', ['agent' => $agent->getId()], [] ,true); ?>" + <a href="<?php echo $this->url('agent/validateur/ajouter', ['agent' => $agent->getId()], [], true); ?>" class="btn btn-primary ajax-modal" data-event="modification"> <span class="icon icon-ajouter"></span> Ajouter un·e validateur·trice </a> <?php endif; ?> </dt> - <dd class="col-md-8"> + <dd class="col-md-8"> - <?php if (empty($validateurs)) : ?> - <span class="text-danger"> + <?php if (empty($validateurs)) : ?> + <span class="text-danger"> <span class="icon icon-attention"></span> Aucun·e validateur·trice connu·e </span> - <?php else: ?> + <?php else: ?> <ul> <?php foreach ($validateurs as $validateur) : ?> - <li - title="Sur la période du <?php echo $validateur->getDateDebut()->format('d/m/Y'); ?> au <?php echo $validateur->getDateFin()?$validateur->getDateFin()->format('d/m/y'):" ---"; ?>"> - <?php echo $validateur->getValidateur()->getDenomination(); ?> <span class="badge"> <?php echo $validateur->getSourceId(); ?> </span> - <?php if ($validateur->getSourceId() === 'MES FORMATIONS' AND $canModifier) : ?> - <?php /** @see \Agent\Controller\ValidateurController::modifierAction() */ ?> - <a href="<?php echo $this->url('agent/validateur/modifier', ['agent-validateur' => $validateur->getId()], [] ,true); ?>" - class="ajax-modal action primary" data-event="modification"> - <span class="icon icon-modifier"></span> - Modifier - </a> - <?php /** @see \Agent\Controller\ValidateurController::supprimerAction() */ ?> - <a href="<?php echo $this->url('agent/validateur/supprimer', ['agent-validateur' => $validateur->getId()], [] ,true); ?>" - class="ajax-modal action danger" data-event="modification"> - <span class="icon icon-unchecked"></span> - Supprimer - </a> - <?php endif; ?> - - </li> + <?php if (!$validateur->estHistorise() or $canModifier) : ?> + <li + title="Sur la période du <?php echo $validateur->getDateDebut()->format('d/m/Y'); ?> au <?php echo $validateur->getDateFin() ? $validateur->getDateFin()->format('d/m/y') : " ---"; ?>"> + <span class="<?php if ($validateur->estHistorise()) echo "historise"; ?>"><?php echo $validateur->getValidateur()->getDenomination(); ?></span> + <span + class="badge"> <?php echo $validateur->getSourceId(); ?> </span> + <?php if ($validateur->getSourceId() === 'MES FORMATIONS' and $canModifier) : ?> + <?php /** @see \Agent\Controller\ValidateurController::modifierAction() */ ?> + <a href="<?php echo $this->url('agent/validateur/modifier', ['agent-validateur' => $validateur->getId()], [], true); ?>" + class="ajax-modal action primary" data-event="modification"> + <span class="icon icon-modifier"></span> + Modifier + </a> + <?php /** @see \Agent\Controller\ValidateurController::supprimerAction() */ ?> + <a href="<?php echo $this->url('agent/validateur/supprimer', ['agent-validateur' => $validateur->getId()], [], true); ?>" + class="ajax-modal action danger" data-event="modification"> + <span class="icon icon-unchecked"></span> + Supprimer + </a> + <?php else : ?> + <?php if ($validateur->estHistorise()) : ?> + <?php /** @see \Agent\Controller\ValidateurController::restaurerAction() */ ?> + <a href="<?php echo $this->url('agent/validateur/restaurer', ['agent-validateur' => $validateur->getId()], [], true); ?>" + class="action warning" > + <span class="icon icon-restaurer"></span> + Ré-établir + </a> + <?php else : ?> + <a href="<?php echo $this->url('agent/validateur/historiser', ['agent-validateur' => $validateur->getId()], [], true); ?>" + class="action warning"> + <span class="icon icon-historiser"></span> + Révoquer + </a> + <?php endif; ?> + <?php endif; ?> + </li> + <?php endif; ?> <?php endforeach; ?> </ul> - <?php endif; ?> + <?php endif; ?> </dd> </dl> @@ -167,17 +185,19 @@ $canModifier = $this->isAllowed(AgentPrivileges::getResourceId(AgentPrivileges:: <ul class="nav nav-tabs" role="tablist"> <li class="nav-item"> <a href="#formations" class="nav-link" aria-controls="formations" role="tab" data-toggle="tabz"> - Formations <br> suivies + Formations <br> suivies </a> </li> <li class="nav-item"> - <a href="#inscriptions-internes" class="nav-link" aria-controls="inscriptions-internes" role="tab" data-toggle="tabz"> + <a href="#inscriptions-internes" class="nav-link" aria-controls="inscriptions-internes" role="tab" + data-toggle="tabz"> Inscriptions en cours <br> Plan de formation </a> </li> <li class="nav-item"> - <a href="#inscriptions-externes" class="nav-link" aria-controls="inscriptions-externes" role="tab" data-toggle="tabz"> + <a href="#inscriptions-externes" class="nav-link" aria-controls="inscriptions-externes" role="tab" + data-toggle="tabz"> Inscriptions en cours <br> Stage externe </a> @@ -198,7 +218,7 @@ $canModifier = $this->isAllowed(AgentPrivileges::getResourceId(AgentPrivileges:: <script> - $(function() { + $(function () { let hash = $(location).attr('hash'); let name = hash.substring(1); if (name === undefined || name === "") name = "formations"; @@ -210,7 +230,7 @@ $canModifier = $this->isAllowed(AgentPrivileges::getResourceId(AgentPrivileges:: $(this).tab('show'); }); }); - $(function() { + $(function () { $("body").on("modification", function (event) { event.div.modal('hide'); window.location.reload(); -- GitLab