forme création sortie
This commit is contained in:
55
migrations/Version20241119101414.php
Normal file
55
migrations/Version20241119101414.php
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace DoctrineMigrations;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Schema\Schema;
|
||||||
|
use Doctrine\Migrations\AbstractMigration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Auto-generated Migration: Please modify to your needs!
|
||||||
|
*/
|
||||||
|
final class Version20241119101414 extends AbstractMigration
|
||||||
|
{
|
||||||
|
public function getDescription(): string
|
||||||
|
{
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function up(Schema $schema): void
|
||||||
|
{
|
||||||
|
// this up() migration is auto-generated, please modify it to your needs
|
||||||
|
$this->addSql('CREATE TABLE etat (id_etat CHAR(36) NOT NULL COMMENT \'(DC2Type:guid)\', libelle VARCHAR(255) NOT NULL, PRIMARY KEY(id_etat)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
|
||||||
|
$this->addSql('CREATE TABLE lieu (id_lieu CHAR(36) NOT NULL COMMENT \'(DC2Type:guid)\', id_ville CHAR(36) NOT NULL COMMENT \'(DC2Type:guid)\', nom VARCHAR(255) NOT NULL, rue VARCHAR(255) DEFAULT NULL, latitude DOUBLE PRECISION DEFAULT NULL, longitude DOUBLE PRECISION DEFAULT NULL, INDEX IDX_2F577D59AD4698F3 (id_ville), PRIMARY KEY(id_lieu)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
|
||||||
|
$this->addSql('CREATE TABLE participant (id_participant CHAR(36) NOT NULL COMMENT \'(DC2Type:guid)\', id_site CHAR(36) NOT NULL COMMENT \'(DC2Type:guid)\', nom VARCHAR(255) NOT NULL, prenom VARCHAR(255) NOT NULL, telephone VARCHAR(255) DEFAULT NULL, email VARCHAR(255) NOT NULL, administrateur TINYINT(1) NOT NULL, actif TINYINT(1) NOT NULL, roles JSON NOT NULL, password VARCHAR(255) NOT NULL, INDEX IDX_D79F6B11E26315E6 (id_site), UNIQUE INDEX UNIQ_IDENTIFIER_EMAIL (email), PRIMARY KEY(id_participant)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
|
||||||
|
$this->addSql('CREATE TABLE site (id_site CHAR(36) NOT NULL COMMENT \'(DC2Type:guid)\', nom VARCHAR(255) NOT NULL, PRIMARY KEY(id_site)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
|
||||||
|
$this->addSql('CREATE TABLE sortie (id_sortie CHAR(36) NOT NULL COMMENT \'(DC2Type:guid)\', id_site CHAR(36) NOT NULL COMMENT \'(DC2Type:guid)\', id_participant CHAR(36) NOT NULL COMMENT \'(DC2Type:guid)\', id_lieu CHAR(36) NOT NULL COMMENT \'(DC2Type:guid)\', id_etat CHAR(36) NOT NULL COMMENT \'(DC2Type:guid)\', nom VARCHAR(255) NOT NULL, date_heure_debut DATE DEFAULT NULL, duree INT DEFAULT NULL, date_limite_inscription DATE DEFAULT NULL, nb_inscriptions_max INT DEFAULT NULL, infos_sortie VARCHAR(255) DEFAULT NULL, INDEX IDX_3C3FD3F2E26315E6 (id_site), INDEX IDX_3C3FD3F2CF8DA6E6 (id_participant), INDEX IDX_3C3FD3F2A477615B (id_lieu), INDEX IDX_3C3FD3F2DEEAEB60 (id_etat), PRIMARY KEY(id_sortie)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
|
||||||
|
$this->addSql('CREATE TABLE ville (id_ville CHAR(36) NOT NULL COMMENT \'(DC2Type:guid)\', nom VARCHAR(255) NOT NULL, code_postal INT DEFAULT NULL, PRIMARY KEY(id_ville)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
|
||||||
|
$this->addSql('CREATE TABLE messenger_messages (id BIGINT AUTO_INCREMENT NOT NULL, body LONGTEXT NOT NULL, headers LONGTEXT NOT NULL, queue_name VARCHAR(190) NOT NULL, created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', available_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', delivered_at DATETIME DEFAULT NULL COMMENT \'(DC2Type:datetime_immutable)\', INDEX IDX_75EA56E0FB7336F0 (queue_name), INDEX IDX_75EA56E0E3BD61CE (available_at), INDEX IDX_75EA56E016BA31DB (delivered_at), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
|
||||||
|
$this->addSql('ALTER TABLE lieu ADD CONSTRAINT FK_2F577D59AD4698F3 FOREIGN KEY (id_ville) REFERENCES ville (idVille)');
|
||||||
|
$this->addSql('ALTER TABLE participant ADD CONSTRAINT FK_D79F6B11E26315E6 FOREIGN KEY (id_site) REFERENCES site (idSite)');
|
||||||
|
$this->addSql('ALTER TABLE sortie ADD CONSTRAINT FK_3C3FD3F2E26315E6 FOREIGN KEY (id_site) REFERENCES site (idSite)');
|
||||||
|
$this->addSql('ALTER TABLE sortie ADD CONSTRAINT FK_3C3FD3F2CF8DA6E6 FOREIGN KEY (id_participant) REFERENCES participant (idParticipant)');
|
||||||
|
$this->addSql('ALTER TABLE sortie ADD CONSTRAINT FK_3C3FD3F2A477615B FOREIGN KEY (id_lieu) REFERENCES lieu (idLieu)');
|
||||||
|
$this->addSql('ALTER TABLE sortie ADD CONSTRAINT FK_3C3FD3F2DEEAEB60 FOREIGN KEY (id_etat) REFERENCES etat (idEtat)');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(Schema $schema): void
|
||||||
|
{
|
||||||
|
// this down() migration is auto-generated, please modify it to your needs
|
||||||
|
$this->addSql('ALTER TABLE lieu DROP FOREIGN KEY FK_2F577D59AD4698F3');
|
||||||
|
$this->addSql('ALTER TABLE participant DROP FOREIGN KEY FK_D79F6B11E26315E6');
|
||||||
|
$this->addSql('ALTER TABLE sortie DROP FOREIGN KEY FK_3C3FD3F2E26315E6');
|
||||||
|
$this->addSql('ALTER TABLE sortie DROP FOREIGN KEY FK_3C3FD3F2CF8DA6E6');
|
||||||
|
$this->addSql('ALTER TABLE sortie DROP FOREIGN KEY FK_3C3FD3F2A477615B');
|
||||||
|
$this->addSql('ALTER TABLE sortie DROP FOREIGN KEY FK_3C3FD3F2DEEAEB60');
|
||||||
|
$this->addSql('DROP TABLE etat');
|
||||||
|
$this->addSql('DROP TABLE lieu');
|
||||||
|
$this->addSql('DROP TABLE participant');
|
||||||
|
$this->addSql('DROP TABLE site');
|
||||||
|
$this->addSql('DROP TABLE sortie');
|
||||||
|
$this->addSql('DROP TABLE ville');
|
||||||
|
$this->addSql('DROP TABLE messenger_messages');
|
||||||
|
}
|
||||||
|
}
|
||||||
18
src/Controller/LieuController.php
Normal file
18
src/Controller/LieuController.php
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controller;
|
||||||
|
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\Routing\Attribute\Route;
|
||||||
|
|
||||||
|
class LieuController extends AbstractController
|
||||||
|
{
|
||||||
|
#[Route('/lieu', name: 'app_lieu')]
|
||||||
|
public function index(): Response
|
||||||
|
{
|
||||||
|
return $this->render('lieu/index.html.twig', [
|
||||||
|
'controller_name' => 'LieuController',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
42
src/Controller/SortieController.php
Normal file
42
src/Controller/SortieController.php
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controller;
|
||||||
|
|
||||||
|
use App\Entity\Sortie;
|
||||||
|
use App\Form\SortieType;
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\Routing\Annotation\Route;
|
||||||
|
|
||||||
|
#[Route('/sortie', name: 'sortie_')]
|
||||||
|
class SortieController extends AbstractController
|
||||||
|
{
|
||||||
|
#[Route('/creates', name: 'create', methods: ['GET', 'POST'])]
|
||||||
|
public function create(Request $request, EntityManagerInterface $entityManager): Response
|
||||||
|
{
|
||||||
|
$sortie = new Sortie();
|
||||||
|
|
||||||
|
// Créer le formulaire
|
||||||
|
$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
|
||||||
|
$entityManager->persist($sortie);
|
||||||
|
$entityManager->flush();
|
||||||
|
|
||||||
|
// Rediriger après soumission
|
||||||
|
$this->addFlash('success', 'Sortie créée avec succès !');
|
||||||
|
return $this->redirectToRoute('sortie_create');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Afficher le formulaire
|
||||||
|
return $this->render('sortie/create.html.twig', [
|
||||||
|
'form' => $form->createView(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
28
src/Controller/VilleController.php
Normal file
28
src/Controller/VilleController.php
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controller;
|
||||||
|
|
||||||
|
use App\Entity\Ville;
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
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 = [];
|
||||||
|
foreach ($lieux as $lieu) {
|
||||||
|
$data[] = [
|
||||||
|
'id' => $lieu->getIdLieu(),
|
||||||
|
'nom' => $lieu->getNom(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return new JsonResponse($data);
|
||||||
|
}
|
||||||
|
}
|
||||||
17
src/DataFixtures/AppFixtures.php
Normal file
17
src/DataFixtures/AppFixtures.php
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\DataFixtures;
|
||||||
|
|
||||||
|
use Doctrine\Bundle\FixturesBundle\Fixture;
|
||||||
|
use Doctrine\Persistence\ObjectManager;
|
||||||
|
|
||||||
|
class AppFixtures extends Fixture
|
||||||
|
{
|
||||||
|
public function load(ObjectManager $manager): void
|
||||||
|
{
|
||||||
|
// $product = new Product();
|
||||||
|
// $manager->persist($product);
|
||||||
|
|
||||||
|
$manager->flush();
|
||||||
|
}
|
||||||
|
}
|
||||||
31
src/DataFixtures/EtatFixtures.php
Normal file
31
src/DataFixtures/EtatFixtures.php
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\DataFixtures;
|
||||||
|
|
||||||
|
use App\Entity\Etat;
|
||||||
|
use Doctrine\Bundle\FixturesBundle\Fixture;
|
||||||
|
use Doctrine\Persistence\ObjectManager;
|
||||||
|
use Symfony\Component\Uid\Uuid;
|
||||||
|
|
||||||
|
class EtatFixtures extends Fixture
|
||||||
|
{
|
||||||
|
public function load(ObjectManager $manager): void
|
||||||
|
{
|
||||||
|
$etats = [
|
||||||
|
'Créée',
|
||||||
|
'Ouverte',
|
||||||
|
'Clôturée',
|
||||||
|
'En cours',
|
||||||
|
'Terminée',
|
||||||
|
'Annulée',
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($etats as $libelle) {
|
||||||
|
$etat = new Etat();
|
||||||
|
$etat->setLibelle($libelle);
|
||||||
|
$manager->persist($etat);
|
||||||
|
}
|
||||||
|
|
||||||
|
$manager->flush(); // Enregistrement en base de données
|
||||||
|
}
|
||||||
|
}
|
||||||
45
src/DataFixtures/LieuFixtures.php
Normal file
45
src/DataFixtures/LieuFixtures.php
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\DataFixtures;
|
||||||
|
|
||||||
|
use App\Entity\Lieu;
|
||||||
|
use Doctrine\Bundle\FixturesBundle\Fixture;
|
||||||
|
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
|
||||||
|
use Doctrine\Persistence\ObjectManager;
|
||||||
|
use Faker\Factory;
|
||||||
|
|
||||||
|
class LieuFixtures extends Fixture implements DependentFixtureInterface
|
||||||
|
{
|
||||||
|
public function load(ObjectManager $manager): void
|
||||||
|
{
|
||||||
|
$faker = Factory::create();
|
||||||
|
|
||||||
|
// Exemple : Références pour des villes déjà créées dans VilleFixtures
|
||||||
|
$villes = [
|
||||||
|
$this->getReference('ville_Paris'),
|
||||||
|
$this->getReference('ville_Lyon'),
|
||||||
|
$this->getReference('ville_Marseille'),
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($villes as $ville) {
|
||||||
|
for ($i = 0; $i < 5; $i++) { // Génère 5 lieux par ville
|
||||||
|
$lieu = new Lieu();
|
||||||
|
$lieu->setNom($faker->streetName());
|
||||||
|
$lieu->setRue($faker->streetAddress());
|
||||||
|
$lieu->setLatitude($faker->latitude());
|
||||||
|
$lieu->setLongitude($faker->longitude());
|
||||||
|
$lieu->setVille($ville); // Associe le lieu à une ville
|
||||||
|
$manager->persist($lieu);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$manager->flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDependencies(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
VilleFixtures::class, // Assure que VilleFixtures est chargée en premier
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
32
src/DataFixtures/VilleFixtures.php
Normal file
32
src/DataFixtures/VilleFixtures.php
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\DataFixtures;
|
||||||
|
|
||||||
|
use App\Entity\Ville;
|
||||||
|
use Doctrine\Bundle\FixturesBundle\Fixture;
|
||||||
|
use Doctrine\Persistence\ObjectManager;
|
||||||
|
|
||||||
|
class VilleFixtures extends Fixture
|
||||||
|
{
|
||||||
|
public function load(ObjectManager $manager): void
|
||||||
|
{
|
||||||
|
// Tableau associatif contenant les noms des villes et leurs codes postaux
|
||||||
|
$villes = [
|
||||||
|
['nom' => 'Paris', 'codePostal' => '75000'],
|
||||||
|
['nom' => 'Lyon', 'codePostal' => '69000'],
|
||||||
|
['nom' => 'Marseille', 'codePostal' => '13000'],
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($villes as $villeData) {
|
||||||
|
$ville = new Ville();
|
||||||
|
$ville->setNom($villeData['nom']);
|
||||||
|
$ville->setCodePostal($villeData['codePostal']); // Définit le code postal
|
||||||
|
$manager->persist($ville);
|
||||||
|
|
||||||
|
// Ajoute une référence pour les fixtures de lieux
|
||||||
|
$this->addReference('ville_' . $villeData['nom'], $ville);
|
||||||
|
}
|
||||||
|
|
||||||
|
$manager->flush();
|
||||||
|
}
|
||||||
|
}
|
||||||
76
src/Form/SortieType.php
Normal file
76
src/Form/SortieType.php
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Form;
|
||||||
|
|
||||||
|
use App\Entity\Etat;
|
||||||
|
use App\Entity\Lieu;
|
||||||
|
use App\Entity\Participant;
|
||||||
|
use App\Entity\Site;
|
||||||
|
use App\Entity\Sortie;
|
||||||
|
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||||
|
use Symfony\Component\Form\AbstractType;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\DateType;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||||
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||||
|
|
||||||
|
class SortieType extends AbstractType
|
||||||
|
{
|
||||||
|
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||||
|
{
|
||||||
|
$builder
|
||||||
|
->add('nom', TextType::class, [
|
||||||
|
'label' => 'Nom de la sortie',
|
||||||
|
])
|
||||||
|
->add('dateHeureDebut', DateTimeType::class, [
|
||||||
|
'label' => 'Date et heure de début',
|
||||||
|
'widget' => 'single_text', // Permet d'utiliser un champ HTML5
|
||||||
|
'html5' => true,
|
||||||
|
])
|
||||||
|
->add('duree', IntegerType::class, [
|
||||||
|
'label' => 'Durée (en minutes)',
|
||||||
|
])
|
||||||
|
->add('dateLimiteInscription', DateType::class, [
|
||||||
|
'label' => "Date limite d'inscription",
|
||||||
|
'widget' => 'single_text',
|
||||||
|
'html5' => true,
|
||||||
|
])
|
||||||
|
->add('nbInscriptionsMax', IntegerType::class, [
|
||||||
|
'label' => 'Nombre maximum de participants',
|
||||||
|
])
|
||||||
|
->add('infosSortie', TextareaType::class, [
|
||||||
|
'label' => 'Informations complémentaires',
|
||||||
|
'required' => false,
|
||||||
|
])
|
||||||
|
->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('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',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function configureOptions(OptionsResolver $resolver): void
|
||||||
|
{
|
||||||
|
$resolver->setDefaults([
|
||||||
|
'data_class' => Sortie::class,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user