diff --git a/module/Formation/src/Formation/Controller/SessionController.php b/module/Formation/src/Formation/Controller/SessionController.php index 9738a3c253aa7f2b5634f928560f9a387d57dcb2..f5dd4134109310173069251c892349ec432df13d 100644 --- a/module/Formation/src/Formation/Controller/SessionController.php +++ b/module/Formation/src/Formation/Controller/SessionController.php @@ -317,12 +317,34 @@ class SessionController extends AbstractActionController return $this->redirect()->toRoute('session/afficher', ['session' => $instance->getId()], [], true); } - public function envoyerConvocationAction(): Response + public function envoyerConvocationAction(): ViewModel { $session = $this->getSessionService()->getRequestedSession($this); $this->getSessionService()->envoyerConvocation($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 convoqué·es : <ul>"; + foreach ($probleme as $individu) $problemeTexte .= "<li>" . $individu . "</li>"; + $problemeTexte .= "</ul>"; + } + + $this->getSessionService()->envoyerEmargement($session); - return $this->redirect()->toRoute('session/afficher', ['session' => $session->getId()], [], true); + + $vm = new ViewModel([ + 'title' => "Envoi des convocations", + 'reponse' => "Opération effectuée", + 'error' => $problemeTexte??null, + ]); + $vm->setTemplate('default/reponse'); + return $vm; } public function demanderRetourAction(): ViewModel diff --git a/module/Formation/src/Formation/Service/Notification/NotificationService.php b/module/Formation/src/Formation/Service/Notification/NotificationService.php index 9dce064cf34242345fe28f0006a4bbe0349a548a..e84bdfde957ec67f68ac5898d7756a6f6add7895 100644 --- a/module/Formation/src/Formation/Service/Notification/NotificationService.php +++ b/module/Formation/src/Formation/Service/Notification/NotificationService.php @@ -277,13 +277,16 @@ class NotificationService foreach ($superieurs as $superieur) $copie[] = $superieur->getValidateur()->getEmail(); } - $rendu = $this->getRenduService()->generateRenduByTemplateCode(MailTemplates::SESSION_CONVOCATION, $vars); - $mail = $this->getMailService()->sendMail($agent->getEmail(), $rendu->getSujet(), $rendu->getCorps(), 'Formation', null, $copie); - $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 AND $inscrit->getIndividu()->getEmail() !== null) { + $rendu = $this->getRenduService()->generateRenduByTemplateCode(MailTemplates::SESSION_CONVOCATION, $vars); + $mail = $this->getMailService()->sendMail($agent->getEmail(), $rendu->getSujet(), $rendu->getCorps(), 'Formation', null, $copie); + $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 envoyée vers les stagaires pour leur demander leurs retours */ diff --git a/module/Formation/src/Formation/Service/Session/SessionService.php b/module/Formation/src/Formation/Service/Session/SessionService.php index 5f2a162b936a4cadc14f6f62f38a95f8e169bf83..c974a6f807f7606969edee03072c0e766bf3f712 100644 --- a/module/Formation/src/Formation/Service/Session/SessionService.php +++ b/module/Formation/src/Formation/Service/Session/SessionService.php @@ -400,8 +400,10 @@ class SessionService return $instance; } - public function envoyerConvocation(Session $session, ?Inscription $inscription = null): Session + /** @return Mail[] $mails */ + public function envoyerConvocation(Session $session, ?Inscription $inscription = null): array { + $mails = []; if ($inscription === null) { $this->getEtatInstanceService()->setEtatActif($session, SessionEtats::ETAT_FORMATION_CONVOCATION); $this->update($session); @@ -413,11 +415,11 @@ class SessionService if ($configuration === null OR $configuration->isActive()) { foreach ($liste as $inscrit) { if ($inscrit->estNonHistorise()) { - $this->getNotificationService()->triggerConvocation($inscrit); + $mails[$inscrit->getIndividu()->getDenomination()] = $this->getNotificationService()->triggerConvocation($inscrit); } } } - return $session; + return $mails; } /** @return Mail[] $mails */ @@ -463,9 +465,6 @@ class SessionService return $session; } - - - /** * @param Session $instance * @return Session diff --git a/module/Formation/view/formation/session/afficher.phtml b/module/Formation/view/formation/session/afficher.phtml index 1b8f006afbc7feb8ae12939f1983bed2104865d4..046e683c60ff91251398002459f345d4c43d3cda 100644 --- a/module/Formation/view/formation/session/afficher.phtml +++ b/module/Formation/view/formation/session/afficher.phtml @@ -145,7 +145,7 @@ $canMesSessions = $this->isAllowed(FormateurPrivileges::getResourceId(FormateurP <br/> <a <?php /** @see SessionController::envoyerConvocationAction() */ ?> href="<?php echo $this->url('session/envoyer-convocation', ['session' => $session->getId()], [], true); ?>" - class="btn btn-primary"> + class="btn btn-primary ajax-modal"> Convoquer les inscrits </a> <?php endif; ?> @@ -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 ajax-modal" data-event="modification"> + class="btn btn-primary ajax-modal"> Demander les retours </a> <?php endif; ?>