Commit 1402b619 authored by Thomas Hamel's avatar Thomas Hamel
Browse files

Merge branch 'ameliorations_module_formation' into test

parents 0b90b40d 35b92e04
Loading
Loading
Loading
Loading
+11 −0
Changes for doc/release-notes/v10/10.6.0/formation.sql: 11 added lines, 0 removed lines.
Original line number Diff line number Diff line
INSERT INTO public.unicaen_renderer_template (code, description, document_type, document_sujet, document_corps,
                                              document_css, namespace)
VALUES ('FORMATION_SEANCE_MODIFIEE', '<p>Mail envoyé aux inscrits (en liste principale et complémentaire) lors d''une modification sur une séance (date, heure, lieu)</p>', 'mail',
        'Changement d’horaire ou de lieu pour la formation : VAR[Formation#Libelle]', e'<p>Bonjour,</p>
<p>Les informations d''une ou des séances de la formation <strong>VAR[Formation#Libelle]</strong> ont été modifiées.</p>
<p>Celle-ci se déroulera selon les dates suivantes :<br>VAR[Session#SeancesTable]</p>
<p>Merci de prendre en compte ces changements et de bien réserver cette date dans votre agenda.</p>
<p>En cas d’empêchement pensez à vous désinscrire afin de libérer votre place.</p>
<p>Cordialement,<br>VAR[Formation#Responsable]</p>',
        '',
        'Formation\Provider\Template');
 No newline at end of file
+43 −1
Changes for module/Formation/src/Formation/Controller/SeanceController.php: 43 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -7,13 +7,17 @@ use Application\Service\AnneeUniv\AnneeUnivServiceAwareTrait;
use Fichier\Service\Fichier\FichierStorageServiceAwareTrait;
use Fichier\Service\Storage\Adapter\Exception\StorageAdapterException;
use Formation\Entity\Db\Seance;
use Formation\Entity\Db\Session;
use Formation\Form\Seance\SeanceFormAwareTrait;
use Formation\Service\Exporter\Emargement\EmargementExporter;
use Formation\Service\Notification\FormationNotificationFactoryAwareTrait;
use Formation\Service\Seance\SeanceServiceAwareTrait;
use Formation\Service\Session\SessionServiceAwareTrait;
use Laminas\Http\Response;
use Laminas\View\Model\ViewModel;
use Laminas\View\Renderer\PhpRenderer;
use Notification\Exception\RuntimeException as NotificationRuntimeException;
use Notification\Service\NotifierServiceAwareTrait;
use Structure\Service\Etablissement\EtablissementServiceAwareTrait;
use UnicaenApp\Exception\RuntimeException;
use UnicaenApp\Service\EntityManagerAwareTrait;
@@ -27,6 +31,8 @@ class SeanceController extends AbstractController
    use SessionServiceAwareTrait;
    use SeanceFormAwareTrait;
    use AnneeUnivServiceAwareTrait;
    use FormationNotificationFactoryAwareTrait;
    use NotifierServiceAwareTrait;

    private ?PhpRenderer $renderer = null;
    public function setRenderer(PhpRenderer $renderer) { $this->renderer = $renderer; }
@@ -85,7 +91,20 @@ class SeanceController extends AbstractController
            $data = $request->getPost();
            $form->setData($data);
            if ($form->isValid()) {
                try {
                    $this->getSeanceService()->update($seance);
                    $sendMail = $form->get('send_mail');
                    if($sendMail->getValue() === '1'){
                        $allMailsSent = $this->triggerNotificationSeanceModifiee($seance->getSession());
                        if($allMailsSent) $this->flashMessenger()->addSuccessMessage('La séance a bien été mise à jour. <br>Les inscrits (en liste principale et complémentaire) ont bien été notifiés des modifications.');
                    }else{
                        $this->flashMessenger()->addSuccessMessage('La séance a bien été mise à jour.');
                    }
                } catch (\RuntimeException $e) {
                    $this->flashMessenger()->addErrorMessage(
                        "La séance n'a pas été mise à jour, une erreur s'est produite :".$e->getMessage()
                    );
                }
            }
        }

@@ -93,7 +112,6 @@ class SeanceController extends AbstractController
            'title' => "Ajout d'une séance pour la seance de formation #".$seance->getId(),
            'form' => $form,
        ]);
        $vm->setTemplate('formation/default/default-form');
        return $vm;
    }

