From 54ac8d052f3ca82280e0d699ef412bff295d3d61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Tue, 17 May 2016 20:41:03 +0200 Subject: [PATCH] fix bug on redirection when all required participation already exists When we request multiple participations on an event, and all people already participate on the event, the controller redirected to a route which provoked a bad request error. Now, we redirect to the view route. --- Controller/ParticipationController.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Controller/ParticipationController.php b/Controller/ParticipationController.php index ca2a5f953..1b23db177 100644 --- a/Controller/ParticipationController.php +++ b/Controller/ParticipationController.php @@ -156,18 +156,19 @@ class ParticipationController extends Controller { $participations = $this->handleRequest($request, new Participation()); + foreach ($participations as $i => $participation) { // check for authorization $this->denyAccessUnlessGranted(ParticipationVoter::CREATE, $participation, 'The user is not allowed to create this participation'); - // check that the user is not already in the event (computing only once) + // create a collection of person's id participating to the event /* @var $peopleParticipating \Doctrine\Common\Collections\ArrayCollection */ $peopleParticipating = isset($peopleParticipating) ? $peopleParticipating : $participation->getEvent()->getParticipations()->map( function(Participation $p) { return $p->getPerson()->getId(); } ); - + // check that the user is not already in the event if ($peopleParticipating->contains($participation->getPerson()->getId())) { $ignoredParticipations[] = $participation ->getEvent()->getParticipations()->filter( @@ -184,10 +185,11 @@ class ParticipationController extends Controller if (!isset($newParticipations)) { // if we do not have nay participants, redirect to event view - $this->addFlash('error', 'Any of the requested people may be added ' - . 'on the event: they are maybe already participating.'); + $this->addFlash('error', $this->get('translator')->trans( + 'None of the requested people may participate ' + . 'the event: they are maybe already participating.')); - return $this->redirectToRoute('chill_event_participation_new', array( + return $this->redirectToRoute('chill_event__event_show', array( 'event_id' => $request->query->getInt('event_id', 0) )); } elseif (count($newParticipations) > 1) {