From 82fa6eca52ad4258e09b25e96289f3795962d7f6 Mon Sep 17 00:00:00 2001 From: Erwann PHILIPPE Date: Mon, 19 Jan 2026 17:22:18 +0100 Subject: [PATCH] =?UTF-8?q?M2T1=20:=20g=C3=A9rer=20les=20formations?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/AdminFormationsController.php | 87 +++++++++++++++++++ src/Entity/Formation.php | 2 + src/Form/FormationType.php | 55 ++++++++++++ templates/baseadmin.html.twig | 41 +++++++++ templates/basefront.html.twig | 2 +- .../pages/admin/admin.addFormation.html.twig | 25 ++++++ .../pages/admin/admin.formations.html.twig | 85 ++++++++++++++++++ templates/pages/formations.html.twig | 2 +- 8 files changed, 297 insertions(+), 2 deletions(-) create mode 100644 src/Controller/admin/AdminFormationsController.php create mode 100644 src/Form/FormationType.php create mode 100644 templates/baseadmin.html.twig create mode 100644 templates/pages/admin/admin.addFormation.html.twig create mode 100644 templates/pages/admin/admin.formations.html.twig diff --git a/src/Controller/admin/AdminFormationsController.php b/src/Controller/admin/AdminFormationsController.php new file mode 100644 index 0000000..bed6f73 --- /dev/null +++ b/src/Controller/admin/AdminFormationsController.php @@ -0,0 +1,87 @@ +formationRepository = $formationRepository; + $this->categorieRepository = $categorieRepository; + } + + #[Route('/admin', name: 'admin.formations')] + public function index() : Response + { + $formations = $this->formationRepository->findAllOrderBy('publishedAt', 'DESC'); + $categories = $this->categorieRepository->findAll(); + return $this->render("pages/admin/admin.formations.html.twig", [ + 'formations' => $formations, + 'categories' => $categories + ]); + } + + #[Route('/admin/formations/tri/{champ}/{ordre}/{table}', name: 'admin.formations.sort')] + public function sort($champ, $ordre, $table=""): Response{ + $formations = $this->formationRepository->findAllOrderBy($champ, $ordre, $table); + $categories = $this->categorieRepository->findAll(); + return $this->render($this->adminPage, [ + 'formations' => $formations, + 'categories' => $categories + ]); + } + + #[Route('/admin/recherche/{champ}/{table}', name: 'admin.formations.findallcontain')] + public function findAllContain($champ, Request $request, $table=""): Response{ + $valeur = $request->get("recherche"); + $formations = $this->formationRepository->findByContainValue($champ, $valeur, $table); + $categories = $this->categorieRepository->findAll(); + return $this->render($this->adminPage, [ + 'formations' => $formations, + 'categories' => $categories, + 'valeur' => $valeur, + 'table' => $table + ]); + } + + #[Route('/admin/creerFormation', name: 'admin.creerFormation')] + public function afficherCreerFormation(Request $request) : Response{ + $formation = new Formation; + $formCreateFormation = $this->createForm(FormationType::class, $formation); + $formCreateFormation->handleRequest($request); + + if($formCreateFormation->isSubmitted() && $formCreateFormation->isValid()){ + $this->formationRepository->add($formation); + $this->addFlash('success', 'La formation a bien été créée !'); + return $this->redirectToRoute('admin.formations'); + } + + return $this->render('pages/admin/admin.addFormation.html.twig', [ + 'formCreateFormation'=> $formCreateFormation->createView() + ]); + } + + #[Route('/admin/remove/{id}', name: 'admin.formations.remove')] + public function remove(int $id) + { + $formation = $this->formationRepository->find($id); + $this->formationRepository->remove($formation); + return $this->redirectToRoute('admin.formations'); + } +} diff --git a/src/Entity/Formation.php b/src/Entity/Formation.php index 86f8e9c..5d09d5e 100644 --- a/src/Entity/Formation.php +++ b/src/Entity/Formation.php @@ -7,6 +7,7 @@ use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; +use Symfony\Component\Validator\Constraints as Assert; #[ORM\Entity(repositoryClass: FormationRepository::class)] class Formation @@ -23,6 +24,7 @@ class Formation private ?int $id = null; #[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)] + #[Assert\LessThanOrEqual('now', message:"La date ne peut pas être postétrieure à aujourd'hui.")] private ?\DateTimeInterface $publishedAt = null; #[ORM\Column(length: 100, nullable: true)] diff --git a/src/Form/FormationType.php b/src/Form/FormationType.php new file mode 100644 index 0000000..dd5f56b --- /dev/null +++ b/src/Form/FormationType.php @@ -0,0 +1,55 @@ +add('publishedAt', null, [ + 'widget' => 'single_text', + 'required' => 'true' + ]) + ->add('title', null, [ + 'required' => 'true' + ]) + ->add('description', null, [ + 'required' => 'false' + ]) + ->add('videoId', null, [ + 'required' => 'true' + ]) + ->add('playlist', EntityType::class, [ + 'class' => Playlist::class, + 'choice_label' => 'name', + 'required' => 'true' + ]) + ->add('categories', EntityType::class, [ + 'class' => Categorie::class, + 'choice_label' => 'name', + 'multiple' => true, + 'required' => false, + ]) + ->add('submit', SubmitType::class, [ + 'label' => 'Enregistrer' + ]) + ; + } + + public function configureOptions(OptionsResolver $resolver): void + { + $resolver->setDefaults([ + 'data_class' => Formation::class, + ]); + } +} diff --git a/templates/baseadmin.html.twig b/templates/baseadmin.html.twig new file mode 100644 index 0000000..e7e87e1 --- /dev/null +++ b/templates/baseadmin.html.twig @@ -0,0 +1,41 @@ +{% extends "base.html.twig" %} + +{% block title %}{% endblock %} +{% block stylesheets %}{% endblock %} +{% block top %} +
+ +
+ Bannière Mediatek Formation +
+ + +
+{% endblock %} +{% block body %}{% endblock %} +{% block footer %} +
+ +
+{% endblock %} +{% block javascripts %}{% endblock %} \ No newline at end of file diff --git a/templates/basefront.html.twig b/templates/basefront.html.twig index fcb998e..e7e87e1 100644 --- a/templates/basefront.html.twig +++ b/templates/basefront.html.twig @@ -6,7 +6,7 @@
- + Bannière Mediatek Formation
- + catégories