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 @@ + + +
D:/workspace/sortir/src/Controller/LieuController.phpD:/workspace/sortir/templates/lieu/index.html.twigD:/workspace/sortir/src/Controller/VilleController.phpD:/workspace/sortir/templates/ville/index.html.twig