mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
[repository][action filter] integrating filters in repository
This commit is contained in:
parent
61982634a6
commit
20d5fabc18
@ -161,7 +161,7 @@ class AccompanyingCourseWorkController extends AbstractController
|
||||
'types' => $filter->getEntityChoiceData('typesFilter'),
|
||||
'before' => $filter->getDateRangeData('dateFilter')['to'],
|
||||
'after' => $filter->getDateRangeData('dateFilter')['from'],
|
||||
'user' => $filter->getUserPickerData('userFilter')
|
||||
'users' => $filter->getUserPickerData('userFilter')
|
||||
];
|
||||
|
||||
$totalItems = $this->workRepository->countByAccompanyingPeriod($period);
|
||||
@ -219,7 +219,7 @@ class AccompanyingCourseWorkController extends AbstractController
|
||||
{
|
||||
|
||||
$filterBuilder = $this->filterOrderHelperFactory->create(self::class);
|
||||
$types = $this->workRepository->findByAccompanyingPeriod($associatedPeriod);
|
||||
$types = $this->workRepository->findActionTypeByPeriod($associatedPeriod);
|
||||
|
||||
$filterBuilder
|
||||
->addDateRange('dateFilter', 'accompanying_course_work.date_filter')
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user