diff --git a/.changes/unreleased/Feature-20250717-110850.yaml b/.changes/unreleased/Feature-20250717-110850.yaml new file mode 100644 index 000000000..63a359e6e --- /dev/null +++ b/.changes/unreleased/Feature-20250717-110850.yaml @@ -0,0 +1,6 @@ +kind: Feature +body: Add filter to social actions list to filter out actions where current user intervenes +time: 2025-07-17T11:08:50.128269232+02:00 +custom: + Issue: "400" + SchemaChange: No schema change diff --git a/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseWorkController.php b/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseWorkController.php index 523d5a875..29362ba83 100644 --- a/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseWorkController.php +++ b/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseWorkController.php @@ -11,6 +11,7 @@ declare(strict_types=1); namespace Chill\PersonBundle\Controller; +use Chill\MainBundle\Entity\User; use Chill\MainBundle\Pagination\PaginatorFactory; use Chill\MainBundle\Templating\Listing\FilterOrderHelper; use Chill\MainBundle\Templating\Listing\FilterOrderHelperFactoryInterface; @@ -130,6 +131,7 @@ final class AccompanyingCourseWorkController extends AbstractController $this->denyAccessUnlessGranted(AccompanyingPeriodWorkVoter::SEE, $period); $filter = $this->buildFilterOrder($period); + $currentUser = $this->getUser(); $filterData = [ 'types' => $filter->hasEntityChoice('typesFilter') ? $filter->getEntityChoiceData('typesFilter') : [], @@ -138,6 +140,10 @@ final class AccompanyingCourseWorkController extends AbstractController 'user' => $filter->getUserPickerData('userFilter'), ]; + if ($filter->getSingleCheckboxData('currentUserFilter') && $currentUser instanceof User) { + $filterData['currentUser'] = $currentUser; + } + $totalItems = $this->workRepository->countByAccompanyingPeriod($period); $paginator = $this->paginator->create($totalItems); @@ -201,6 +207,8 @@ final class AccompanyingCourseWorkController extends AbstractController ->addUserPicker('userFilter', 'accompanying_course_work.user_filter', ['required' => false]) ; + $filterBuilder->addSingleCheckbox('currentUserFilter', 'accompanying_course_work.my_actions_filter'); + return $filterBuilder->build(); } } diff --git a/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriod/AccompanyingPeriodWorkRepository.php b/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriod/AccompanyingPeriodWorkRepository.php index 0d5bf5eee..df5ee6c66 100644 --- a/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriod/AccompanyingPeriodWorkRepository.php +++ b/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriod/AccompanyingPeriodWorkRepository.php @@ -90,7 +90,7 @@ class AccompanyingPeriodWorkRepository implements ObjectRepository * * first, opened works * * then, closed works * - * @param array{types?: list, user?: list, after?: \DateTimeImmutable|null, before?: \DateTimeImmutable|null} $filters + * @param array{types?: list, user?: list, currentUser?: User, after?: \DateTimeImmutable|null, before?: \DateTimeImmutable|null} $filters * * @return AccompanyingPeriodWork[] */ @@ -101,6 +101,7 @@ class AccompanyingPeriodWorkRepository implements ObjectRepository $sql = "SELECT {$rsm} FROM chill_person_accompanying_period_work w LEFT JOIN chill_person_accompanying_period_work_referrer AS rw ON accompanyingperiodwork_id = w.id + AND (rw.enddate IS NULL OR rw.enddate > CURRENT_DATE) WHERE accompanyingPeriod_id = :periodId"; // implement filters @@ -119,6 +120,10 @@ class AccompanyingPeriodWorkRepository implements ObjectRepository .')'; } + if (isset($filters['currentUser'])) { + $sql .= ' AND rw.user_id = :currentUser'; + } + $sql .= " AND daterange(:after::date, :before::date) && daterange(w.startDate, w.endDate, '[]')"; // if the start and end date were inversed, we inverse the order to avoid an error @@ -152,6 +157,11 @@ class AccompanyingPeriodWorkRepository implements ObjectRepository ->setParameter('limit', $limit, Types::INTEGER) ->setParameter('offset', $offset, Types::INTEGER); + if (isset($filters['currentUser'])) { + $nq->setParameter('currentUser', $filters['currentUser']->getId()); + } + + foreach ($filters['user'] as $key => $user) { $nq->setParameter('user_'.$key, $user); } diff --git a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml index c9f1af282..958ccb246 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml @@ -926,7 +926,7 @@ accompanying_course_work: types_filter: Filtrer par type d'action user_filter: Filtrer par intervenant On-going works over total: Actions en cours / Actions du parcours - + my_actions_filter: Mes actions (où j'interviens) # Person addresses: Adresses de résidence