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'],
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
20
templates/lieu/index.html.twig
Normal file
20
templates/lieu/index.html.twig
Normal file
@@ -0,0 +1,20 @@
|
||||
<!DOCTYPE html>
|
||||
|
||||
<title>Hello LieuController!</title>
|
||||
|
||||
{% block body %}
|
||||
<style>
|
||||
.example-wrapper { margin: 1em auto; max-width: 800px; width: 95%; font: 18px/1.5 sans-serif; }
|
||||
.example-wrapper code { background: #F5F5F5; padding: 2px 6px; }
|
||||
</style>
|
||||
|
||||
<div class="example-wrapper">
|
||||
<h1>Hello {{ controller_name }}! ✅</h1>
|
||||
|
||||
This friendly message is coming from:
|
||||
<ul>
|
||||
<li>Your controller at <code>D:/workspace/sortir/src/Controller/LieuController.php</code></li>
|
||||
<li>Your template at <code>D:/workspace/sortir/templates/lieu/index.html.twig</code></li>
|
||||
</ul>
|
||||
</div>
|
||||
{% endblock %}
|
||||
169
templates/sortie/create.html.twig
Normal file
169
templates/sortie/create.html.twig
Normal file
@@ -0,0 +1,169 @@
|
||||
{% extends 'main/base.html.twig' %}
|
||||
|
||||
{% block head %}
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Créer une sortie</title>
|
||||
{% block stylesheets %}
|
||||
{{ encore_entry_link_tags('app') }}
|
||||
<link rel="stylesheet" href="https://unpkg.com/leaflet/dist/leaflet.css" />
|
||||
<link rel="stylesheet" href="https://unpkg.com/leaflet-geosearch/dist/geosearch.css" />
|
||||
{% endblock %}
|
||||
</head>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="min-h-screen flex items-center justify-center bg-gray-100">
|
||||
<!-- Carte blanche centrée -->
|
||||
<div class="w-full max-w-3xl bg-white p-8 rounded-lg shadow-lg">
|
||||
<h1 class="text-2xl font-bold text-gray-800 mb-6 text-center">Créer une sortie</h1>
|
||||
|
||||
<!-- Début du formulaire -->
|
||||
{{ form_start(form, { 'attr': { 'class': 'space-y-6' } }) }}
|
||||
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
|
||||
<!-- Partie gauche du formulaire -->
|
||||
<div class="space-y-4">
|
||||
{{ 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'}}) }}
|
||||
</div>
|
||||
|
||||
<!-- Partie droite du formulaire -->
|
||||
<div class="space-y-4">
|
||||
{{ 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'}}) }}
|
||||
<div class="flex items-center space-x-2">
|
||||
{{ 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'}}) }}
|
||||
<button type="button" id="add-lieu-button" class="p-3 bg-blue-500 text-white rounded-lg hover:bg-blue-600 focus:outline-none focus:ring-2 focus:ring-blue-300">+</button>
|
||||
</div>
|
||||
|
||||
<!-- Champs dépendants -->
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700">Rue :</label>
|
||||
<span id="rue-value" class="block w-full p-3 border border-gray-300 rounded-lg bg-gray-100">Renseigner avec le lieu</span>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700">Code postal :</label>
|
||||
<span id="codePostal-value" class="block w-full p-3 border border-gray-300 rounded-lg bg-gray-100">Renseigner avec le lieu</span>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700">Latitude :</label>
|
||||
<span id="latitude-value" class="block w-full p-3 border border-gray-300 rounded-lg bg-gray-100">Renseigner avec le lieu</span>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700">Longitude :</label>
|
||||
<span id="longitude-value" class="block w-full p-3 border border-gray-300 rounded-lg bg-gray-100">Renseigner avec le lieu</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Boutons -->
|
||||
<div class="mt-6 flex justify-center space-x-4">
|
||||
<button type="submit" name="action" value="save" class="px-6 py-3 bg-green-500 text-white rounded-lg shadow hover:bg-green-600 focus:outline-none focus:ring-2 focus:ring-green-300">
|
||||
Enregistrer
|
||||
</button>
|
||||
<a href="{{ path('home') }}" class="px-6 py-3 bg-gray-500 text-white rounded-lg shadow hover:bg-gray-600 focus:outline-none focus:ring-2 focus:ring-gray-300">
|
||||
Annuler
|
||||
</a>
|
||||
</div>
|
||||
|
||||
{{ form_end(form) }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Modal pour ajouter un lieu avec une carte -->
|
||||
<div id="add-lieu-modal" class="fixed inset-0 flex items-center justify-center bg-gray-800 bg-opacity-50 hidden">
|
||||
<div class="bg-white p-6 rounded-lg shadow-lg w-full max-w-3xl">
|
||||
<h2 class="text-xl font-bold mb-4">Ajouter un lieu</h2>
|
||||
<div id="map" class="w-full h-64 mb-4"></div>
|
||||
<div class="flex justify-end space-x-4">
|
||||
<button type="button" id="cancel-add-lieu" class="px-4 py-2 bg-gray-500 text-white rounded-lg hover:bg-gray-600 focus:outline-none focus:ring-2 focus:ring-gray-300">Annuler</button>
|
||||
<button type="button" id="select-location" class="px-4 py-2 bg-blue-500 text-white rounded-lg hover:bg-blue-600 focus:outline-none focus:ring-2 focus:ring-blue-300">Sélectionner</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="https://unpkg.com/leaflet/dist/leaflet.js"></script>
|
||||
<script src="https://unpkg.com/leaflet-geosearch/dist/geosearch.umd.js"></script>
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
const addLieuButton = document.getElementById('add-lieu-button');
|
||||
const addLieuModal = document.getElementById('add-lieu-modal');
|
||||
const cancelAddLieuButton = document.getElementById('cancel-add-lieu');
|
||||
const selectLocationButton = document.getElementById('select-location');
|
||||
const lieuSelect = document.getElementById('lieu-select');
|
||||
|
||||
const rueField = document.getElementById('rue-value');
|
||||
const codePostalField = document.getElementById('codePostal-value');
|
||||
const latitudeField = document.getElementById('latitude-value');
|
||||
const longitudeField = document.getElementById('longitude-value');
|
||||
|
||||
let map, marker;
|
||||
|
||||
// Initialize the map
|
||||
addLieuButton.addEventListener('click', function () {
|
||||
addLieuModal.classList.remove('hidden');
|
||||
|
||||
if (!map) {
|
||||
map = L.map('map').setView([48.8566, 2.3522], 13); // Default view on Paris
|
||||
|
||||
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
||||
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
|
||||
}).addTo(map);
|
||||
|
||||
const provider = new window.GeoSearch.OpenStreetMapProvider();
|
||||
const searchControl = new window.GeoSearch.GeoSearchControl({
|
||||
provider: provider,
|
||||
style: 'bar',
|
||||
autoComplete: true,
|
||||
autoCompleteDelay: 250,
|
||||
});
|
||||
|
||||
map.addControl(searchControl);
|
||||
|
||||
map.on('geosearch/showlocation', function (e) {
|
||||
const latlng = e.location;
|
||||
map.setView(latlng, 13);
|
||||
if (marker) {
|
||||
marker.setLatLng(latlng);
|
||||
} else {
|
||||
marker = L.marker(latlng).addTo(map);
|
||||
}
|
||||
document.getElementById('latitude-value').textContent = latlng.y;
|
||||
document.getElementById('longitude-value').textContent = latlng.x;
|
||||
});
|
||||
|
||||
map.on('click', function (e) {
|
||||
const { lat, lng } = e.latlng;
|
||||
|
||||
if (marker) {
|
||||
marker.setLatLng([lat, lng]);
|
||||
} else {
|
||||
marker = L.marker([lat, lng]).addTo(map);
|
||||
}
|
||||
|
||||
document.getElementById('latitude-value').textContent = lat;
|
||||
document.getElementById('longitude-value').textContent = lng;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
cancelAddLieuButton.addEventListener('click', function () {
|
||||
addLieuModal.classList.add('hidden');
|
||||
});
|
||||
|
||||
selectLocationButton.addEventListener('click', function () {
|
||||
if (marker) {
|
||||
const { lat, lng } = marker.getLatLng();
|
||||
latitudeField.textContent = lat;
|
||||
longitudeField.textContent = lng;
|
||||
addLieuModal.classList.add('hidden');
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
{% endblock %}
|
||||
14
templates/sortie/index.html.twig
Normal file
14
templates/sortie/index.html.twig
Normal file
@@ -0,0 +1,14 @@
|
||||
{% extends 'main/base.html.twig' %}
|
||||
{% block head %}
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Sortie</title>
|
||||
{% block stylesheets %}
|
||||
{{ encore_entry_link_tags('app') }}
|
||||
{% endblock %}
|
||||
</head>
|
||||
{% endblock %}
|
||||
|
||||
{%block content %}
|
||||
<h1>Liste sortie</h1>
|
||||
{% endblock %}
|
||||
20
templates/ville/index.html.twig
Normal file
20
templates/ville/index.html.twig
Normal file
@@ -0,0 +1,20 @@
|
||||
<!DOCTYPE html>
|
||||
|
||||
<title>Hello VilleController!</title>
|
||||
|
||||
{% block body %}
|
||||
<style>
|
||||
.example-wrapper { margin: 1em auto; max-width: 800px; width: 95%; font: 18px/1.5 sans-serif; }
|
||||
.example-wrapper code { background: #F5F5F5; padding: 2px 6px; }
|
||||
</style>
|
||||
|
||||
<div class="example-wrapper">
|
||||
<h1>Hello {{ controller_name }}! ✅</h1>
|
||||
|
||||
This friendly message is coming from:
|
||||
<ul>
|
||||
<li>Your controller at <code>D:/workspace/sortir/src/Controller/VilleController.php</code></li>
|
||||
<li>Your template at <code>D:/workspace/sortir/templates/ville/index.html.twig</code></li>
|
||||
</ul>
|
||||
</div>
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user