Add a filter to AccompanyingCourseWorkController.php list for acpw where current user intervenes

This commit is contained in:
Julie Lenaerts 2025-07-17 11:07:04 +02:00
parent 5f01673404
commit 1b655b19ef
4 changed files with 21 additions and 2 deletions

View File

@ -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

View File

@ -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,12 +131,16 @@ 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') : [],
'before' => $filter->getDateRangeData('dateFilter')['to'],
'after' => $filter->getDateRangeData('dateFilter')['from'],
'user' => $filter->getUserPickerData('userFilter'),
'currentUser' => $filter->getSingleCheckboxData('myActionsFilter')
? ($currentUser instanceof User ? $currentUser : null)
: null,
];
$totalItems = $this->workRepository->countByAccompanyingPeriod($period);
@ -201,6 +206,8 @@ final class AccompanyingCourseWorkController extends AbstractController
->addUserPicker('userFilter', 'accompanying_course_work.user_filter', ['required' => false])
;
$filterBuilder->addSingleCheckbox('myActionsFilter', 'accompanying_course_work.my_actions_filter');
return $filterBuilder->build();
}
}

View File

@ -21,6 +21,7 @@ use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Query\ResultSetMappingBuilder;
use Doctrine\ORM\QueryBuilder;
use Doctrine\Persistence\ObjectRepository;
use Symfony\Component\Security\Core\User\UserInterface;
class AccompanyingPeriodWorkRepository implements ObjectRepository
{
@ -90,7 +91,7 @@ class AccompanyingPeriodWorkRepository implements ObjectRepository
* * first, opened works
* * then, closed works
*
* @param array{types?: list<SocialAction>, user?: list<User>, after?: \DateTimeImmutable|null, before?: \DateTimeImmutable|null} $filters
* @param array{types?: list<SocialAction>, user?: list<User>, currentUser?: User, after?: \DateTimeImmutable|null, before?: \DateTimeImmutable|null} $filters
*
* @return AccompanyingPeriodWork[]
*/
@ -101,6 +102,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 +121,10 @@ class AccompanyingPeriodWorkRepository implements ObjectRepository
.')';
}
if (isset($filters['currentUser'])) {
$sql .= ' AND rw.user_id = '.$filters['currentUser']->getId();
}
$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

View File

@ -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