From 2df89819a83e9f661545cbf2ecf67ce83029fedd Mon Sep 17 00:00:00 2001
From: "florian.joriot@unicaen.fr" <florian.joriot@unicaen.fr>
Date: Mon, 17 Apr 2023 11:17:41 +0200
Subject: [PATCH] Correction bug ajout de typeFormation bug
---
.../OffreFormation/config/module.config.php | 9 ++++-
.../Controller/TypeFormationController.php | 33 ++++++++++++++++---
.../type-formation/ajout.phtml | 7 ++++
.../type-formation/index.phtml | 2 +-
4 files changed, 45 insertions(+), 6 deletions(-)
create mode 100755 module/OffreFormation/view/offre-formation/type-formation/ajout.phtml
diff --git a/module/OffreFormation/config/module.config.php b/module/OffreFormation/config/module.config.php
index ced0b64dde..0e5ca9cda6 100755
--- a/module/OffreFormation/config/module.config.php
+++ b/module/OffreFormation/config/module.config.php
@@ -308,6 +308,13 @@ return [
],
'action' => 'saisie',
],
+ 'ajout' => [
+ 'route' => '/ajout/:groupeTypeFormation',
+ 'constraints' => [
+ 'typeFormation' => '[0-9]*',
+ ],
+ 'action' => 'ajout',
+ ],
'supprimer' => [
'route' => '/supprimer/:typeFormation',
'constraints' => [
@@ -550,7 +557,7 @@ return [
],
[
'controller' => TypeFormationController::class,
- 'action' => ['saisie', 'supprimer', 'saisieGroupe', 'supprimerGroupe', "trier"],
+ 'action' => ['saisie', 'ajout', 'supprimer', 'saisieGroupe', 'supprimerGroupe', "trier"],
'privileges' => [Privileges::ODF_TYPE_FORMATION_EDITION],
],
],
diff --git a/module/OffreFormation/src/Controller/TypeFormationController.php b/module/OffreFormation/src/Controller/TypeFormationController.php
index 7bbb50c304..998d6a3aeb 100644
--- a/module/OffreFormation/src/Controller/TypeFormationController.php
+++ b/module/OffreFormation/src/Controller/TypeFormationController.php
@@ -56,13 +56,12 @@ class TypeFormationController extends AbstractController
]);
$typeFormation = $this->getEvent()->getParam('typeFormation');
-
- $form = $this->getFormTypeFormationTypeFormationSaisie();
+ $form = $this->getFormTypeFormationTypeFormationSaisie();
if (empty($typeFormation)) {
- $title = "Création d'un nouveau type de formation";
+ $title = "Création d'un nouveau type de formation";
/** @var TypeFormation $typeFormation */
- $typeFormation = $this->getServiceTypeFormation()->newEntity();
+ $typeFormation = $this->getServiceTypeFormation()->newEntity();
$groupeTypeFormation = $this->getEvent()->getParam('groupeTypeFormation');
$typeFormation->setGroupe($groupeTypeFormation);
} else {
@@ -82,6 +81,32 @@ class TypeFormationController extends AbstractController
+ public function ajoutAction()
+ {
+ $this->em()->getFilters()->enable('historique')->init([
+ GroupeTypeFormation::class,
+ ]);
+
+ $form = $this->getFormTypeFormationTypeFormationSaisie();
+ $title = "Création d'un nouveau type de formation";
+ /** @var TypeFormation $typeFormation */
+ $typeFormation = $this->getServiceTypeFormation()->newEntity();
+ $groupeTypeFormation = $this->getEvent()->getParam('groupeTypeFormation');
+ $typeFormation->setGroupe($groupeTypeFormation);
+
+ $form->bindRequestSave($typeFormation, $this->getRequest(), function () use ($typeFormation, $form) {
+
+ $this->getServiceTypeFormation()->save($typeFormation);
+ $this->flashMessenger()->addSuccessMessage(
+ "Ajout réussi"
+ );
+ });
+
+ return compact('form', 'title');
+ }
+
+
+
public function saisieGroupeAction()
{
$groupeTypeFormation = $this->getEvent()->getParam('groupeTypeFormation');
diff --git a/module/OffreFormation/view/offre-formation/type-formation/ajout.phtml b/module/OffreFormation/view/offre-formation/type-formation/ajout.phtml
new file mode 100755
index 0000000000..ac28762d2c
--- /dev/null
+++ b/module/OffreFormation/view/offre-formation/type-formation/ajout.phtml
@@ -0,0 +1,7 @@
+<?php
+/**
+ * @var $this \Application\View\Renderer\PhpRenderer
+ */
+
+echo $this->messenger()->addCurrentMessagesFromFlashMessenger();
+echo $this->form($form);
diff --git a/module/OffreFormation/view/offre-formation/type-formation/index.phtml b/module/OffreFormation/view/offre-formation/type-formation/index.phtml
index 38b071c75d..15df23feeb 100755
--- a/module/OffreFormation/view/offre-formation/type-formation/index.phtml
+++ b/module/OffreFormation/view/offre-formation/type-formation/index.phtml
@@ -86,7 +86,7 @@ echo $this->messenger()->addCurrentMessagesFromFlashMessenger();
<?php if ($canEdit): ?>
<tr class="champ-triable">
<a class="btn btn-primary ajax-modal " data-event="type-formation-edition"
- href="<?= $this->url('type-formation/saisie', ['typeFormation' => '', 'groupeTypeFormation' => $groupeTypeFormation->getId()]); ?>"><i
+ href="<?= $this->url('type-formation/ajout', ['groupeTypeFormation' => $groupeTypeFormation->getId()]); ?>"><i
class="fas fa-plus"></i>
Ajout d'un nouveau type de formation</a>
</tr>
--
GitLab