feat: add filtering of applications

This commit is contained in:
Björn Fromme
2025-02-10 17:08:42 +01:00
parent 2c189de0c7
commit 3e2c5976aa
8 changed files with 514 additions and 7 deletions
+67 -3
View File
@@ -5,6 +5,8 @@ namespace App\Repository;
use App\Entity\Application;
use App\Entity\Assignment;
use App\Entity\Teamer;
use App\Model\ApplicationFilterDto;
use App\Model\AssignmentFilterDto;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\ORM\Query;
use Doctrine\Persistence\ManagerRegistry;
@@ -24,11 +26,11 @@ class ApplicationRepository extends ServiceEntityRepository
parent::__construct($registry, Application::class);
}
public function getPendingQuery(): Query
public function getPendingQuery(ApplicationFilterDto $filterDto): Query
{
$qb = $this->createQueryBuilder('application');
return $qb
$qb
->select('application', 'assignment', 'destination', 'job_profile', 'teamer')
->innerJoin('application.assignment', 'assignment')
->innerJoin('assignment.destination', 'destination')
@@ -36,8 +38,70 @@ class ApplicationRepository extends ServiceEntityRepository
->innerJoin('application.teamer', 'teamer')
->where($qb->expr()->neq('application.status', ':status'))
->setParameter('status', Application::STATUS_REJECTED)
->getQuery()
;
if (false === $filterDto->isIncludePast()) {
$qb
->andWhere($qb->expr()->gte('destination.dateFrom', ':now'))
->setParameter('now', new \DateTimeImmutable())
;
}
if (null !== $dateFrom = $filterDto->getDateFrom()) {
$qb
->andWhere($qb->expr()->gte('destination.dateFrom', ':dateFrom'))
->setParameter('dateFrom', $dateFrom)
;
}
if (null !== $dateTo = $filterDto->getDateTo()) {
$qb
->andWhere($qb->expr()->lte('destination.dateTo', ':dateTo'))
->setParameter('dateTo', $dateTo)
;
}
if ($jobProfiles = $filterDto->getJobProfiles()) {
$qb
->andWhere($qb->expr()->in('assignment.jobProfile', ':jobProfiles'))
->setParameter('jobProfiles', $jobProfiles)
;
}
if (0 < count($filterDto->getHotels())) {
$constraints = [];
foreach ($filterDto->getHotels() as $index => $hotel) {
$constraints[] = $qb->expr()->like('destination.hotel', ':hotel'.$index);
}
$qb->andWhere($qb->expr()->orX(...$constraints));
foreach ($filterDto->getHotels() as $index => $hotel) {
$qb->setParameter('hotel'.$index, '%'.$hotel.'%');
}
}
if (null !== $duration = $filterDto->getDuration()) {
$days = match ($duration) {
AssignmentFilterDto::DURATION_WEEKEND => [2, 4],
AssignmentFilterDto::DURATION_MID_WEEK => [5, 6],
AssignmentFilterDto::DURATION_FULL_WEEK => [7, 7],
default => [8, 0],
};
[$minDays, $maxDays] = $days;
$qb
->andWhere($qb->expr()->gte('DATEDIFF(destination.dateTo, destination.dateFrom)', ':minDays'))
->setParameter('minDays', $minDays)
;
if (0 < $maxDays) {
$qb
->andWhere($qb->expr()->lte('DATEDIFF(destination.dateTo, destination.dateFrom)', ':maxDays'))
->setParameter('maxDays', $maxDays)
;
}
}
return $qb->getQuery();
}
public function getPendingForTeamerQuery(Teamer $teamer): Query