@@ -198,4 +216,28 @@ class SeanceController extends AbstractController
        ]);
        $export->export('SYGAL_emargement_' . $session->getId() . "_" . $seance->getId() . ".pdf");
    }

    private function triggerNotificationSeanceModifiee(Session $session): bool
    {
        $hasError = false;

        $principale = $session->getListePrincipale();
        $complementaire = $session->getListeComplementaire();

        $inscriptions = array_merge($principale, $complementaire);

        foreach ($inscriptions as $inscription) {
            try {
                $notif = $this->formationNotificationFactory->createNotificationSeanceModifiee($inscription);
                $this->notifierService->trigger($notif);
            } catch (NotificationRuntimeException $e) {
                $hasError = true;
                $this->flashMessenger()->addErrorMessage(
                    "Une erreur s'est produite dans l'envoi du mail : ".$e->getMessage()
                );
            }
        }

        return !$hasError;
    }
}
 No newline at end of file
+8 −0
Changes for module/Formation/src/Formation/Controller/SeanceControllerFactory.php: 8 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -4,7 +4,9 @@ namespace Formation\Controller;

use Application\Service\AnneeUniv\AnneeUnivService;
use Fichier\Service\Fichier\FichierStorageService;
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;
@@ -31,6 +33,8 @@ class SeanceControllerFactory {
         * @var SeanceService $seanceService
         * @var SessionService $sessionService
         * @var AnneeUnivService $anneeUnivService
         * @var AnneeUnivService $anneeUnivService
         * @var NotifierService $notifierService
         */
        $entityManager = $container->get('doctrine.entitymanager.orm_default');
        $etablissementService = $container->get(EtablissementService::class);
@@ -38,6 +42,8 @@ class SeanceControllerFactory {
        $seanceService = $container->get(SeanceService::class);
        $sessionService = $container->get(SessionService::class);
        $anneeUnivService = $container->get(AnneeUnivService::class);
        $formationNotificationFactory = $container->get(FormationNotificationFactory::class);
        $notifierService = $container->get(NotifierService::class);

        /**
         * @var SeanceForm $seanceForm
@@ -55,6 +61,8 @@ class SeanceControllerFactory {
        $controller->setSeanceService($seanceService);
        $controller->setSessionService($sessionService);
        $controller->setAnneeUnivService($anneeUnivService);
        $controller->setFormationNotificationFactory($formationNotificationFactory);
        $controller->setNotifierService($notifierService);
        /** forms *****************************************************************************************************/
        $controller->setSeanceForm($seanceForm);
        /** autre *****************************************************************************************************/
+15 −0
Changes for module/Formation/src/Formation/Form/Seance/SeanceForm.php: 15 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@
namespace Formation\Form\Seance;

use Application\Utils\FormUtils;
use Laminas\Form\Element\Checkbox;
use Laminas\Form\Element\Date;
use Laminas\Form\Element\Text;
use Laminas\Form\Element\Textarea;
@@ -111,6 +112,20 @@ class SeanceForm extends Form {
            ],
        ]);

        $this->add([
            'name' => 'send_mail',
            'type' => Checkbox::class,
            'options' => [
                'label' => 'Envoyer un mail aux inscrits leur notifiant les changements effectués ?',
                'use_hidden_element' => true,
                'checked_value' => '1',
                'unchecked_value' => '0',
            ],
            'attributes' => [
                'id' => 'send_mail',
            ],
        ]);

        FormUtils::addSaveButton($this);

        $this->setInputFilter((new Factory())->createInputFilter([
+2 −1
Changes for module/Formation/src/Formation/Provider/Template/MailTemplates.php: 2 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -17,10 +17,11 @@ class MailTemplates
    const SESSION_ANNULEE = "FORMATION_SESSION_ANNULEE";
    const SESSION_ABSENCES_INJUSTIFIEES = "FORMATION_SESSION_ABSENCES_INJUSTIFIEES";

    const SEANCE_MODIFIEE = "FORMATION_SEANCE_MODIFIEE";

    public const FORMATION_SPECIFIQUE_AJOUTEE = "FORMATION_FORMATION_SPECIFIQUE_OUVERTE";

    public const TRANSMETTRE_LISTE_INSCRITS_FORMATEURS = "FORMATION_TRANSMETTRE_LISTE_INSCRITS_FORMATEURS";

    public const FORMATION_EXTERNE_AJOUTEE = "FORMATION_EXTERNE_AJOUTEE";

}
 No newline at end of file
Loading