From 93a5568aeec0263c8c1ff027f42a683726740296 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Thu, 7 Apr 2016 23:29:22 +0200 Subject: [PATCH] splitting function in order to prepare single/multiple adding association ref #6 --- Controller/ParticipationController.php | 27 ++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Controller/ParticipationController.php b/Controller/ParticipationController.php index 9024ea253..a04f05ed0 100644 --- a/Controller/ParticipationController.php +++ b/Controller/ParticipationController.php @@ -21,6 +21,7 @@ namespace Chill\EventBundle\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; use Chill\EventBundle\Entity\Participation; use Chill\EventBundle\Form\ParticipationType; use Symfony\Component\Form\Extension\Core\Type\SubmitType; @@ -33,7 +34,33 @@ use Chill\EventBundle\Security\Authorization\ParticipationVoter; */ class ParticipationController extends Controller { + /** + * Show a form to add a participation + * + * This function parse the person_id / persons_ids query argument + * and decide if it should process a single or multiple participation + * + * @param Request $request + */ public function newAction(Request $request) + { + $single = $request->query->getInt('person_id', null); + $multiple = $request->query->get('persons_ids', null); + + if ($single !== NULL AND $multiple !== NULL) { + // we are not allowed to have both person_id and persons_ids + return (new Response()) + ->setStatusCode(Response::HTTP_BAD_REQUEST) + ->setContent("You are not allow to provide both 'person_id' and " + . "'persons_ids' simulaneously"); + } + + if ($single !== NULL) { + return $this->newSingleAction($request); + } + } + + protected function newSingleAction(Request $request) { $participation = $this->handleRequest($request, new Participation());