splitting function in order to prepare single/multiple adding association

ref #6
This commit is contained in:
Julien Fastré 2016-04-07 23:29:22 +02:00
parent 9cdbd8303a
commit 93a5568aee

View File

@ -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());