[repository][action filter] integrating filters in repository

This commit is contained in:
2023-07-06 13:39:08 +02:00
parent 61982634a6
commit 20d5fabc18
2 changed files with 58 additions and 4 deletions

View File

@@ -108,8 +108,32 @@ final class AccompanyingPeriodWorkRepository implements ObjectRepository
CASE WHEN enddate IS NULL THEN '-infinity'::timestamp ELSE 'infinity'::timestamp END ASC,
startdate DESC,
enddate DESC,
id DESC
LIMIT :limit OFFSET :offset";
id DESC";
// implement filters
if([] !== ($filters['types'] ?? []))
{
$sql .= "AND WHERE w.socialAction IN (:types)";
}
if([] !== ($filters['users'] ?? []))
{
$sql .= "AND WHERE w.createdBy IN (:users)";
foreach ($filters['users'] as $key => $user) {
$sql .= "OR :user_" . $key . " IN w.referrers)";
$nq = $this->em->createNativeQuery($sql, $rsm)
->setParameter(':user_' . $key);
}
// ... to be continued
}
// set limit and offset
$sql .= " LIMIT :limit OFFSET :offset";
$nq = $this->em->createNativeQuery($sql, $rsm)
->setParameter('periodId', $period->getId(), Types::INTEGER)
@@ -119,6 +143,36 @@ final class AccompanyingPeriodWorkRepository implements ObjectRepository
return $nq->getResult();
}
/**
* Return a list of types of social actions associated to the accompanying period
*
* @return array<SocialAction>
*/
public function findActionTypeByPeriod(AccompanyingPeriod $period): array
{
$in = $this->em->createQueryBuilder();
$in
->select('1')
->from(AccompanyingPeriodWork::class, 'apw');
$in->andWhere('apw.accompanyingPeriod = :period')->setParameter('period', $period);
// join between the embedded exist query and the main query
$in->andWhere('apw.socialAction = sa');
$qb = $this->em->createQueryBuilder()->setParameters($in->getParameters());
$qb
->select('sa')
->from(SocialAction::class, 'sa')
->where(
$qb->expr()->exists($in->getDQL())
);
return $qb->getQuery()->getResult();
}
public function findNearEndDateByUser(User $user, DateTimeImmutable $since, DateTimeImmutable $until, int $limit = 20, int $offset = 0): array
{
return $this->buildQueryNearEndDateByUser($user, $since, $until)