From 8618efc35a9a3af7857a93b5291ddfd3be163489 Mon Sep 17 00:00:00 2001 From: Tchama Date: Thu, 28 Nov 2019 16:38:03 +0100 Subject: [PATCH] adding remove participation method --- Controller/ParticipationController.php | 70 ++++++++++++++++++- Resources/config/routing/participation.yml | 8 +++ Resources/translations/messages.fr.yml | 4 ++ .../views/Event/confirm_delete.html.twig | 20 ++++++ Resources/views/Event/show.html.twig | 4 ++ 5 files changed, 103 insertions(+), 3 deletions(-) create mode 100644 Resources/views/Event/confirm_delete.html.twig diff --git a/Controller/ParticipationController.php b/Controller/ParticipationController.php index 10c7d6f6f..dd99e6fed 100644 --- a/Controller/ParticipationController.php +++ b/Controller/ParticipationController.php @@ -19,6 +19,8 @@ namespace Chill\EventBundle\Controller; +use Chill\EventBundle\Entity\Event; +use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -551,8 +553,9 @@ class ParticipationController extends Controller /** * show a form to edit multiple participation for the same event. - * + * * @param int $event_id + * @return \Symfony\Component\HttpFoundation\RedirectResponse|Response */ public function editMultipleAction($event_id) { @@ -637,8 +640,8 @@ class ParticipationController extends Controller } /** - * - * @param \Doctrine\Common\Collections\Collectionn $participations contains object of Participation type + * + * @param \Doctrine\Common\Collections\Collection $participations contains object of Participation type * @param \Chill\EventBundle\Entity\Event $event * @return \Symfony\Component\Form\FormInterface */ @@ -669,4 +672,65 @@ class ParticipationController extends Controller return $form; } + /** + * @param integer $participation_id + * @param Request $request + * @return \Symfony\Component\HttpFoundation\RedirectResponse|Response + */ + public function deleteAction($participation_id, Request $request) + { + $em = $this->getDoctrine()->getManager(); + $participation = $em->getRepository('ChillEventBundle:Participation')->findOneBy([ + 'id' => $participation_id + ]); + + if (! $participation) { + throw $this->createNotFoundException('Unable to find participation.'); + } + + /** @var Event $event */ + $event = $participation->getEvent(); + + $form = $this->createDeleteForm($participation_id); + + if ($request->getMethod() === Request::METHOD_DELETE) { + $form->handleRequest($request); + + if ($form->isValid()) { + + $em->remove($participation); + $em->flush(); + + $this->addFlash('success', $this->get('translator') + ->trans("The participation has been sucessfully removed") + ); + + return $this->redirectToRoute('chill_event__event_show', [ + 'event_id' => $event->getId() + ]); + } + } + return $this->render('ChillEventBundle:Event:confirm_delete.html.twig', [ + 'event_id' => $event->getId(), + 'delete_form' => $form->createView() + ]); + + } + + /** + * @param $participation_id + * @return \Symfony\Component\Form\FormInterface + */ + private function createDeleteForm($participation_id) + { + return $this->createFormBuilder() + ->setAction($this->generateUrl('chill_event_participation_delete', [ + 'participation_id' => $participation_id + ])) + ->setMethod('DELETE') + ->add('submit', SubmitType::class, ['label' => 'Delete']) + ->getForm() + ; + } + } diff --git a/Resources/config/routing/participation.yml b/Resources/config/routing/participation.yml index bbb727382..7d4efc90a 100644 --- a/Resources/config/routing/participation.yml +++ b/Resources/config/routing/participation.yml @@ -23,3 +23,11 @@ chill_event_participation_update_multiple: path: /{event_id}/update_multiple defaults: { _controller: ChillEventBundle:Participation:updateMultiple } methods: [POST] + +chill_event_participation_delete: + path: /{participation_id}/delete + requirements: + participation_id: \d+ + defaults: { _controller: ChillEventBundle:Participation:delete } + methods: [ GET, DELETE ] + diff --git a/Resources/translations/messages.fr.yml b/Resources/translations/messages.fr.yml index b02bf7627..b2ab63f01 100644 --- a/Resources/translations/messages.fr.yml +++ b/Resources/translations/messages.fr.yml @@ -43,9 +43,13 @@ The participation was updated: La participation a été mise à jour 'The following people have been ignored because they are already participating on the event': '{1} La personne suivante a été ignorée parce qu''elle participe déjà à l''événement | ]1,Inf] Les personnes suivantes ont été ignorées parce qu''elles participent déjà à l''événement' There are no participation to edit for this event: Il n'y a pas de participation pour cet événement The participations have been successfully updated.: Les participations ont été mises à jour. +The participation has been sucessfully removed: La participation a été correctement supprimée. The participations were created: Les participations ont été créées Events participation: Participation aux événements +Remove participation: Supprimer la participation +Are you sure you want to remove that participation ?: Êtes-vous certain de vouloir supprimer cette participation ? + #search Event search: Recherche d'événements '%total% events match the search %pattern%' : '{0} Aucun événement ne correspond aux termes de recherche "%pattern%" | {1} Un événement a été trouvé par la recherche "%pattern%" | ]1,Inf] %total% événements correspondent aux termes de recherche "%pattern%".' diff --git a/Resources/views/Event/confirm_delete.html.twig b/Resources/views/Event/confirm_delete.html.twig new file mode 100644 index 000000000..f235ebb00 --- /dev/null +++ b/Resources/views/Event/confirm_delete.html.twig @@ -0,0 +1,20 @@ +{% extends 'ChillEventBundle::layout.html.twig' %} + +{% set activeRouteKey = 'chill_event__event_show' %} + +{% block title 'Remove participation'|trans %} + +{% block event_content %} + + {{ include('ChillMainBundle:Util:confirmation_template.html.twig', + { + 'title' : 'Remove participation'|trans, + 'confirm_question' : 'Are you sure you want to remove that participation ?'|trans, + 'cancel_route' : activeRouteKey, + 'cancel_parameters' : { 'event_id' : event_id }, + 'form' : delete_form + } + ) }} + +{% endblock %} + diff --git a/Resources/views/Event/show.html.twig b/Resources/views/Event/show.html.twig index e79137f03..e818cab46 100644 --- a/Resources/views/Event/show.html.twig +++ b/Resources/views/Event/show.html.twig @@ -91,6 +91,10 @@ {{ 'Edit'|trans }} +
  • + +
  • {% endif %}