diff --git a/module/Application/view/default/reponse.phtml b/module/Application/view/default/reponse.phtml index 5595d8ccb1d5607455755b8eeae89fc2651da5b1..d7a77131190074bfef6fe113ebbebb17dfeeffdf 100644 --- a/module/Application/view/default/reponse.phtml +++ b/module/Application/view/default/reponse.phtml @@ -2,6 +2,8 @@ /** * @var string $reponse + * @var string $success + * @var string $probleme */ ?> @@ -10,8 +12,15 @@ <?php echo $reponse; ?> <?php endif; ?> +<?php if (isset($success)) : ?> + <div class="alert alert-success text-success"> + <span class="icon icon-checked"></span> + <?php echo $success; ?> + </div> +<?php endif; ?> + <?php if (isset($error)) : ?> - <div class="alert alert-error text-danger"> + <div class="alert alert-danger text-danger"> <span class="icon icon-unchecked"></span> <?php echo $error; ?> </div> diff --git a/module/Formation/src/Formation/Controller/SessionController.php b/module/Formation/src/Formation/Controller/SessionController.php index 5431822615c27dd72251f1ef74f4f57abc7541db..e49ac282520592531cc2b407de526227aab8bed3 100644 --- a/module/Formation/src/Formation/Controller/SessionController.php +++ b/module/Formation/src/Formation/Controller/SessionController.php @@ -302,47 +302,95 @@ class SessionController extends AbstractActionController } /** WORKFLOW *****************************************************************************************************/ - public function ouvrirInscriptionAction(): Response + + public function ouvrirInscriptionAction(): ViewModel { $session = $this->getSessionService()->getRequestedSession($this); - $this->getSessionService()->ouvrirInscription($session); + $mails = $this->getSessionService()->ouvrirInscription($session); + + foreach ($mails as $individu => $mail) { + if ($mail === null) $probleme[] = $individu; else $success[] = $individu; + } + if (!empty($success)) { + $successTexte = "Les abonné·es ont été notifié·es de l'ouverture des inscriptions de cette session (".count($success)." courrier·s envoyé·s)"; + } + if (!empty($probleme)) { + $problemeTexte = "Les abonné·es suivant·es n'ont pas pu être prévenu·es : <ul>"; + foreach ($probleme as $individu) $problemeTexte .= "<li>" . $individu . "</li>"; + $problemeTexte .= "</ul>"; + } - return $this->redirect()->toRoute('session/afficher', ['session' => $session->getId()], [], true); + $vm = new ViewModel([ + 'title' => "Ouverture des inscriptions", + 'reponse' => "Opération effectuée", + 'success' => $successTexte??null, + 'error' => $problemeTexte??null, + ]); + $vm->setTemplate('default/reponse'); + return $vm; } - public function fermerInscriptionAction(): Response + public function fermerInscriptionAction(): ViewModel { $instance = $this->getSessionService()->getRequestedSession($this); - $this->getSessionService()->fermerInscription($instance); + $mails = $this->getSessionService()->fermerInscription($instance); + $probleme = []; $success = []; + foreach ($mails as $individu => $mail) { + if ($mail === null) $probleme[] = $individu; else $success[] = $individu; + } + if (!empty($success)) { + $successTexte = "Les inscrit·es des listes principales et complémentaires ont été notifié·es (".count($success)." courrier·s envoyé·s). "; + } + if (!empty($probleme)) { + $problemeTexte = "Les inscrit·es suivant·es n'ont pas pu être prévenu·es : <ul>"; + foreach ($probleme as $individu) $problemeTexte .= "<li>" . $individu . "</li>"; + $problemeTexte .= "</ul>"; + } - return $this->redirect()->toRoute('session/afficher', ['session' => $instance->getId()], [], true); + $vm = new ViewModel([ + 'title' => "Fermeture des inscriptions", + 'reponse' => "Opération effectuée", + 'success' => $successTexte??null, + 'error' => $problemeTexte??null, + ]); + $vm->setTemplate('default/reponse'); + return $vm; } public function envoyerConvocationAction(): ViewModel { $session = $this->getSessionService()->getRequestedSession($this); - $this->getSessionService()->envoyerConvocation($session); + $mails = $this->getSessionService()->envoyerConvocation($session); - $probleme = []; + $probleme = []; $success = []; foreach ($mails as $individu => $mail) { - if ($mail === null) { - $probleme[] = $individu; - } + if ($mail === null) $probleme[] = $individu; else $success[] = $individu; } + if (!empty($success)) { + $successTexte = "Les convocations ont été envoyées aux inscrit·es de la liste principale (".count($success)." courrier·s envoyé·s). "; + } 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); + $mails = $this->getSessionService()->envoyerEmargement($session); + $probleme = []; $success = []; + foreach ($mails as $individu => $mail) { + if ($mail === null) $probleme[] = $individu; else $success[] = $individu; + } + if (!empty($probleme)) { + $problemeTexte = "<p>".$problemeTexte."</p>"; + $problemeTexte .= "<p>La notification vers les formateur·trices a échouée.</p>"; + } $vm = new ViewModel([ 'title' => "Envoi des convocations", 'reponse' => "Opération effectuée", + 'success' => $successTexte??null, 'error' => $problemeTexte??null, ]); $vm->setTemplate('default/reponse'); @@ -354,12 +402,17 @@ class SessionController extends AbstractActionController $session = $this->getSessionService()->getRequestedSession($this); $mails = $this->getSessionService()->demanderRetour($session); - $probleme = []; + $success = []; $probleme = []; foreach ($mails as $individu => $mail) { if ($mail === null) { $probleme[] = $individu; + } else { + $success[] = $individu; } } + if (!empty($success)) { + $successTexte = "Les stagiaire·s ont être prévenu·es par courrier électronique (".count($success)." courrier·s envoyé·s). <ul>"; + } 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>"; @@ -369,17 +422,43 @@ class SessionController extends AbstractActionController $vm = new ViewModel([ 'title' => "Demande de retour", 'reponse' => "La demande a bien été effectuée", + 'success' => $successTexte??null, 'error' => $problemeTexte??null, ]); $vm->setTemplate('default/reponse'); return $vm; } - public function cloturerAction(): Response + public function cloturerAction(): ViewModel { $session = $this->getSessionService()->getRequestedSession($this); - $this->getSessionService()->cloturer($session); - return $this->redirect()->toRoute('session/afficher', ['session' => $session->getId()], [], true); + $mails = $this->getSessionService()->cloturer($session); + + $success = []; $probleme = []; + foreach ($mails as $individu => $mail) { + if ($mail === null) { + $probleme[] = $individu; + } else { + $success[] = $individu; + } + } + if (!empty($success)) { + $successTexte = "Les inscrits de la liste complémentaire ont été abonné·es (".count($success)." courrier·s envoyé·s)."; + } + if (!empty($probleme)) { + $problemeTexte = "Les inscrit·es 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' => "Clôture de la session", + 'reponse' => "La clôture de la session et l'abonnement des inscrit·es de la liste complémentaire", + 'success' => $successTexte??null, + 'error' => $problemeTexte??null, + ]); + $vm->setTemplate('default/reponse'); + return $vm; } public function annulerAction(): ViewModel @@ -395,8 +474,29 @@ class SessionController extends AbstractActionController $data = $request->getPost(); $form->setData($data); if ($form->isValid()) { - $this->getSessionService()->annuler($session); - exit(); + $mails = $this->getSessionService()->annuler($session); + + $success = []; $probleme = []; + foreach ($mails as $individu => $mail) { + if ($mail === null) $probleme[] = $individu; else $success[] = $individu; + } + if (!empty($success)) { + $successTexte = "Les inscrit·es de la liste principale ont été prévenu·es (".count($success)." courrier·s envoyé·s)."; + } + if (!empty($probleme)) { + $problemeTexte = "Les inscrit·es 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' => "Annulation de la session", + 'reponse' => "La session est maintenant annulée. <br>Raison:".$session->getMotifAnnulation(), + 'success' => $successTexte??null, + 'error' => $problemeTexte??null, + ]); + $vm->setTemplate('default/reponse'); + return $vm; } } @@ -408,11 +508,17 @@ class SessionController extends AbstractActionController return $vm; } - public function reouvrirAction(): Response + public function reouvrirAction(): ViewModel { $session = $this->getSessionService()->getRequestedSession($this); $this->getSessionService()->reouvrir($session); - return $this->redirect()->toRoute('session/afficher', ['session' => $session->getId()], [], true); + + $vm = new ViewModel([ + 'title' => "Ré-ouverture de la session", + 'reponse' => "La session est de nouveau ouverte et peut-être à nouveau modifiée.", + ]); + $vm->setTemplate('default/reponse'); + return $vm; } public function changerEtatAction(): ViewModel @@ -430,7 +536,6 @@ class SessionController extends AbstractActionController //Les gestions n'utilise pas le bouton correctement ... // switch ($etat->getCode()) { // case SessionEtats::ETAT_CREATION_EN_COURS : -// $this->getSessionService()->recreation($session); // exit(); // case SessionEtats::ETAT_INSCRIPTION_OUVERTE : // $this->getSessionService()->ouvrirInscription($session); diff --git a/module/Formation/src/Formation/Service/Notification/NotificationService.php b/module/Formation/src/Formation/Service/Notification/NotificationService.php index e84bdfde957ec67f68ac5898d7756a6f6add7895..bc1fb17d5b85eb496e50f194ad1cd2f3678dfc06 100644 --- a/module/Formation/src/Formation/Service/Notification/NotificationService.php +++ b/module/Formation/src/Formation/Service/Notification/NotificationService.php @@ -83,15 +83,14 @@ class NotificationService public function generateAndSend(string $templateCode, $adresses, array $motsClefs = [], array $vars = []): ?Mail { try { - $rendu = $this->getRenduService()->generateRenduByTemplateCode($templateCode, $vars); - $mail = $this->getMailService()->sendMail($adresses, $rendu->getSujet(), $rendu->getCorps(), 'Formation'); - $motsClefs[] = $rendu->getTemplate()->generateTag(); - $mail->setMotsClefs($motsClefs); - $this->getMailService()->update($mail); + $rendu = $this->getRenduService()->generateRenduByTemplateCode($templateCode, $vars); + $mail = $this->getMailService()->sendMail($adresses, $rendu->getSujet(), $rendu->getCorps(), 'Formation'); + $motsClefs[] = $rendu->getTemplate()->generateTag(); + $mail->setMotsClefs($motsClefs); + $this->getMailService()->update($mail); return $mail; } catch (RuntimeException $e) { - $adresses = (is_array($adresses))?implode('|', $adresses):$adresses; - throw new RuntimeException("Un problème est survenu lors de l'envoi du mail vers [".$adresses."]",0,$e); + return null; } } @@ -216,14 +215,17 @@ class NotificationService $session = $inscrit->getSession(); if (!$session->isMailActive()) return null; - $vars = $this->generateVariableArray($inscrit); - $rendu = $this->getRenduService()->generateRenduByTemplateCode(MailTemplates::SESSION_LISTE_PRINCIPALE, $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 AND $inscrit->getIndividu()->getEmail() !== null) { + $vars = $this->generateVariableArray($inscrit); + $rendu = $this->getRenduService()->generateRenduByTemplateCode(MailTemplates::SESSION_LISTE_PRINCIPALE, $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; + } + return null; } /** Notification envoyée vers les inscrit·es de la liste complémentaire lors de la clôture des inscriptions */ @@ -233,14 +235,17 @@ class NotificationService if (!$session->isMailActive()) return null; $individu = $inscrit->getIndividu(); - $vars = $this->generateVariableArray($inscrit); - $rendu = $this->getRenduService()->generateRenduByTemplateCode(MailTemplates::SESSION_LISTE_COMPLEMENTAIRE, $vars); - $mail = $this->getMailService()->sendMail($individu->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 AND $inscrit->getIndividu()->getEmail() !== null) { + $vars = $this->generateVariableArray($inscrit); + $rendu = $this->getRenduService()->generateRenduByTemplateCode(MailTemplates::SESSION_LISTE_COMPLEMENTAIRE, $vars); + $mail = $this->getMailService()->sendMail($individu->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 l'agent lors de son retrait d'une liste */ @@ -249,14 +254,17 @@ class NotificationService $session = $inscrit->getSession(); if (!$session->isMailActive()) return null; - $vars = $this->generateVariableArray($inscrit); - $rendu = $this->getRenduService()->generateRenduByTemplateCode(MailTemplates::SESSION_LISTE_COMPLEMENTAIRE, $vars); - $mail = $this->getMailService()->sendMail($inscrit->getAgent()->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 AND $inscrit->getIndividu()->getEmail() !== null) { + $vars = $this->generateVariableArray($inscrit); + $rendu = $this->getRenduService()->generateRenduByTemplateCode(MailTemplates::SESSION_LISTE_COMPLEMENTAIRE, $vars); + $mail = $this->getMailService()->sendMail($inscrit->getAgent()->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 envoyée vers l'inscrit de la liste principale pour convocation */ @@ -390,17 +398,19 @@ class NotificationService $agent = $inscrit->getAgent(); if ($agent === null) throw new RuntimeException("Aucune personne d'identifié·e pour cette inscription"); - $vars = $this->generateVariableArray($inscrit); - $rendu = $this->getRenduService()->generateRenduByTemplateCode(MailTemplates::SESSION_ANNULEE, $vars); - $mail = $this->getMailService()->sendMail($inscrit->getAgent()->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 AND $inscrit->getIndividu()->getEmail() !== null) { + $vars = $this->generateVariableArray($inscrit); + $rendu = $this->getRenduService()->generateRenduByTemplateCode(MailTemplates::SESSION_ANNULEE, $vars); + $mail = $this->getMailService()->sendMail($inscrit->getAgent()->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; } - /** Mails de rappel ***********************************************************************************************/ public function triggerRappelAgentAvantFormation(Session $session): ?array @@ -433,20 +443,23 @@ class NotificationService $mails[] = $formateur->getEmail(); } - $urlService = $this->getUrlService()->setVariables(['instance' => $session]); - $vars = [ - 'session' => $session, - 'instance' => $session, - 'UrlService' => $urlService, - 'MacroService' => $this->getMacroService() - ]; - $rendu = $this->getRenduService()->generateRenduByTemplateCode(MailTemplates::SESSION_EMARGEMENT, $vars); - $mail = $this->getMailService()->sendMail(implode(",", $mails), $rendu->getSujet(), $rendu->getCorps(), 'Formation'); - $mail->setMotsClefs([$session->generateTag(), $rendu->getTemplate()->generateTag()]); - $this->getMailService()->update($mail); - $session->addMail($mail); - $this->getObjectManager()->flush($session); - return $mail; + if (!empty($mails)) { + $urlService = $this->getUrlService()->setVariables(['instance' => $session]); + $vars = [ + 'session' => $session, + 'instance' => $session, + 'UrlService' => $urlService, + 'MacroService' => $this->getMacroService() + ]; + $rendu = $this->getRenduService()->generateRenduByTemplateCode(MailTemplates::SESSION_EMARGEMENT, $vars); + $mail = $this->getMailService()->sendMail(implode(",", $mails), $rendu->getSujet(), $rendu->getCorps(), 'Formation'); + $mail->setMotsClefs([$session->generateTag(), $rendu->getTemplate()->generateTag()]); + $this->getMailService()->update($mail); + $session->addMail($mail); + $this->getObjectManager()->flush($session); + return $mail; + } + return null; } /** diff --git a/module/Formation/src/Formation/Service/Session/SessionService.php b/module/Formation/src/Formation/Service/Session/SessionService.php index c974a6f807f7606969edee03072c0e766bf3f712..f078aa280b4c154129d760686ee2213a0e49e0e7 100644 --- a/module/Formation/src/Formation/Service/Session/SessionService.php +++ b/module/Formation/src/Formation/Service/Session/SessionService.php @@ -335,48 +335,35 @@ class SessionService /** Fonctions associées aux états de l'instance *******************************************************************/ - - public function recreation(Session $instance): Session + /** @return Mail[] */ + public function ouvrirInscription(Session $session): array { - $this->getEtatInstanceService()->setEtatActif($instance, SessionEtats::ETAT_CREATION_EN_COURS); - $this->update($instance); - - return $instance; - } - - - /** - * @param Session $instance - * @return Session - */ - public function ouvrirInscription(Session $instance): Session - { - $this->getEtatInstanceService()->setEtatActif($instance, SessionEtats::ETAT_INSCRIPTION_OUVERTE); - $this->update($instance); - + $this->getEtatInstanceService()->setEtatActif($session, SessionEtats::ETAT_INSCRIPTION_OUVERTE); + $this->update($session); //notification abonnement - $abonnements = $instance->getFormation()->getAbonnements(); + $abonnements = $session->getFormation()->getAbonnements(); + $mails = []; foreach ($abonnements as $abonnement) { - if ($abonnement->estNonHistorise()) $this->getNotificationService()->triggerNouvelleSession($instance, $abonnement); + if ($abonnement->estNonHistorise()) { + $mails[$abonnement->getAgent()->getDenomination()] = $this->getNotificationService()->triggerNouvelleSession($session, $abonnement); + } } - return $instance; + return $mails; } - /** - * @param Session $instance - * @return Session - */ - public function fermerInscription(Session $instance): Session + /** @return Mail[] */ + public function fermerInscription(Session $session): array { - $this->getEtatInstanceService()->setEtatActif($instance, SessionEtats::ETAT_INSCRIPTION_FERMEE); - $this->update($instance); + $this->getEtatInstanceService()->setEtatActif($session, SessionEtats::ETAT_INSCRIPTION_FERMEE); + $this->update($session); - foreach ($instance->getListePrincipale() as $inscrit) { + $mails = []; + foreach ($session->getListePrincipale() as $inscrit) { $configuration = $this->getNotificationConfigurationService()->getNotificationConfigurationWithParams("SESSION", MailTemplates::SESSION_LISTE_PRINCIPALE, "Inscriptions closes"); - if ($configuration === null OR $configuration->isActive()) $this->getNotificationService()->triggerListePrincipale($inscrit); + if ($configuration === null OR $configuration->isActive()) $mails[$inscrit->getIndividu()->getDenomination() . " (Liste principale)"] = $this->getNotificationService()->triggerListePrincipale($inscrit); $agent = $inscrit->getAgent(); $formation = $inscrit->getSession()->getFormation(); @@ -385,19 +372,20 @@ class SessionService if ($abonnement !== null) $this->getAbonnementService()->retirerAbonnement($agent, $formation); } } - foreach ($instance->getListeComplementaire() as $inscrit) { + foreach ($session->getListeComplementaire() as $inscrit) { $configuration = $this->getNotificationConfigurationService()->getNotificationConfigurationWithParams("SESSION", MailTemplates::SESSION_LISTE_COMPLEMENTAIRE, "Inscriptions closes"); - if ($configuration === null OR $configuration->isActive()) $this->getNotificationService()->triggerListeComplementaire($inscrit); - - $agent = $inscrit->getAgent(); - $formation = $inscrit->getSession()->getFormation(); - if ($inscrit->isInterne()) { - $abonnement = $this->getAbonnementService()->getAbonnementByAgentAndFormation($agent, $formation); - if ($abonnement === null) $this->getAbonnementService()->ajouterAbonnement($agent, $formation); - } + if ($configuration === null OR $configuration->isActive()) $mails[$inscrit->getIndividu()->getDenomination() . " (Liste complémentaire)"] = $this->getNotificationService()->triggerListeComplementaire($inscrit); + + //NOTE :: sera fait à la cloture de la session plutôt qu'à la cloture +// $agent = $inscrit->getAgent(); +// $formation = $inscrit->getSession()->getFormation(); +// if ($inscrit->isInterne()) { +// $abonnement = $this->getAbonnementService()->getAbonnementByAgentAndFormation($agent, $formation); +// if ($abonnement === null) $this->getAbonnementService()->ajouterAbonnement($agent, $formation); +// } } - return $instance; + return $mails; } /** @return Mail[] $mails */ @@ -423,33 +411,35 @@ class SessionService } /** @return Mail[] $mails */ - public function demanderRetour(Session $instance): array + public function demanderRetour(Session $session): array { $mails = []; - $this->getEtatInstanceService()->setEtatActif($instance, SessionEtats::ETAT_ATTENTE_RETOURS); - $this->update($instance); + $this->getEtatInstanceService()->setEtatActif($session, SessionEtats::ETAT_ATTENTE_RETOURS); + $this->update($session); $configuration = $this->getNotificationConfigurationService()->getNotificationConfigurationWithParams("SESSION", MailTemplates::SESSION_DEMANDE_RETOUR, "Demande de retour"); if ($configuration === null OR $configuration->isActive()) { - foreach ($instance->getListePrincipale() as $inscrit) { + foreach ($session->getListePrincipale() as $inscrit) { $mails[$inscrit->getIndividu()->getDenomination()] = $this->getNotificationService()->triggerDemandeRetour($inscrit); } } return $mails; } - public function envoyerAbsence(Session $session, ?Inscription $inscription = null): Session + /** @return Mail[] */ + public function envoyerAbsence(Session $session, ?Inscription $inscription = null): array { $liste = []; if ($inscription !== null) $liste[] = $inscription; else $liste = $session->getListePrincipale(); + $mails = []; $configuration = $this->getNotificationConfigurationService()->getNotificationConfigurationWithParams("SESSION", MailTemplates::SESSION_ABSENCE, "Envoi des constats d'absence"); if ($configuration === null OR $configuration->isActive()) { foreach ($liste as $inscrit) { - if ($inscrit->estNonHistorise()) $this->getNotificationService()->triggerConstatAbsence($inscrit); + if ($inscrit->estNonHistorise()) $mails[] = $this->getNotificationService()->triggerConstatAbsence($inscrit); } } - return $session; + return $mails; } public function envoyerAttestation(Session $session, ?Inscription $inscription = null): Session @@ -465,68 +455,64 @@ class SessionService return $session; } - /** - * @param Session $instance - * @return Session - */ - public function envoyerEmargement(Session $instance): Session + /** @return Mail[] */ + public function envoyerEmargement(Session $session): array { - if ($instance->isEmargementActive()) { - $this->update($instance); + $mails = []; + if ($session->isEmargementActive()) { + $this->update($session); $configuration = $this->getNotificationConfigurationService()->getNotificationConfigurationWithParams("SESSION", MailTemplates::SESSION_EMARGEMENT, "Envoi de l'emargement"); if ($configuration === null OR $configuration->isActive()) { - $this->getNotificationService()->triggerLienPourEmargement($instance); + $mails[] = $this->getNotificationService()->triggerLienPourEmargement($session); } } - return $instance; + return $mails; } - /** - * @param Session $instance - * @return Session - */ - public function cloturer(Session $instance): Session + /** @return Mail[] */ + public function cloturer(Session $session): array { //changement de l'état de la session - $this->getEtatInstanceService()->setEtatActif($instance, SessionEtats::ETAT_CLOTURE_INSTANCE); - $this->update($instance); + $this->getEtatInstanceService()->setEtatActif($session, SessionEtats::ETAT_CLOTURE_INSTANCE); + $this->update($session); + $mails = []; //ajout d'un abonnement à la formation aux inscrits de la liste complémentaire - $formation = $instance->getFormation(); - foreach ($instance->getListeComplementaire() as $inscription) { - $agent = $inscription->getAgent(); - if ($agent !== null) { // exclusion des stagiaires externes - $abonnement = $this->getAbonnementService()->getAbonnementByAgentAndFormation($agent, $formation); - if ($abonnement === null) { - $this->getAbonnementService()->ajouterAbonnement($agent, $formation); - $this->getNotificationService()->triggerAjoutAbonnementPostCloture($inscription); + $formation = $session->getFormation(); + foreach ($session->getListeComplementaire() as $inscription) { + if ($inscription->isInterne()) { // exclusion des stagiaires externes + $agent = $inscription->getAgent(); + if ($agent !== null) { + $abonnement = $this->getAbonnementService()->getAbonnementByAgentAndFormation($agent, $formation); + if ($abonnement === null) { + $this->getAbonnementService()->ajouterAbonnement($agent, $formation); + $mails[] = $this->getNotificationService()->triggerAjoutAbonnementPostCloture($inscription); + } } } } - return $instance; + return $mails; } - /** - * @param Session $instance - * @return Session - */ - public function annuler(Session $instance): Session + /** @return Mail[] */ + public function annuler(Session $session): array { - $this->getEtatInstanceService()->setEtatActif($instance, SessionEtats::ETAT_SESSION_ANNULEE); - $this->update($instance); - foreach ($instance->getInscriptions() as $inscrit) { + $this->getEtatInstanceService()->setEtatActif($session, SessionEtats::ETAT_SESSION_ANNULEE); + $this->update($session); + $mails = []; + foreach ($session->getInscriptions() as $inscrit) { if (!$inscrit->isEtatActif(InscriptionEtats::ETAT_DESISTEMENT AND !$inscrit->isEtatActif(InscriptionEtats::ETAT_REFUSER))) { $configuration = $this->getNotificationConfigurationService()->getNotificationConfigurationWithParams("SESSION", MailTemplates::SESSION_ANNULEE, "Annulation de la session"); - if ($configuration === null or $configuration->isActive()) $this->getNotificationService()->triggerSessionAnnulee($inscrit); + if ($configuration === null or $configuration->isActive()) $mails[$inscrit->getStagiaireDenomination()] = $this->getNotificationService()->triggerSessionAnnulee($inscrit); $agent = $inscrit->getAgent(); $formation = $inscrit->getSession()->getFormation(); $abonnement = $this->getAbonnementService()->getAbonnementByAgentAndFormation($agent, $formation); - if ($abonnement === null) $this->getAbonnementService()->ajouterAbonnement($agent, $formation); + if ($abonnement === null) $mails[$agent->getDenomination()] = $this->getAbonnementService()->ajouterAbonnement($agent, $formation); } } - return $instance; + return $mails; } /** diff --git a/module/Formation/view/formation/session/afficher.phtml b/module/Formation/view/formation/session/afficher.phtml index 046e683c60ff91251398002459f345d4c43d3cda..c3544a07cce9d1dbd69a4e69921b404627ae99ea 100644 --- a/module/Formation/view/formation/session/afficher.phtml +++ b/module/Formation/view/formation/session/afficher.phtml @@ -129,7 +129,7 @@ $canMesSessions = $this->isAllowed(FormateurPrivileges::getResourceId(FormateurP <br/> <a <?php /** @see SessionController::ouvrirInscriptionAction() */ ?> href="<?php echo $this->url('session/ouvrir-inscription', ['session' => $session->getId()], [], true); ?>" - class="btn btn-primary"> + class="btn btn-primary ajax-modal"> Ouvrir les inscriptions </a> <?php endif; ?> @@ -137,7 +137,7 @@ $canMesSessions = $this->isAllowed(FormateurPrivileges::getResourceId(FormateurP <br/> <a <?php /** @see SessionController::fermerInscriptionAction() */ ?> href="<?php echo $this->url('session/fermer-inscription', ['session' => $session->getId()], [], true); ?>" - class="btn btn-primary"> + class="btn btn-primary ajax-modal"> Fermer les inscriptions </a> <?php endif; ?> @@ -161,7 +161,7 @@ $canMesSessions = $this->isAllowed(FormateurPrivileges::getResourceId(FormateurP <br/> <a <?php /** @see SessionController::cloturerAction() */ ?> href="<?php echo $this->url('session/cloturer', ['session' => $session->getId()], [], true); ?>" - class="btn btn-primary <?php if (!empty($presencesManquantes) or !empty($fraisManquants)) echo " disabled "; ?>"> + class="btn btn-primary ajax-modal <?php if (!empty($presencesManquantes) or !empty($fraisManquants)) echo " disabled "; ?>"> Clotûrer la session </a> <?php endif; ?> @@ -169,7 +169,7 @@ $canMesSessions = $this->isAllowed(FormateurPrivileges::getResourceId(FormateurP <?php if ($canGererInscription) : ?> <a <?php /** @see SessionController::changerEtatAction() */ ?> href="<?php echo $this->url('session/changer-etat', ['session' => $session->getId()], [], true); ?>" - class="btn btn-primary ajax-modal" data-event="modification"> + class="btn btn-warning ajax-modal" data-event="modification"> Changer l'état </a> <?php endif; ?> @@ -178,13 +178,13 @@ $canMesSessions = $this->isAllowed(FormateurPrivileges::getResourceId(FormateurP <?php if (!$session->isEtatActif(SessionEtats::ETAT_SESSION_ANNULEE)) : ?> <a <?php /** @see SessionController::annulerAction() */ ?> href="<?php echo $this->url('session/annuler', ['session' => $session->getId()], [], true); ?>" - class="btn btn-danger ajax-modal" data-event="modification"> + class="btn btn-danger ajax-modal" > Annuler la session </a> <?php else : ?> <a <?php /** @see SessionController::reouvrirAction() */ ?> href="<?php echo $this->url('session/reouvrir', ['session' => $session->getId()], [], true); ?>" - class="btn btn-primary"> + class="btn btn-primary ajax-modal"> Remettre la session en édition </a> <?php endif; ?>