mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-01 12:33:49 +00:00
Merge branch 'master' into upgrade-sf5
This commit is contained in:
@@ -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,7 +31,7 @@ use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
/**
|
||||
* Class ParticipationController.
|
||||
*/
|
||||
class ParticipationController extends AbstractController
|
||||
final class ParticipationController extends AbstractController
|
||||
{
|
||||
/**
|
||||
* ParticipationController constructor.
|
||||
@@ -36,8 +39,11 @@ class ParticipationController extends AbstractController
|
||||
public function __construct(
|
||||
private readonly LoggerInterface $logger,
|
||||
private readonly TranslatorInterface $translator,
|
||||
private readonly EventRepository $eventRepository,
|
||||
private readonly PersonRepository $personRepository,
|
||||
private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry
|
||||
) {}
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @\Symfony\Component\Routing\Annotation\Route(path="/{_locale}/event/participation/create", name="chill_event_participation_create")
|
||||
@@ -232,6 +238,7 @@ class ParticipationController extends AbstractController
|
||||
return $this->render('@ChillEvent/Participation/new.html.twig', [
|
||||
'form' => $form->createView(),
|
||||
'participation' => $participation,
|
||||
'ignored_participations' => [],
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -541,7 +548,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
|
||||
@@ -550,7 +557,7 @@ class ParticipationController extends AbstractController
|
||||
Request $request,
|
||||
Participation $participation,
|
||||
bool $multiple = false
|
||||
): array|\Chill\EventBundle\Entity\Participation {
|
||||
): array|Participation {
|
||||
$em = $this->managerRegistry->getManager();
|
||||
|
||||
if ($em->contains($participation)) {
|
||||
@@ -558,30 +565,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 = [];
|
||||
|
||||
@@ -590,15 +592,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'
|
||||
);
|
||||
|
Reference in New Issue
Block a user