From 455d419166c1163123a0b1392defddc48bc92a1a Mon Sep 17 00:00:00 2001 From: marvin Date: Tue, 19 Nov 2024 16:55:30 +0100 Subject: [PATCH] =?UTF-8?q?forme=20cr=C3=A9ation=20sortie?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Controller/SortieController.php | 14 +-- src/Controller/VilleController.php | 33 ++++-- src/Form/SortieType.php | 37 +++--- templates/lieu/index.html.twig | 20 ++++ templates/sortie/create.html.twig | 169 ++++++++++++++++++++++++++++ templates/sortie/index.html.twig | 14 +++ templates/ville/index.html.twig | 20 ++++ 7 files changed, 276 insertions(+), 31 deletions(-) create mode 100644 templates/lieu/index.html.twig create mode 100644 templates/sortie/create.html.twig create mode 100644 templates/sortie/index.html.twig create mode 100644 templates/ville/index.html.twig diff --git a/src/Controller/SortieController.php b/src/Controller/SortieController.php index 096bf50..33f0aa1 100644 --- a/src/Controller/SortieController.php +++ b/src/Controller/SortieController.php @@ -4,6 +4,8 @@ namespace App\Controller; use App\Entity\Sortie; use App\Form\SortieType; +use App\Repository\LieuRepository; +use App\Repository\VilleRepository; use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; @@ -18,25 +20,23 @@ class SortieController extends AbstractController { $sortie = new Sortie(); - // Créer le formulaire + // Créez le formulaire sans options spéciales $form = $this->createForm(SortieType::class, $sortie); - - // Traiter la requête $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { - // Sauvegarder dans la base de données + // Sauvegarde dans la base de données $entityManager->persist($sortie); $entityManager->flush(); - // Rediriger après soumission - $this->addFlash('success', 'Sortie créée avec succès !'); + $this->addFlash('success', 'La sortie a été créée avec succès.'); + return $this->redirectToRoute('sortie_create'); } - // Afficher le formulaire return $this->render('sortie/create.html.twig', [ 'form' => $form->createView(), ]); } + } diff --git a/src/Controller/VilleController.php b/src/Controller/VilleController.php index 2dbe585..70e43f8 100644 --- a/src/Controller/VilleController.php +++ b/src/Controller/VilleController.php @@ -3,6 +3,8 @@ namespace App\Controller; use App\Entity\Ville; +use App\Repository\LieuRepository; +use App\Repository\VilleRepository; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Response; @@ -10,19 +12,36 @@ use Symfony\Component\Routing\Attribute\Route; class VilleController extends AbstractController { - #[Route('/get-lieux/{id}', name: 'get_lieux')] - public function getLieux(Ville $ville): JsonResponse - { - $lieux = $ville->getLieux(); - $data = []; + #[Route('/get-lieux/{id}', name: 'get_lieux', methods: ['GET'])] + public function getLieux(string $id, VilleRepository $villeRepository, LieuRepository $lieuRepository): JsonResponse + { + // Trouve la ville correspondant à l'ID (GUID) + $ville = $villeRepository->find($id); + + if (!$ville) { + return new JsonResponse(['error' => 'Ville non trouvée'], Response::HTTP_NOT_FOUND); + } + + // Trouve tous les lieux associés à la ville + $lieux = $lieuRepository->findBy(['ville' => $ville]); + $response = []; + foreach ($lieux as $lieu) { - $data[] = [ + $response[] = [ 'id' => $lieu->getIdLieu(), 'nom' => $lieu->getNom(), + 'rue' => $lieu->getRue(), + 'codePostal' => $lieu->getVille()->getCodePostal(), + 'latitude' => $lieu->getLatitude(), + 'longitude' => $lieu->getLongitude(), ]; } - return new JsonResponse($data); + return new JsonResponse($response); } + + + + } diff --git a/src/Form/SortieType.php b/src/Form/SortieType.php index ef0425c..c63d691 100644 --- a/src/Form/SortieType.php +++ b/src/Form/SortieType.php @@ -7,6 +7,7 @@ use App\Entity\Lieu; use App\Entity\Participant; use App\Entity\Site; use App\Entity\Sortie; +use App\Entity\Ville; use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\IntegerType; @@ -24,46 +25,48 @@ class SortieType extends AbstractType $builder ->add('nom', TextType::class, [ 'label' => 'Nom de la sortie', + 'attr' => ['class' => 'form-control'], ]) ->add('dateHeureDebut', DateTimeType::class, [ 'label' => 'Date et heure de début', - 'widget' => 'single_text', // Permet d'utiliser un champ HTML5 + 'widget' => 'single_text', 'html5' => true, + 'attr' => ['class' => 'form-control'], ]) ->add('duree', IntegerType::class, [ 'label' => 'Durée (en minutes)', + 'attr' => ['class' => 'form-control'], ]) ->add('dateLimiteInscription', DateType::class, [ 'label' => "Date limite d'inscription", 'widget' => 'single_text', 'html5' => true, + 'attr' => ['class' => 'form-control'], ]) ->add('nbInscriptionsMax', IntegerType::class, [ 'label' => 'Nombre maximum de participants', + 'attr' => ['class' => 'form-control'], ]) ->add('infosSortie', TextareaType::class, [ 'label' => 'Informations complémentaires', 'required' => false, + 'attr' => ['class' => 'form-control'], ]) - ->add('site', EntityType::class, [ - 'class' => Site::class, - 'choice_label' => 'nom', // Utilise le nom du site comme libellé - 'label' => 'Site organisateur', - ]) - ->add('participant', EntityType::class, [ - 'class' => Participant::class, - 'choice_label' => 'nom', // Utilise le nom du participant - 'label' => 'Organisateur', + ->add('ville', EntityType::class, [ + 'class' => Ville::class, + 'choice_label' => 'nom', + 'mapped' => false, // Non lié à l'entité Sortie + 'label' => 'Ville', + 'placeholder' => 'Sélectionnez une ville', + 'attr' => ['id' => 'ville-select'], ]) ->add('lieu', EntityType::class, [ 'class' => Lieu::class, - 'choice_label' => 'nom', // Utilise le nom du lieu - 'label' => 'Lieu de la sortie', - ]) - ->add('etat', EntityType::class, [ - 'class' => Etat::class, - 'choice_label' => 'libelle', // Utilise le nom de l'état - 'label' => 'État de la sortie', + 'choice_label' => 'nom', + 'label' => 'Lieu', + 'placeholder' => 'Sélectionnez une ville d\'abord', + 'choices' => [], // Pas de choix au début + 'attr' => ['id' => 'lieu-select'], ]); } diff --git a/templates/lieu/index.html.twig b/templates/lieu/index.html.twig new file mode 100644 index 0000000..04f2df6 --- /dev/null +++ b/templates/lieu/index.html.twig @@ -0,0 +1,20 @@ + + +Hello LieuController! + +{% block body %} + + +
+

Hello {{ controller_name }}! ✅

+ + This friendly message is coming from: + +
+{% endblock %} diff --git a/templates/sortie/create.html.twig b/templates/sortie/create.html.twig new file mode 100644 index 0000000..2963bc5 --- /dev/null +++ b/templates/sortie/create.html.twig @@ -0,0 +1,169 @@ +{% extends 'main/base.html.twig' %} + +{% block head %} + + + Créer une sortie + {% block stylesheets %} + {{ encore_entry_link_tags('app') }} + + + {% endblock %} + +{% endblock %} + +{% block content %} +
+ +
+

Créer une sortie

+ + + {{ form_start(form, { 'attr': { 'class': 'space-y-6' } }) }} + +
+ +
+ {{ form_row(form.nom, {'label': 'Nom de la sortie', 'attr': {'class': 'block w-full p-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500'}}) }} + {{ form_row(form.dateHeureDebut, {'label': 'Date et heure de la sortie', 'attr': {'class': 'block w-full p-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500'}}) }} + {{ form_row(form.dateLimiteInscription, {'label': 'Date limite d\'inscription', 'attr': {'class': 'block w-full p-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500'}}) }} + {{ form_row(form.nbInscriptionsMax, {'label': 'Nombre de places', 'attr': {'class': 'block w-full p-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500'}}) }} + {{ form_row(form.duree, {'label': 'Durée (en minutes)', 'attr': {'class': 'block w-full p-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500'}}) }} + {{ form_row(form.infosSortie, {'label': 'Description et infos', 'attr': {'class': 'block w-full p-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500'}}) }} +
+ + +
+ {{ form_row(form.ville, {'label': 'Ville organisatrice', 'attr': {'class': 'block w-full p-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500', 'id': 'ville-select'}}) }} +
+ {{ form_row(form.lieu, {'label': 'Lieu', 'attr': {'class': 'block w-full p-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500', 'id': 'lieu-select'}}) }} + +
+ + +
+ + Renseigner avec le lieu +
+
+ + Renseigner avec le lieu +
+
+ + Renseigner avec le lieu +
+
+ + Renseigner avec le lieu +
+
+
+ + +
+ + + Annuler + +
+ + {{ form_end(form) }} +
+
+ + + + + + + + +{% endblock %} diff --git a/templates/sortie/index.html.twig b/templates/sortie/index.html.twig new file mode 100644 index 0000000..8a0e315 --- /dev/null +++ b/templates/sortie/index.html.twig @@ -0,0 +1,14 @@ +{% extends 'main/base.html.twig' %} +{% block head %} + + + Sortie + {% block stylesheets %} + {{ encore_entry_link_tags('app') }} + {% endblock %} + +{% endblock %} + +{%block content %} +

Liste sortie

+{% endblock %} diff --git a/templates/ville/index.html.twig b/templates/ville/index.html.twig new file mode 100644 index 0000000..4f62baf --- /dev/null +++ b/templates/ville/index.html.twig @@ -0,0 +1,20 @@ + + +Hello VilleController! + +{% block body %} + + +
+

Hello {{ controller_name }}! ✅

+ + This friendly message is coming from: + +
+{% endblock %}