forme création sortie
This commit is contained in:
@@ -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(),
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -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'],
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user