From 97053c80c53e75a5a6c0bd2d099f9af35b7a8dc6 Mon Sep 17 00:00:00 2001
From: Jean-Philippe Metivier <jean-philippe.metivier@unicaen.fr>
Date: Tue, 3 Dec 2024 17:32:40 +0100
Subject: [PATCH] Notification/Rappel demande de validation par les valideurs
---
database/migration/1.0.5.sql | 3 ++
.../config/merged/session.config.php | 13 ++++++
.../Controller/InscriptionController.php | 2 +-
.../Controller/SessionController.php | 40 +++++++++++++++++++
.../Provider/Template/MailTemplates.php | 2 +
.../Notification/NotificationService.php | 24 +++++++++++
.../formation/session/partial/inscrits.phtml | 9 +++++
7 files changed, 92 insertions(+), 1 deletion(-)
create mode 100644 database/migration/1.0.5.sql
diff --git a/database/migration/1.0.5.sql b/database/migration/1.0.5.sql
new file mode 100644
index 00000000..d036622e
--- /dev/null
+++ b/database/migration/1.0.5.sql
@@ -0,0 +1,3 @@
+INSERT INTO unicaen_renderer_template (code, description, document_type, document_sujet, document_corps, document_css, namespace) VALUES ('FORMATION_SESSION_RAPPEL_DEMANDE_VALIDATION', '<p>Courrier de rappel de la demande de validation d''une inscription à une formation du plan de formation</p>', 'mail', 'RAPPEL Vous n''avez pas encore validé la demande de formation de VAR[AGENT#Denomination]', e'<p>Bonjour,</p>
+<p>Vous n\'avez pas encore validé la demande de formation de VAR[AGENT#Denomination] pour la session VAR[SESSION#libelle] du VAR[SESSION#periode].<br>Veuillez vous rendre dans votre tableau de bord en tant que Valideur·euse sur l\'application VAR[Macro#AppName] (VAR[Url#AppLink]) afin de statuer sur cette demande.</p>
+<p>Bonne journée,<br>L\'application VAR[Macro#AppName]</p>', null, 'Formation\Provider\Template');
diff --git a/module/Formation/config/merged/session.config.php b/module/Formation/config/merged/session.config.php
index 3f597a60..3aefc05f 100644
--- a/module/Formation/config/merged/session.config.php
+++ b/module/Formation/config/merged/session.config.php
@@ -110,6 +110,8 @@ return [
'demander-retour',
'cloturer',
'changer-etat',
+
+ 'notifier-responsable-pour-validation',
],
'privileges' => [
FormationinstancePrivileges::FORMATIONINSTANCE_GERER_INSCRIPTION,
@@ -383,6 +385,17 @@ return [
],
],
],
+ /** notification **********************************************************/
+ 'notifier-responsable-pour-validation' => [
+ 'type' => Segment::class,
+ 'options' => [
+ 'route' => '/notifier-responsable-pour-validation/:session',
+ 'defaults' => [
+ /** @see SessionController::notifierResponsablePourValidationAction() */
+ 'action' => 'notifier-responsable-pour-validation',
+ ],
+ ],
+ ],
/** gestion des formateurs ************************************************/
'ajouter-formateur' => [
'type' => Segment::class,
diff --git a/module/Formation/src/Formation/Controller/InscriptionController.php b/module/Formation/src/Formation/Controller/InscriptionController.php
index 8b028e96..484f1615 100644
--- a/module/Formation/src/Formation/Controller/InscriptionController.php
+++ b/module/Formation/src/Formation/Controller/InscriptionController.php
@@ -618,7 +618,7 @@ class InscriptionController extends AbstractActionController
$form->setData($data);
if ($form->isValid()) {
$plafond = $this->getParametreService()->getValeurForParametre(FormationParametres::TYPE, FormationParametres::INSCRIPTION_PLAFOND_ANNUEL);
- $volumeAnnuel = $this->getInscriptionService()->getVolumeAnnuelByAgent($agent, $session->getDebut(true)->format("Y")) + $session->getDuree(true);
+ $volumeAnnuel = $this->getInscriptionService()->getVolumeAnnuelByAgent($agent, ($session->getDebut(true))?$session->getDebut(true)->format("Y"):0) + $session->getDuree(true);
$justification = (isset($data['justification']) && trim($data['justification']) !== '') ? trim($data['justification']) : null;
if ($justification === null) {
diff --git a/module/Formation/src/Formation/Controller/SessionController.php b/module/Formation/src/Formation/Controller/SessionController.php
index e49ac282..6308b78c 100644
--- a/module/Formation/src/Formation/Controller/SessionController.php
+++ b/module/Formation/src/Formation/Controller/SessionController.php
@@ -8,6 +8,7 @@ use Formation\Form\Annulation\AnnulationFormAwareTrait;
use Formation\Form\SelectionFormateur\SelectionFormateurFormAwareTrait;
use Formation\Form\SelectionGestionnaire\SelectionGestionnaireFormAwareTrait;
use Formation\Form\Session\SessionFormAwareTrait;
+use Formation\Provider\Etat\InscriptionEtats;
use Formation\Provider\Etat\SessionEtats;
use Formation\Provider\Parametre\AutreParametres;
use Formation\Provider\Role\FormationRoles;
@@ -569,6 +570,45 @@ class SessionController extends AbstractActionController
]);
}
+
+ public function notifierResponsablePourValidationAction(): ViewModel
+ {
+ $session = $this->getSessionService()->getRequestedSession($this);
+ $inscriptions = $this->getInscriptionService()->getInscriptionsBySession($session);
+ $inscriptions = array_filter($inscriptions, function (Inscription $inscription) {
+ return $inscription->estNonHistorise() AND $inscription->isEtatActif(InscriptionEtats::ETAT_DEMANDE);
+ });
+
+ $mails = [];
+ /** @var Inscription $inscription */
+ foreach ($inscriptions as $inscription)
+ {
+ $mails[$inscription->getIndividu()->getDenomination()] = $this->getNotificationService()->triggerRappelDemandeValidationValideur($inscription);
+ }
+
+ $success = []; $probleme = [];
+ foreach ($mails as $individu => $mail) {
+ if ($mail === null) $probleme[] = $individu; else $success[] = $individu;
+ }
+ if (!empty($success)) {
+ $successTexte = " Les valideur·deuses ont été notifié·es (".count($success)." courrier·s envoyé·s).";
+ }
+ if (!empty($probleme)) {
+ $problemeTexte = "L'opération n'a pas pu être faite pour les inscriptions de : <ul>";
+ foreach ($probleme as $individu) $problemeTexte .= "<li>" . $individu . "</li>";
+ $problemeTexte .= "</ul>";
+ }
+
+ $vm = new ViewModel([
+ 'title' => "Courrier de rappel de demande de validation",
+ 'reponse' => "Opération effectuée",
+ 'success' => $successTexte??null,
+ 'error' => $problemeTexte??null,
+ ]);
+ $vm->setTemplate('default/reponse');
+ return $vm;
+ }
+
public function resultatEnqueteAction(): ViewModel
{
$session = $this->getSessionService()->getRequestedSession($this);
diff --git a/module/Formation/src/Formation/Provider/Template/MailTemplates.php b/module/Formation/src/Formation/Provider/Template/MailTemplates.php
index 95c4f29b..36a6aa11 100644
--- a/module/Formation/src/Formation/Provider/Template/MailTemplates.php
+++ b/module/Formation/src/Formation/Provider/Template/MailTemplates.php
@@ -26,6 +26,8 @@ class MailTemplates {
const SESSION_DEMANDE_RETOUR = "FORMATION_SESSION_DEMANDE_RETOUR";
const SESSION_ANNULEE = "FORMATION_SESSION_ANNULEE";
+ //notification de rappel ou de precision
+ const SESSION_RAPPEL_DEMANDE_VALIDATION = "FORMATION_SESSION_RAPPEL_DEMANDE_VALIDATION";
//rappel
const FORMATION_RAPPEL_AVANT_FORMATION = "FORMATION_NOTIFICATION_SESSION_IMMINENTE";
const FORMATION_INSCRIPTION_OUVERTE = "FORMATION_NOTIFICATION_ABONNEMENT_FORMATION";
diff --git a/module/Formation/src/Formation/Service/Notification/NotificationService.php b/module/Formation/src/Formation/Service/Notification/NotificationService.php
index bc1fb17d..25aeeeff 100644
--- a/module/Formation/src/Formation/Service/Notification/NotificationService.php
+++ b/module/Formation/src/Formation/Service/Notification/NotificationService.php
@@ -411,6 +411,30 @@ class NotificationService
return null;
}
+ public function triggerRappelDemandeValidationValideur(Inscription $inscription): ?Mail
+ {
+ $valideurs = $this->getAgentValidateurService()->getAgentsValidateursByAgent($inscription->getAgent());
+ if (empty($valideurs)) return null;
+
+ $adresses = [];
+ foreach ($valideurs as $valideur) {
+ if ($valideur->getAgent()->getEmail()) $adresses[] = $valideur->getValidateur()->getEmail();
+ }
+ if (empty($adresses)) return null;
+
+ $session = $inscription->getSession();
+
+ $vars = $this->generateVariableArray($inscription);
+ $rendu = $this->getRenduService()->generateRenduByTemplateCode(MailTemplates::SESSION_RAPPEL_DEMANDE_VALIDATION, $vars);
+ $mail = $this->getMailService()->sendMail($adresses, $rendu->getSujet(), $rendu->getCorps(), 'Formation');
+ $mail->setMotsClefs([$session->generateTag(), $inscription->generateTag(), $rendu->getTemplate()->generateTag()]);
+ $this->getMailService()->update($mail);
+ $session->addMail($mail);
+ $this->getObjectManager()->flush($session);
+ return $mail;
+
+ }
+
/** Mails de rappel ***********************************************************************************************/
public function triggerRappelAgentAvantFormation(Session $session): ?array
diff --git a/module/Formation/view/formation/session/partial/inscrits.phtml b/module/Formation/view/formation/session/partial/inscrits.phtml
index abfa131b..24160402 100644
--- a/module/Formation/view/formation/session/partial/inscrits.phtml
+++ b/module/Formation/view/formation/session/partial/inscrits.phtml
@@ -34,6 +34,7 @@ $canSupprimerInscription = $this->isAllowed(FormationinstancePrivileges::getReso
$urlRetour = $this->url('session/afficher', ['session' => $instance->getId()], ['fragment' => 'inscriptions'], true);
+$canNotifierValideur = $this->isAllowed(FormationinstancePrivileges::getResourceId(FormationinstancePrivileges::FORMATIONINSTANCE_GERER_INSCRIPTION));
$liste = $instance->getListeDisponible();
$principaleComplete = $instance->isListePrincipaleComplete();
@@ -43,6 +44,14 @@ $inscriptions = $instance->getInscriptions()
?>
+<?php /** @see \Formation\Controller\SessionController::notifierResponsablePourValidationAction() */ ?>
+<a href="<?php echo $this->url('session/notifier-responsable-pour-validation', ['session' => $instance->getId()], []); ?>"
+ class="btn btn-primary ajax-modal" data-event="modification"
+>
+ <span class="icon icon-notifier"></span>
+ Rappel de la demande de validation aux valideur·euses
+</a>
+
<div class="row">
<div class="col-md-6">
<h2>
--
GitLab