allow to add single participation with persons_ids

This commit is contained in:
Julien Fastré 2016-05-17 21:04:14 +02:00
parent 54ac8d052f
commit 5bcff0cba4
2 changed files with 13 additions and 9 deletions

View File

@ -102,7 +102,7 @@ class ParticipationController extends Controller
if ($multiple === true) { if ($multiple === true) {
$persons_ids = $request->query->get('persons_ids'); $persons_ids = $request->query->get('persons_ids');
if (!preg_match('/^([0-9]{1,},){1,}[0-9]{1,}$/', $persons_ids)) { if (!preg_match('/^([0-9]{1,},{0,1}){1,}[0-9]{0,}$/', $persons_ids)) {
throw new \RuntimeException("The persons_ids value should " throw new \RuntimeException("The persons_ids value should "
. "contains int separated by ','"); . "contains int separated by ','");
} }
@ -123,7 +123,7 @@ class ParticipationController extends Controller
*/ */
protected function newSingle(Request $request) protected function newSingle(Request $request)
{ {
$participation = $this->handleRequest($request, new Participation()); $participation = $this->handleRequest($request, new Participation(), false);
$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');
@ -154,7 +154,7 @@ class ParticipationController extends Controller
*/ */
protected function newMultiple(Request $request) protected function newMultiple(Request $request)
{ {
$participations = $this->handleRequest($request, new Participation()); $participations = $this->handleRequest($request, new Participation(), true);
foreach ($participations as $i => $participation) { foreach ($participations as $i => $participation) {
@ -249,7 +249,7 @@ class ParticipationController extends Controller
public function createSingle(Request $request) public function createSingle(Request $request)
{ {
$participation = $this->handleRequest($request, new Participation()); $participation = $this->handleRequest($request, new Participation(), false);
$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');
@ -280,7 +280,7 @@ class ParticipationController extends Controller
public function createMultiple(Request $request) public function createMultiple(Request $request)
{ {
$participations = $this->handleRequest($request, new Participation()); $participations = $this->handleRequest($request, new Participation(), true);
foreach($participations as $participation) { foreach($participations as $participation) {
$this->denyAccessUnlessGranted(ParticipationVoter::CREATE, $this->denyAccessUnlessGranted(ParticipationVoter::CREATE,
@ -324,11 +324,15 @@ class ParticipationController extends Controller
* *
* @param Request $request * @param Request $request
* @param Participation $participation * @param Participation $participation
* @return Participation * @param boolean $multiple (default false)
* @return Participation|Participations[] return one single participation if $multiple == false
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException if the event/person is not found * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException if the event/person is not found
* @throws \Symfony\Component\Security\Core\Exception\AccessDeniedException if the user does not have access to event/person * @throws \Symfony\Component\Security\Core\Exception\AccessDeniedException if the user does not have access to event/person
*/ */
protected function handleRequest(Request $request, Participation $participation) protected function handleRequest(
Request $request,
Participation $participation,
$multiple = false)
{ {
$em = $this->getDoctrine()->getManager(); $em = $this->getDoctrine()->getManager();
if ($em->contains($participation)) { if ($em->contains($participation)) {
@ -382,7 +386,7 @@ class ParticipationController extends Controller
$participations[] = $participation; $participations[] = $participation;
} }
return count($participations) > 1 ? $participations : $participations[0]; return $multiple ? $participations : $participations[0];
} }
/** /**

View File

@ -33,7 +33,7 @@ Back to the event: Retour à l'événement
The participation was created: La participation a été créée The participation was created: La participation a été créée
The participation was updated: La participation a été mise à jour The participation was updated: La participation a été mise à jour
Participation Edit: Modifier une participation Participation Edit: Modifier une participation
'Any of the requested people may be added on the event: they are maybe already participating.': 'Aucune des personnes suggérées ne peut être ajoutée à l''événement: elles sont peut-être déjà inscrites comme participantes.' 'None of the requested people may participate the event: they are maybe already participating.': 'Aucune des personnes indiquées ne peut être ajoutée à l''événement: elles sont peut-être déjà inscrites comme participantes.'
'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' '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 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 participations have been successfully updated.: Les participations ont été mises à jour.