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.
This commit is contained in:
Julien Fastré 2016-05-17 20:41:03 +02:00
parent e723aeeeb4
commit 54ac8d052f

View File

@ -156,18 +156,19 @@ class ParticipationController extends Controller
{ {
$participations = $this->handleRequest($request, new Participation()); $participations = $this->handleRequest($request, new Participation());
foreach ($participations as $i => $participation) { foreach ($participations as $i => $participation) {
// check for authorization // check for authorization
$this->denyAccessUnlessGranted(ParticipationVoter::CREATE, $this->denyAccessUnlessGranted(ParticipationVoter::CREATE,
$participation, 'The user is not allowed to create this participation'); $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 */ /* @var $peopleParticipating \Doctrine\Common\Collections\ArrayCollection */
$peopleParticipating = isset($peopleParticipating) ? $peopleParticipating : $peopleParticipating = isset($peopleParticipating) ? $peopleParticipating :
$participation->getEvent()->getParticipations()->map( $participation->getEvent()->getParticipations()->map(
function(Participation $p) { return $p->getPerson()->getId(); } function(Participation $p) { return $p->getPerson()->getId(); }
); );
// check that the user is not already in the event
if ($peopleParticipating->contains($participation->getPerson()->getId())) { if ($peopleParticipating->contains($participation->getPerson()->getId())) {
$ignoredParticipations[] = $participation $ignoredParticipations[] = $participation
->getEvent()->getParticipations()->filter( ->getEvent()->getParticipations()->filter(
@ -184,10 +185,11 @@ class ParticipationController extends Controller
if (!isset($newParticipations)) { if (!isset($newParticipations)) {
// if we do not have nay participants, redirect to event view // if we do not have nay participants, redirect to event view
$this->addFlash('error', 'Any of the requested people may be added ' $this->addFlash('error', $this->get('translator')->trans(
. 'on the event: they are maybe already participating.'); '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) 'event_id' => $request->query->getInt('event_id', 0)
)); ));
} elseif (count($newParticipations) > 1) { } elseif (count($newParticipations) > 1) {