diff --git a/module/Formation/src/Formation/Controller/SessionController.php b/module/Formation/src/Formation/Controller/SessionController.php
index 9e77bef103287e4221f4d4b8bb11d214531895d5..9738a3c253aa7f2b5634f928560f9a387d57dcb2 100644
--- a/module/Formation/src/Formation/Controller/SessionController.php
+++ b/module/Formation/src/Formation/Controller/SessionController.php
@@ -325,11 +325,30 @@ class SessionController extends AbstractActionController
return $this->redirect()->toRoute('session/afficher', ['session' => $session->getId()], [], true);
}
- public function demanderRetourAction(): Response
+ public function demanderRetourAction(): ViewModel
{
$session = $this->getSessionService()->getRequestedSession($this);
- $this->getSessionService()->demanderRetour($session);
- return $this->redirect()->toRoute('session/afficher', ['session' => $session->getId()], [], true);
+ $mails = $this->getSessionService()->demanderRetour($session);
+
+ $probleme = [];
+ foreach ($mails as $individu => $mail) {
+ if ($mail === null) {
+ $probleme[] = $individu;
+ }
+ }
+ if (!empty($probleme)) {
+ $problemeTexte = "Les stagiaire·s suivant·es n'ont pas pu être prévenu·es : <ul>";
+ foreach ($probleme as $individu) $problemeTexte .= "<li>" . $individu . "</li>";
+ $problemeTexte .= "</ul>";
+ }
+
+ $vm = new ViewModel([
+ 'title' => "Demande de retour",
+ 'reponse' => "La demande a bien été effectuée",
+ 'error' => $problemeTexte??null,
+ ]);
+ $vm->setTemplate('default/reponse');
+ return $vm;
}
public function cloturerAction(): Response
diff --git a/module/Formation/src/Formation/Service/Notification/NotificationService.php b/module/Formation/src/Formation/Service/Notification/NotificationService.php
index eb7a08ddf84f9651fbecb170ded8451bb0029d4a..f894c2f43ad13467ef18e559316cd377a4733574 100644
--- a/module/Formation/src/Formation/Service/Notification/NotificationService.php
+++ b/module/Formation/src/Formation/Service/Notification/NotificationService.php
@@ -294,12 +294,15 @@ class NotificationService
$vars = $this->generateVariableArray($inscrit);
$rendu = $this->getRenduService()->generateRenduByTemplateCode(MailTemplates::SESSION_DEMANDE_RETOUR, $vars);
- $mail = $this->getMailService()->sendMail($inscrit->getIndividu()->getEmail(), $rendu->getSujet(), $rendu->getCorps(), 'Formation');
- $mail->setMotsClefs([$session->generateTag(), $inscrit->generateTag(), $rendu->getTemplate()->generateTag()]);
- $this->getMailService()->update($mail);
- $session->addMail($mail);
- $this->getObjectManager()->flush($session);
- return $mail;
+ if ($inscrit->getIndividu() !== null) {
+ $mail = $this->getMailService()->sendMail($inscrit->getIndividu()->getEmail(), $rendu->getSujet(), $rendu->getCorps(), 'Formation');
+ $mail->setMotsClefs([$session->generateTag(), $inscrit->generateTag(), $rendu->getTemplate()->generateTag()]);
+ $this->getMailService()->update($mail);
+ $session->addMail($mail);
+ $this->getObjectManager()->flush($session);
+ return $mail;
+ }
+ return null;
}
/** Notification vers les inscrit·e ayant eu une absence */
diff --git a/module/Formation/src/Formation/Service/Session/SessionService.php b/module/Formation/src/Formation/Service/Session/SessionService.php
index 4d107be10a8c5d5e17a3e4660aa56c96b8b3f97c..c95fd47529cd3024e0e1a78748317688022c93fc 100644
--- a/module/Formation/src/Formation/Service/Session/SessionService.php
+++ b/module/Formation/src/Formation/Service/Session/SessionService.php
@@ -24,6 +24,7 @@ use Laminas\Mvc\Controller\AbstractActionController;
use UnicaenApp\Exception\RuntimeException;
use UnicaenEtat\Service\EtatInstance\EtatInstanceServiceAwareTrait;
use UnicaenEtat\Service\EtatType\EtatTypeServiceAwareTrait;
+use UnicaenMail\Entity\Db\Mail;
use UnicaenParametre\Service\Parametre\ParametreServiceAwareTrait;
use UnicaenUtilisateur\Entity\Db\UserInterface;
@@ -419,18 +420,20 @@ class SessionService
return $session;
}
- public function demanderRetour(Session $instance): Session
+ /** @return Mail[] $mails */
+ public function demanderRetour(Session $instance): array
{
+ $mails = [];
$this->getEtatInstanceService()->setEtatActif($instance, SessionEtats::ETAT_ATTENTE_RETOURS);
$this->update($instance);
$configuration = $this->getNotificationConfigurationService()->getNotificationConfigurationWithParams("SESSION", MailTemplates::SESSION_DEMANDE_RETOUR, "Demande de retour");
if ($configuration === null OR $configuration->isActive()) {
foreach ($instance->getListePrincipale() as $inscrit) {
- $this->getNotificationService()->triggerDemandeRetour($inscrit);
+ $mails[$inscrit->getIndividu()->getDenomination()] = $this->getNotificationService()->triggerDemandeRetour($inscrit);
}
}
- return $instance;
+ return $mails;
}
public function envoyerAbsence(Session $session, ?Inscription $inscription = null): Session
diff --git a/module/Formation/view/formation/session/afficher.phtml b/module/Formation/view/formation/session/afficher.phtml
index 3bb6045fc74734f15f0d376f1bdb02a9990c2b1c..bdeb3186603706a86f36b1cc98dd3ac1c40905d0 100644
--- a/module/Formation/view/formation/session/afficher.phtml
+++ b/module/Formation/view/formation/session/afficher.phtml
@@ -153,7 +153,7 @@ $canMesSessions = $this->isAllowed(FormateurPrivileges::getResourceId(FormateurP
<br/>
<a <?php /** @see SessionController::demanderRetourAction() */ ?>
href="<?php echo $this->url('session/demander-retour', ['session' => $session->getId()], [], true); ?>"
- class="btn btn-primary">
+ class="btn btn-primary ajax-modal" data-event="modification">
Demander les retours
</a>
<?php endif; ?>