diff --git a/composer.lock b/composer.lock index ac18170522f4680053a175359d84ff262a211ba5..bc5f67b3df3a3db5aeae74b43c6b72cf763b4b57 100644 --- a/composer.lock +++ b/composer.lock @@ -5394,16 +5394,16 @@ }, { "name": "symfony/validator", - "version": "v5.3.10", + "version": "v5.3.12", "source": { "type": "git", "url": "https://github.com/symfony/validator.git", - "reference": "a85f3ba9e1c883253fc00a2e3d111e6e82a0baf5" + "reference": "379ca8939ebcab78d835e188673396a9f8d6eee8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/validator/zipball/a85f3ba9e1c883253fc00a2e3d111e6e82a0baf5", - "reference": "a85f3ba9e1c883253fc00a2e3d111e6e82a0baf5", + "url": "https://api.github.com/repos/symfony/validator/zipball/379ca8939ebcab78d835e188673396a9f8d6eee8", + "reference": "379ca8939ebcab78d835e188673396a9f8d6eee8", "shasum": "" }, "require": { @@ -5484,7 +5484,7 @@ "description": "Provides tools to validate values", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/validator/tree/v5.3.10" + "source": "https://github.com/symfony/validator/tree/v5.3.12" }, "funding": [ { @@ -5500,7 +5500,7 @@ "type": "tidelift" } ], - "time": "2021-10-28T19:22:18+00:00" + "time": "2021-11-22T22:24:25+00:00" }, { "name": "symfony/var-dumper", diff --git a/public/css/style.css b/public/css/style.css index ea8ef7757b549c5eca69e70676c8dd967b913166..07170cd2f7e1493cecb863da98a4b9dac049aedf 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -215,4 +215,7 @@ main { select { display: inline; +} +.error_msg { + color: #e53935; } \ No newline at end of file diff --git a/src/Controller/DefaultController.php b/src/Controller/DefaultController.php index 5597a691ad1e98f8494161c9393cfbfa3471cc4a..399ee173a60489de1d5b0efd8c18d0d6e7ae0cf9 100644 --- a/src/Controller/DefaultController.php +++ b/src/Controller/DefaultController.php @@ -6,6 +6,8 @@ use App\Entity\Evenement; use App\Entity\Participant; use App\Entity\Lieu; use App\Form\EvenementType; +use App\Form\AddParticipantType; +use App\Repository\ParticipantRepository; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -81,5 +83,46 @@ class DefaultController extends AbstractController ]); } + #[Route('/evenement/{id}/add?msg={msg}', name: 'event_add_participants', methods: ['GET', 'POST'])] + public function addParticipants(Evenement $event, Request $request, $msg = ''): Response + { + $participant = new Participant(); + $form = $this->createForm(AddParticipantType::class, $participant); + $form->handleRequest($request); + if ($form->isSubmitted() && $form->isValid()) { + $repo = $this->getDoctrine()->getRepository(Participant::class); + $existingParticipant = $repo->findOneBy([ + 'email' => $participant->getEmail(), + 'evenement' => $event, + ]); + + if (empty($existingParticipant)) { + $em = $this->getDoctrine()->getManager(); + $em->persist($participant); + $em->flush(); + return $this->redirectToRoute('events'); + } else { + return $this->redirectToRoute("event_add_participants", ["id" => $event->getId(), "msg" => "Ce participant participe déjà à l'évènement."]); + } + + } + return $this->render('default/addParticipants.html.twig', [ + 'form' => $form->createView(), + 'msg' => $msg + ]); + } + + #[Route('/participant/{id}/delete', name: 'delete_participant', methods: ['GET', 'POST'])] + public function deleteParticipant(Participant $participant, Request $request): Response + { + + $em = $this->getDoctrine()->getManager(); + $em->remove($participant); + $em->flush(); + return $this->redirectToRoute('events'); + + return $this->render('default/exo1.html.twig' ); + } + } diff --git a/src/Form/AddParticipantType.php b/src/Form/AddParticipantType.php new file mode 100644 index 0000000000000000000000000000000000000000..8be143126c15f4c89279fb9b2bb56fa88937be6e --- /dev/null +++ b/src/Form/AddParticipantType.php @@ -0,0 +1,33 @@ +add('nom') + ->add('prenom') + ->add('email') + ->add('evenement', EntityType::class, [ + 'class' => Evenement::class, + 'choice_label' => 'nom', + ]) + ; + } + + public function configureOptions(OptionsResolver $resolver): void + { + $resolver->setDefaults([ + 'data_class' => Participant::class, + ]); + } +} diff --git a/templates/default/addParticipants.html.twig b/templates/default/addParticipants.html.twig new file mode 100644 index 0000000000000000000000000000000000000000..51710602d6767b772baaa42247a041c7e07fd99f --- /dev/null +++ b/templates/default/addParticipants.html.twig @@ -0,0 +1,15 @@ +{% extends 'base.html.twig' %} + +{% block title %}Evenement{% endblock %} + +{% block body %} +
{{ msg }}
+ +{% endblock %} diff --git a/templates/default/exo1bis.html.twig b/templates/default/exo1bis.html.twig index b0fa3ea33d257efc2cfecdb9fd72a90c0bc87724..1caa392c8934cdac27ee01f88edb2ba0e99dcc27 100644 --- a/templates/default/exo1bis.html.twig +++ b/templates/default/exo1bis.html.twig @@ -24,7 +24,10 @@{{ p.nom }} Del
+ + {% endfor %} +