Feat: Add repository method to fetch filter options
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user