use a PickPersonDynamic type in event bundle

This commit is contained in:
2023-11-27 13:24:19 +01:00
parent f11f7498d7
commit 930a76cc66
5 changed files with 54 additions and 94 deletions

View File

@@ -14,7 +14,10 @@ namespace Chill\EventBundle\Controller;
use Chill\EventBundle\Entity\Event;
use Chill\EventBundle\Entity\Participation;
use Chill\EventBundle\Form\ParticipationType;
use Chill\EventBundle\Repository\EventRepository;
use Chill\EventBundle\Security\Authorization\ParticipationVoter;
use Chill\PersonBundle\Repository\PersonRepository;
use Chill\PersonBundle\Security\Authorization\PersonVoter;
use Doctrine\Common\Collections\Collection;
use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
@@ -28,14 +31,17 @@ use Symfony\Contracts\Translation\TranslatorInterface;
/**
* Class ParticipationController.
*/
class ParticipationController extends AbstractController
final class ParticipationController extends AbstractController
{
/**
* ParticipationController constructor.
*/
public function __construct(private readonly LoggerInterface $logger, private readonly TranslatorInterface $translator)
{
}
public function __construct(
private readonly LoggerInterface $logger,
private readonly TranslatorInterface $translator,
private readonly EventRepository $eventRepository,
private readonly PersonRepository $personRepository,
) {}
/**
* @\Symfony\Component\Routing\Annotation\Route(path="/{_locale}/event/participation/create", name="chill_event_participation_create")
@@ -321,7 +327,7 @@ class ParticipationController extends AbstractController
*/
public function editMultipleAction($event_id): Response|\Symfony\Component\HttpFoundation\RedirectResponse
{
$event = $this->getDoctrine()->getRepository(Event::class)
$event = $this->getDoctrine()->getRepository(\Chill\EventBundle\Entity\Event::class)
->find($event_id);
if (null === $event) {
@@ -539,7 +545,7 @@ class ParticipationController extends AbstractController
* If the request is multiple, the $participation object is cloned.
* Limitations: the $participation should not be persisted.
*
* @return Participation|Participation[] return one single participation if $multiple == false
* @return Participation|list<Participation> 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
@@ -556,30 +562,25 @@ class ParticipationController extends AbstractController
}
$event_id = $request->query->getInt('event_id', 0); // sf4 check:
// prevent error: `Argument 2 passed to ::getInt() must be of the type int, null given`
if (null !== $event_id) {
$event = $em->getRepository(Event::class)
->find($event_id);
$event = $this->eventRepository->find($event_id);
if (null === $event) {
throw $this->createNotFoundException('The event with id '.$event_id.' is not found');
}
$this->denyAccessUnlessGranted(
'CHILL_EVENT_SEE',
$event,
'The user is not allowed to see the event'
);
$participation->setEvent($event);
if (null === $event) {
throw $this->createNotFoundException('The event with id '.$event_id.' is not found');
}
$this->denyAccessUnlessGranted(
'CHILL_EVENT_SEE',
$event,
'The user is not allowed to see the event'
);
$participation->setEvent($event);
// this script should be able to handle multiple, so we translate
// single person_id in an array
$persons_ids = $request->query->has('person_id') ?
[$request->query->getInt('person_id', 0)] // sf4 check:
// prevent error: `Argument 2 passed to ::getInt() must be of the type int, null given`
[$request->query->get('person_id', 0)]
: explode(',', (string) $request->query->get('persons_ids'));
$participations = [];
@@ -588,15 +589,14 @@ class ParticipationController extends AbstractController
$participation = \count($persons_ids) > 1 ? clone $participation : $participation;
if (null !== $person_id) {
$person = $em->getRepository(\Chill\PersonBundle\Entity\Person::class)
->find($person_id);
$person = $this->personRepository->find($person_id);
if (null === $person) {
throw $this->createNotFoundException('The person with id '.$person_id.' is not found');
}
$this->denyAccessUnlessGranted(
'CHILL_PERSON_SEE',
PersonVoter::SEE,
$person,
'The user is not allowed to see the person'
);