Add a filter to list for acpw where current user intervenes

This commit is contained in:
2025-08-18 16:26:20 +00:00
committed by Julien Fastré
parent 481f82b4c7
commit 904f4e5ed9
4 changed files with 26 additions and 2 deletions

View File

@@ -90,7 +90,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 +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);
}