Commit 796dd335 authored by Thomas Hamel's avatar Thomas Hamel
Browse files

ajout d'un template et envoi d'un mail aux doctorants concernés lors de la...

ajout d'un template et envoi d'un mail aux doctorants concernés lors de la création/modif d'une formation spécifique
parent 4e080a3a
Loading
Loading
Loading
Loading
+10 −0
Changes for doc/release-notes/8.2.0/01_formation.sql: 10 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -62,3 +62,13 @@ from PROFIL_TO_ROLE p2r
         join PROFIL_PRIVILEGE pp on pp.PROFIL_ID = pr.id
where not exists (select * from role_privilege where role_id = p2r.role_id and privilege_id = pp.privilege_id)
;

-- Template mail lors de la création d'une formation spécifique à destination des doctorants de l'ED
INSERT INTO public.unicaen_renderer_template (code, description, document_type, document_sujet, document_corps,
                                              document_css, namespace)
VALUES ('FORMATION_FORMATION_SPECIFIQUE_OUVERTE',
        '<p>Mail envoyé au doctorant·e lorsqu''une formation spécifique est ouverte au sein de leur ED</p>', 'mail',
        'Nouvelle formation spécifique ouverte dans votre ED', e'<p>Bonjour,</p>
<p>La formation <strong>VAR[Formation#Libelle]</strong> vient d\'ouvrir dans votre École Doctorale. Si vous voulez plus d\'informations, rendez-vous dans l\'application ESUP-SyGAL, onglet <em>\'mes formations\'.</em></p>
<p>En vous souhaitant une bonne journée,<br />VAR[Formation#Responsable]</p>',
        null, 'Formation\Provider\Template');
 No newline at end of file
+33 −0
Changes for module/Formation/src/Formation/Controller/FormationController.php: 33 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -4,8 +4,11 @@ namespace Formation\Controller;

use Application\Controller\AbstractController;
use Formation\Service\Module\ModuleServiceAwareTrait;
use Formation\Service\Notification\FormationNotificationFactoryAwareTrait;
use Formation\Service\Session\SessionServiceAwareTrait;
use Laminas\Http\Response;
use Notification\Exception\RuntimeException;
use Notification\Service\NotifierServiceAwareTrait;
use Structure\Service\Etablissement\EtablissementServiceAwareTrait;
use Formation\Entity\Db\Formation;
use Formation\Form\Formation\FormationFormAwareTrait;
@@ -20,6 +23,8 @@ class FormationController extends AbstractController
    use ModuleServiceAwareTrait;
    use SessionServiceAwareTrait;
    use FormationFormAwareTrait;
    use NotifierServiceAwareTrait;
    use FormationNotificationFactoryAwareTrait;

    use EtablissementServiceAwareTrait;

@@ -51,6 +56,19 @@ class FormationController extends AbstractController
            $form->setData($data);
            if ($form->isValid()) {
                $this->getFormationService()->create($formation);
                //Envoi d'un mail lors de la création d'une formation spécifique à la liste de diffusion du site déclaré
                if($formation->getType() === Formation::TYPE_CODE_SPECIFIQUE && $formation->getSite() && $formation->getTypeStructure()){
                    try {
                        $notif = $this->formationNotificationFactory->createNotificationFormationSpecifiqueAjoutee($formation);
                        $this->notifierService->trigger($notif);
                        $this->flashMessenger()->addInfoMessage("Une notification par mail a été envoyée aux doctorants appartenant au site organisateur {$formation->getSite()}, et à l'ED {$formation->getTypeStructure()}.");
                    } catch (RuntimeException $e) {
                        $ed = $formation->getTypeStructure()->getEcoleDoctorale();
                        $this->flashMessenger()->addErrorMessage("La session a bien été créee, cependant aucune liste de diffusion trouvée pour l'ED {$ed} (afin de notifier les doctorants).");
                    }
                }else if($formation->getType() === Formation::TYPE_CODE_SPECIFIQUE && !($formation->getSite() && $formation->getTypeStructure())){
                    $this->flashMessenger()->addWarningMessage("La session a bien été créee, cependant si vous voulez la notification des doctorants de l'ouverture de cette formation spécifique ({$formation->getLibelle()}), il faut renseigner le site organisateur et la structure associée.");
                }
            }
        }

@@ -70,11 +88,26 @@ class FormationController extends AbstractController
        $form->setAttribute('action', $this->url()->fromRoute('formation/formation/modifier', [], [], true));
        $form->bind($formation);

        $oldSite = $formation->getSite();
        $oldStructure = $formation->getTypeStructure();
        $request = $this->getRequest();
        if ($request->isPost()) {
            $data = $request->getPost();
            $form->setData($data);
            if ($form->isValid()) {
                // Envoi d'un mail lors de la création d'une formation spécifique à la liste de diffusion du site déclaré
                // seulement si le site et la structure ont été renseignés
                // et des informations ont été modifiées
                if ($formation->getType() === Formation::TYPE_CODE_SPECIFIQUE && ($formation->getSite() && $formation->getTypeStructure()) && ($formation->getSite() !== $oldSite || $formation->getTypeStructure() !== $oldStructure)) {
                    try {
                        $notif = $this->formationNotificationFactory->createNotificationFormationSpecifiqueAjoutee($formation);
                        $this->notifierService->trigger($notif);
                        $this->flashMessenger()->addInfoMessage("Le site organisateur et/ou la structure associée ont été modifiés. <br>Une notification par mail a donc été envoyée aux doctorants appartenant au site organisateur {$formation->getSite()}, et à l'ED {$formation->getTypeStructure()}.");
                    } catch (RuntimeException $e) {
                        $ed = $formation->getTypeStructure()->getEcoleDoctorale();
                        $this->flashMessenger()->addErrorMessage("La session a bien été modifiée, cependant aucune liste de diffusion trouvée pour l'ED {$ed} (afin de notifier les doctorants).");
                    }
                }
                $this->getFormationService()->update($formation);
            }
        }
+8 −0
Changes for module/Formation/src/Formation/Controller/FormationControllerFactory.php: 8 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -3,7 +3,9 @@
namespace Formation\Controller;

use Formation\Service\Module\ModuleService;
use Formation\Service\Notification\FormationNotificationFactory;
use Formation\Service\Session\SessionService;
use Notification\Service\NotifierService;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use Structure\Service\Etablissement\EtablissementService;
@@ -34,6 +36,9 @@ class FormationControllerFactory {
        $formationService = $container->get(FormationService::class);
        $moduleService = $container->get(ModuleService::class);
        $sessionService = $container->get(SessionService::class);
        $notificationService = $container->get(NotifierService::class);
        /** @var FormationNotificationFactory $formationNotificationFactory */
        $formationNotificationFactory = $container->get(FormationNotificationFactory::class);

        /**
         * @var FormationForm $formationForm
@@ -47,6 +52,9 @@ class FormationControllerFactory {
        $controller->setModuleService($moduleService);
        $controller->setSessionService($sessionService);
        $controller->setFormationForm($formationForm);
        $controller->setNotifierService($notificationService);
        $controller->setFormationNotificationFactory($formationNotificationFactory);

        return $controller;
    }
}
 No newline at end of file
+1 −0
Changes for module/Formation/src/Formation/Controller/ModuleController.php: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -145,6 +145,7 @@ class ModuleController extends AbstractController

        return new ViewModel([
            'modules' => $modules,
            'anneeUniversitaire' => $anneeUniv
        ]);
    }
}
 No newline at end of file
+4 −1
Changes for module/Formation/src/Formation/Provider/Template/MailTemplates.php: 4 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -2,7 +2,8 @@

namespace Formation\Provider\Template;

class MailTemplates {
class MailTemplates
{

    const INSCRIPTION_ENREGISTREE = "FORMATION_INSCRIPTION_ENREGISTREE";
    const INSCRIPTION_LISTE_PRINCIPALE = "FORMATION_INSCRIPTION_LISTE_PRINCIPALE";
@@ -15,4 +16,6 @@ class MailTemplates {
    const SESSION_TERMINEE = "FORMATION_SESSION_TERMINEE";
    const SESSION_ANNULEE = "FORMATION_SESSION_ANNULEE";

    const FORMATION_SPECIFIQUE_AJOUTEE = "FORMATION_FORMATION_SPECIFIQUE_OUVERTE";

}
 No newline at end of file
Loading