Allow filtering of event list by center and responsable

This commit is contained in:
Julie Lenaerts 2025-07-02 17:55:22 +02:00
parent 0164c57eb4
commit 49ac25d3e1
6 changed files with 41 additions and 11 deletions

View File

@ -17,7 +17,6 @@ use Chill\ActivityBundle\Repository\ActivityReasonRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/** /**
* ActivityReason controller. * ActivityReason controller.

View File

@ -15,11 +15,15 @@ use Chill\EventBundle\Entity\Event;
use Chill\EventBundle\Entity\EventType; use Chill\EventBundle\Entity\EventType;
use Chill\EventBundle\Repository\EventACLAwareRepositoryInterface; use Chill\EventBundle\Repository\EventACLAwareRepositoryInterface;
use Chill\EventBundle\Repository\EventTypeRepository; use Chill\EventBundle\Repository\EventTypeRepository;
use Chill\EventBundle\Security\EventVoter;
use Chill\MainBundle\Entity\Center;
use Chill\MainBundle\Pagination\PaginatorFactoryInterface; use Chill\MainBundle\Pagination\PaginatorFactoryInterface;
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
use Chill\MainBundle\Templating\Listing\FilterOrderHelper; use Chill\MainBundle\Templating\Listing\FilterOrderHelper;
use Chill\MainBundle\Templating\Listing\FilterOrderHelperFactory; use Chill\MainBundle\Templating\Listing\FilterOrderHelperFactory;
use Chill\MainBundle\Templating\TranslatableStringHelperInterface; use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
use Chill\PersonBundle\Form\Type\PickPersonDynamicType; use Chill\PersonBundle\Form\Type\PickPersonDynamicType;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\Extension\Core\Type\FormType; use Symfony\Component\Form\Extension\Core\Type\FormType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType; use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\FormFactoryInterface; use Symfony\Component\Form\FormFactoryInterface;
@ -29,17 +33,18 @@ use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Twig\Environment; use Twig\Environment;
final readonly class EventListController final class EventListController extends AbstractController
{ {
public function __construct( public function __construct(
private Environment $environment, private readonly Environment $environment,
private EventACLAwareRepositoryInterface $eventACLAwareRepository, private readonly EventACLAwareRepositoryInterface $eventACLAwareRepository,
private EventTypeRepository $eventTypeRepository, private readonly EventTypeRepository $eventTypeRepository,
private FilterOrderHelperFactory $filterOrderHelperFactory, private readonly FilterOrderHelperFactory $filterOrderHelperFactory,
private FormFactoryInterface $formFactory, private readonly FormFactoryInterface $formFactory,
private PaginatorFactoryInterface $paginatorFactory, private readonly PaginatorFactoryInterface $paginatorFactory,
private TranslatableStringHelperInterface $translatableStringHelper, private readonly TranslatableStringHelperInterface $translatableStringHelper,
private UrlGeneratorInterface $urlGenerator, private readonly UrlGeneratorInterface $urlGenerator,
private readonly AuthorizationHelper $authorizationHelper,
) {} ) {}
#[Route(path: '{_locale}/event/event/list', name: 'chill_event_event_list')] #[Route(path: '{_locale}/event/event/list', name: 'chill_event_event_list')]
@ -50,6 +55,8 @@ final readonly class EventListController
'q' => (string) $filter->getQueryString(), 'q' => (string) $filter->getQueryString(),
'dates' => $filter->getDateRangeData('dates'), 'dates' => $filter->getDateRangeData('dates'),
'event_types' => $filter->getEntityChoiceData('event_types'), 'event_types' => $filter->getEntityChoiceData('event_types'),
'responsables' => $filter->getUserPickerData('responsables'),
'centers' => $filter->getEntityChoiceData('centers'),
]; ];
$total = $this->eventACLAwareRepository->countAllViewable($filterData); $total = $this->eventACLAwareRepository->countAllViewable($filterData);
$pagination = $this->paginatorFactory->create($total); $pagination = $this->paginatorFactory->create($total);
@ -73,6 +80,7 @@ final readonly class EventListController
private function buildFilterOrder(): FilterOrderHelper private function buildFilterOrder(): FilterOrderHelper
{ {
$types = $this->eventTypeRepository->findAllActive(); $types = $this->eventTypeRepository->findAllActive();
$centers = $this->authorizationHelper->getReachableCenters($this->getUser(), EventVoter::SEE);
$builder = $this->filterOrderHelperFactory->create(__METHOD__); $builder = $this->filterOrderHelperFactory->create(__METHOD__);
$builder $builder
@ -80,6 +88,10 @@ final readonly class EventListController
->addSearchBox(['name']) ->addSearchBox(['name'])
->addEntityChoice('event_types', 'event.filter.event_types', EventType::class, $types, [ ->addEntityChoice('event_types', 'event.filter.event_types', EventType::class, $types, [
'choice_label' => fn (EventType $e) => $this->translatableStringHelper->localize($e->getName()), 'choice_label' => fn (EventType $e) => $this->translatableStringHelper->localize($e->getName()),
])
->addUserPicker('responsables', 'event.filter.pick_responsable', ['multiple' => true, 'required' => false])
->addEntityChoice('centers', 'event.filter.center', Center::class, $centers, [
'choice_label' => fn (Center $c) => $c->getName(),
]); ]);
return $builder->build(); return $builder->build();

View File

@ -15,7 +15,6 @@ use Chill\DocStoreBundle\Entity\StoredObject;
use Chill\DocStoreBundle\Form\StoredObjectType; use Chill\DocStoreBundle\Form\StoredObjectType;
use Chill\EventBundle\Entity\BudgetTypeEnum; use Chill\EventBundle\Entity\BudgetTypeEnum;
use Chill\EventBundle\Entity\Event; use Chill\EventBundle\Entity\Event;
use Chill\EventBundle\Form\Type\PickAnimatorType;
use Chill\EventBundle\Form\Type\PickEventThemeType; use Chill\EventBundle\Form\Type\PickEventThemeType;
use Chill\EventBundle\Form\Type\PickEventTypeType; use Chill\EventBundle\Form\Type\PickEventTypeType;
use Chill\EventBundle\Repository\EventBudgetKindRepository; use Chill\EventBundle\Repository\EventBudgetKindRepository;

View File

@ -88,6 +88,16 @@ final readonly class EventACLAwareRepository implements EventACLAwareRepositoryI
$qb->andWhere('event.type IN (:event_types)'); $qb->andWhere('event.type IN (:event_types)');
$qb->setParameter('event_types', $filters['event_types']); $qb->setParameter('event_types', $filters['event_types']);
} }
if (0 < count($filters['centers'] ?? [])) {
$qb->andWhere('event.center IN (:centers)');
$qb->setParameter('centers', $filters['centers']);
}
if (0 < count($filters['responsables'] ?? [])) {
$qb->andWhere('event.moderator IN (:responsables)');
$qb->setParameter('responsables', $filters['responsables']);
}
} }
public function buildQueryByAllViewable(array $filters): QueryBuilder public function buildQueryByAllViewable(array $filters): QueryBuilder

View File

@ -2,6 +2,13 @@
declare(strict_types=1); 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\Migrations\Event; namespace Chill\Migrations\Event;
use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Schema\Schema;

View File

@ -151,6 +151,9 @@ event:
filter: filter:
event_types: Par types d'événement event_types: Par types d'événement
event_dates: Par date d'événement event_dates: Par date d'événement
center: Par centre
by_responsable: Par responsable
pick_responsable: Filtrer par responsables
budget: budget:
resources: Ressources resources: Ressources
charges: Charges charges: Charges