mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-28 02:23:51 +00:00
allow to add single participation with persons_ids
This commit is contained in:
@@ -102,7 +102,7 @@ class ParticipationController extends Controller
|
||||
if ($multiple === true) {
|
||||
$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 "
|
||||
. "contains int separated by ','");
|
||||
}
|
||||
@@ -123,7 +123,7 @@ class ParticipationController extends Controller
|
||||
*/
|
||||
protected function newSingle(Request $request)
|
||||
{
|
||||
$participation = $this->handleRequest($request, new Participation());
|
||||
$participation = $this->handleRequest($request, new Participation(), false);
|
||||
|
||||
$this->denyAccessUnlessGranted(ParticipationVoter::CREATE,
|
||||
$participation, 'The user is not allowed to create this participation');
|
||||
@@ -154,7 +154,7 @@ class ParticipationController extends Controller
|
||||
*/
|
||||
protected function newMultiple(Request $request)
|
||||
{
|
||||
$participations = $this->handleRequest($request, new Participation());
|
||||
$participations = $this->handleRequest($request, new Participation(), true);
|
||||
|
||||
|
||||
foreach ($participations as $i => $participation) {
|
||||
@@ -249,7 +249,7 @@ class ParticipationController extends Controller
|
||||
|
||||
public function createSingle(Request $request)
|
||||
{
|
||||
$participation = $this->handleRequest($request, new Participation());
|
||||
$participation = $this->handleRequest($request, new Participation(), false);
|
||||
|
||||
$this->denyAccessUnlessGranted(ParticipationVoter::CREATE,
|
||||
$participation, 'The user is not allowed to create this participation');
|
||||
@@ -280,7 +280,7 @@ class ParticipationController extends Controller
|
||||
|
||||
public function createMultiple(Request $request)
|
||||
{
|
||||
$participations = $this->handleRequest($request, new Participation());
|
||||
$participations = $this->handleRequest($request, new Participation(), true);
|
||||
|
||||
foreach($participations as $participation) {
|
||||
$this->denyAccessUnlessGranted(ParticipationVoter::CREATE,
|
||||
@@ -324,11 +324,15 @@ class ParticipationController extends Controller
|
||||
*
|
||||
* @param Request $request
|
||||
* @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\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();
|
||||
if ($em->contains($participation)) {
|
||||
@@ -382,7 +386,7 @@ class ParticipationController extends Controller
|
||||
$participations[] = $participation;
|
||||
}
|
||||
|
||||
return count($participations) > 1 ? $participations : $participations[0];
|
||||
return $multiple ? $participations : $participations[0];
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user