From 69d5b556a440b080045253337cefbe781e6fa535 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Mon, 16 Oct 2023 16:46:23 +0200 Subject: [PATCH] Feat: Add repository method to fetch filter options --- src/Repository/AssignmentRepository.php | 48 +++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/src/Repository/AssignmentRepository.php b/src/Repository/AssignmentRepository.php index f71b4d8..fd26356 100644 --- a/src/Repository/AssignmentRepository.php +++ b/src/Repository/AssignmentRepository.php @@ -60,4 +60,52 @@ class AssignmentRepository extends ServiceEntityRepository return $qb->getQuery(); } + + public function getFilterOptions(): array + { + $options = []; + + // Date range + $qb = $this->createQueryBuilder('assignment'); + $result = $qb + ->select('MIN(destination.dateFrom) minDate', 'MAX(destination.dateTo) maxDate') + ->innerJoin('assignment.destination', 'destination') + ->getQuery() + ->getSingleResult() + ; + + $options['minDate'] = $result['minDate']; + $options['maxDate'] = $result['maxDate']; + + // Job-profiles + $qb = $this->createQueryBuilder('assignment'); + $result = $qb + ->select('job_profile.id', 'job_profile.name') + ->innerJoin('assignment.jobProfile', 'job_profile') + ->orderBy('job_profile.name', 'ASC') + ->getQuery() + ->getArrayResult() + ; + + foreach ($result as $row) { + $options['jobProfiles'][$row['id']] = $row['name']; + } + + // Products + $qb = $this->createQueryBuilder('assignment'); + $result = $qb + ->select('destination.id id', 'destination.product product', 'destination.hotel hotel') + ->innerJoin('assignment.destination', 'destination') + ->orderBy('destination.product', 'ASC') + ->groupBy('destination.id') + ->getQuery() + ->getArrayResult() + ; + + foreach ($result as $row) { + $options['products'][$row['id']] = $row['product']; + } + + return $options; + } }