mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-05 14:25:00 +00:00
Merge branch 'master' into upgrade-sf5
This commit is contained in:
@@ -17,10 +17,11 @@ use Chill\EventBundle\Form\EventType;
|
||||
use Chill\EventBundle\Form\Type\PickEventType;
|
||||
use Chill\EventBundle\Security\Authorization\EventVoter;
|
||||
use Chill\MainBundle\Entity\Center;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\MainBundle\Pagination\PaginatorFactory;
|
||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelperInterface;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Form\Type\PickPersonType;
|
||||
use Chill\PersonBundle\Form\Type\PickPersonDynamicType;
|
||||
use Chill\PersonBundle\Privacy\PrivacyEvent;
|
||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||
use PhpOffice\PhpSpreadsheet\Writer\Csv;
|
||||
@@ -37,38 +38,15 @@ use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||
use Symfony\Component\Form\FormFactoryInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
/**
|
||||
* Class EventController.
|
||||
*/
|
||||
class EventController extends AbstractController
|
||||
final class EventController extends AbstractController
|
||||
{
|
||||
/**
|
||||
* @var AuthorizationHelper
|
||||
*/
|
||||
protected $authorizationHelper;
|
||||
|
||||
/**
|
||||
* @var EventDispatcherInterface
|
||||
*/
|
||||
protected $eventDispatcher;
|
||||
|
||||
/**
|
||||
* @var FormFactoryInterface
|
||||
*/
|
||||
protected $formFactoryInterface;
|
||||
|
||||
/**
|
||||
* @var PaginatorFactory
|
||||
*/
|
||||
protected $paginator;
|
||||
|
||||
/**
|
||||
* @var TranslatorInterface
|
||||
*/
|
||||
protected $translator;
|
||||
|
||||
/**
|
||||
* EventController constructor.
|
||||
*/
|
||||
@@ -80,11 +58,6 @@ class EventController extends AbstractController
|
||||
PaginatorFactory $paginator,
|
||||
private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry
|
||||
) {
|
||||
$this->eventDispatcher = $eventDispatcher;
|
||||
$this->authorizationHelper = $authorizationHelper;
|
||||
$this->formFactoryInterface = $formFactoryInterface;
|
||||
$this->translator = $translator;
|
||||
$this->paginator = $paginator;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -182,7 +155,7 @@ class EventController extends AbstractController
|
||||
|
||||
$this->denyAccessUnlessGranted('CHILL_PERSON_SEE', $person);
|
||||
|
||||
$reachablesCircles = $this->authorizationHelper->getReachableCircles(
|
||||
$reachablesCircles = $this->authorizationHelper->getReachableScopes(
|
||||
$this->getUser(),
|
||||
EventVoter::SEE,
|
||||
$person->getCenter()
|
||||
@@ -234,6 +207,12 @@ class EventController extends AbstractController
|
||||
*/
|
||||
public function newAction(?Center $center, Request $request)
|
||||
{
|
||||
$user = $this->security->getUser();
|
||||
|
||||
if (!$user instanceof User) {
|
||||
throw new AccessDeniedHttpException('not a regular user. Maybe an administrator ?');
|
||||
}
|
||||
|
||||
if (null === $center) {
|
||||
$center_id = $request->query->get('center_id');
|
||||
$center = $this->managerRegistry->getRepository(Center::class)->find($center_id);
|
||||
@@ -241,6 +220,7 @@ class EventController extends AbstractController
|
||||
|
||||
$entity = new Event();
|
||||
$entity->setCenter($center);
|
||||
$entity->setLocation($user->getCurrentLocation());
|
||||
|
||||
$form = $this->createCreateForm($entity);
|
||||
$form->handleRequest($request);
|
||||
@@ -283,7 +263,7 @@ class EventController extends AbstractController
|
||||
}
|
||||
|
||||
$form = $this->formFactoryInterface
|
||||
->createNamedBuilder(null, FormType::class, null, [
|
||||
->createNamedBuilder('', FormType::class, null, [
|
||||
'csrf_protection' => false,
|
||||
])
|
||||
->setMethod('GET')
|
||||
@@ -324,7 +304,7 @@ class EventController extends AbstractController
|
||||
}
|
||||
|
||||
$this->denyAccessUnlessGranted(
|
||||
'CHILL_EVENT_SEE_DETAILS',
|
||||
EventVoter::SEE_DETAILS,
|
||||
$event,
|
||||
'You are not allowed to see details on this event'
|
||||
);
|
||||
@@ -368,7 +348,7 @@ class EventController extends AbstractController
|
||||
$this->addFlash('success', $this->translator
|
||||
->trans('The event was updated'));
|
||||
|
||||
return $this->redirectToRoute('chill_event__event_edit', ['event_id' => $event_id]);
|
||||
return $this->redirectToRoute('chill_event__event_show', ['event_id' => $event_id]);
|
||||
}
|
||||
|
||||
return $this->render('@ChillEvent/Event/edit.html.twig', [
|
||||
@@ -386,7 +366,7 @@ class EventController extends AbstractController
|
||||
{
|
||||
/** @var \Symfony\Component\Form\FormBuilderInterface $builder */
|
||||
$builder = $this
|
||||
->get('form.factory')
|
||||
->formFactoryInterface
|
||||
->createNamedBuilder(
|
||||
null,
|
||||
FormType::class,
|
||||
@@ -431,11 +411,9 @@ class EventController extends AbstractController
|
||||
*/
|
||||
protected function createAddParticipationByPersonForm(Event $event)
|
||||
{
|
||||
/** @var \Symfony\Component\Form\FormBuilderInterface $builder */
|
||||
$builder = $this
|
||||
->get('form.factory')
|
||||
$builder = $this->formFactoryInterface
|
||||
->createNamedBuilder(
|
||||
null,
|
||||
'',
|
||||
FormType::class,
|
||||
null,
|
||||
[
|
||||
@@ -445,23 +423,17 @@ class EventController extends AbstractController
|
||||
]
|
||||
);
|
||||
|
||||
$builder->add('person_id', PickPersonType::class, [
|
||||
'role' => 'CHILL_EVENT_CREATE',
|
||||
'centers' => $event->getCenter(),
|
||||
$builder->add('person_id', PickPersonDynamicType::class, [
|
||||
'as_id' => true,
|
||||
'multiple' => false,
|
||||
'submit_on_adding_new_entity' => true,
|
||||
'label' => 'Add a participation',
|
||||
]);
|
||||
|
||||
$builder->add('event_id', HiddenType::class, [
|
||||
'data' => $event->getId(),
|
||||
]);
|
||||
|
||||
$builder->add(
|
||||
'submit',
|
||||
SubmitType::class,
|
||||
[
|
||||
'label' => 'Add a participation',
|
||||
]
|
||||
);
|
||||
|
||||
return $builder->getForm();
|
||||
}
|
||||
|
||||
@@ -470,7 +442,7 @@ class EventController extends AbstractController
|
||||
*/
|
||||
protected function createExportByFormatForm()
|
||||
{
|
||||
$builder = $this->createFormBuilder()
|
||||
$builder = $this->createFormBuilder(['format' => 'xlsx'])
|
||||
->add('format', ChoiceType::class, [
|
||||
'choices' => [
|
||||
'xlsx' => 'xlsx',
|
||||
|
118
src/Bundle/ChillEventBundle/Controller/EventListController.php
Normal file
118
src/Bundle/ChillEventBundle/Controller/EventListController.php
Normal file
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\EventBundle\Controller;
|
||||
|
||||
use Chill\EventBundle\Entity\Event;
|
||||
use Chill\EventBundle\Entity\EventType;
|
||||
use Chill\EventBundle\Repository\EventACLAwareRepositoryInterface;
|
||||
use Chill\EventBundle\Repository\EventTypeRepository;
|
||||
use Chill\MainBundle\Pagination\PaginatorFactoryInterface;
|
||||
use Chill\MainBundle\Templating\Listing\FilterOrderHelper;
|
||||
use Chill\MainBundle\Templating\Listing\FilterOrderHelperFactory;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
|
||||
use Chill\PersonBundle\Form\Type\PickPersonDynamicType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\FormType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
|
||||
use Symfony\Component\Form\FormFactoryInterface;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||
use Twig\Environment;
|
||||
|
||||
final readonly class EventListController
|
||||
{
|
||||
public function __construct(
|
||||
private Environment $environment,
|
||||
private EventACLAwareRepositoryInterface $eventACLAwareRepository,
|
||||
private EventTypeRepository $eventTypeRepository,
|
||||
private FilterOrderHelperFactory $filterOrderHelperFactory,
|
||||
private FormFactoryInterface $formFactory,
|
||||
private PaginatorFactoryInterface $paginatorFactory,
|
||||
private TranslatableStringHelperInterface $translatableStringHelper,
|
||||
private UrlGeneratorInterface $urlGenerator,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("{_locale}/event/event/list", name="chill_event_event_list")
|
||||
*/
|
||||
public function __invoke(): Response
|
||||
{
|
||||
$filter = $this->buildFilterOrder();
|
||||
$filterData = [
|
||||
'q' => (string) $filter->getQueryString(),
|
||||
'dates' => $filter->getDateRangeData('dates'),
|
||||
'event_types' => $filter->getEntityChoiceData('event_types'),
|
||||
];
|
||||
$total = $this->eventACLAwareRepository->countAllViewable($filterData);
|
||||
$pagination = $this->paginatorFactory->create($total);
|
||||
$events = $this->eventACLAwareRepository->findAllViewable($filterData, $pagination->getCurrentPageFirstItemNumber(), $pagination->getItemsPerPage());
|
||||
$eventForms = [];
|
||||
foreach ($events as $event) {
|
||||
$eventForms[$event->getId()] = $this->createAddParticipationByPersonForm($event)->createView();
|
||||
}
|
||||
|
||||
return new Response($this->environment->render(
|
||||
'@ChillEvent/Event/page_list.html.twig',
|
||||
[
|
||||
'events' => $events,
|
||||
'pagination' => $pagination,
|
||||
'eventForms' => $eventForms,
|
||||
'filter' => $filter,
|
||||
]
|
||||
));
|
||||
}
|
||||
|
||||
private function buildFilterOrder(): FilterOrderHelper
|
||||
{
|
||||
$types = $this->eventTypeRepository->findAllActive();
|
||||
|
||||
$builder = $this->filterOrderHelperFactory->create(__METHOD__);
|
||||
$builder
|
||||
->addDateRange('dates', 'event.filter.event_dates')
|
||||
->addSearchBox(['name'])
|
||||
->addEntityChoice('event_types', 'event.filter.event_types', EventType::class, $types, [
|
||||
'choice_label' => fn (EventType $e) => $this->translatableStringHelper->localize($e->getName()),
|
||||
]);
|
||||
|
||||
return $builder->build();
|
||||
}
|
||||
|
||||
private function createAddParticipationByPersonForm(Event $event): FormInterface
|
||||
{
|
||||
$builder = $this->formFactory
|
||||
->createNamedBuilder(
|
||||
'',
|
||||
FormType::class,
|
||||
null,
|
||||
[
|
||||
'method' => 'GET',
|
||||
'action' => $this->urlGenerator->generate('chill_event_participation_new'),
|
||||
'csrf_protection' => false,
|
||||
]
|
||||
);
|
||||
|
||||
$builder->add('person_id', PickPersonDynamicType::class, [
|
||||
'as_id' => true,
|
||||
'multiple' => false,
|
||||
'submit_on_adding_new_entity' => true,
|
||||
'label' => 'Add a participation',
|
||||
]);
|
||||
|
||||
$builder->add('event_id', HiddenType::class, [
|
||||
'data' => $event->getId(),
|
||||
]);
|
||||
|
||||
return $builder->getForm();
|
||||
}
|
||||
}
|
@@ -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