feat: filter availabilities
addresses #869at5k4f
This commit is contained in:
@@ -4,6 +4,7 @@ namespace App\Repository;
|
||||
|
||||
use App\Entity\Availability;
|
||||
use App\Entity\Teamer;
|
||||
use App\Model\AvailabilityFilterDto;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\ORM\Query;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
@@ -23,7 +24,7 @@ class AvailabilityRepository extends ServiceEntityRepository
|
||||
parent::__construct($registry, Availability::class);
|
||||
}
|
||||
|
||||
public function getListQuery(bool $custom = false): Query
|
||||
public function getListQuery(bool $custom = false, ?AvailabilityFilterDto $filterDto = null): Query
|
||||
{
|
||||
$qb = $this->createQueryBuilder('availability');
|
||||
|
||||
@@ -49,6 +50,50 @@ class AvailabilityRepository extends ServiceEntityRepository
|
||||
;
|
||||
}
|
||||
|
||||
if (null === $filterDto) {
|
||||
return $qb->getQuery();
|
||||
}
|
||||
|
||||
if (null !== $dateFrom = $filterDto->getDateFrom()) {
|
||||
$qb
|
||||
->andWhere($qb->expr()->gte('availability.dateFrom', ':dateFrom'))
|
||||
->setParameter('dateFrom', $dateFrom)
|
||||
;
|
||||
}
|
||||
|
||||
if (null !== $dateTo = $filterDto->getDateTo()) {
|
||||
$qb
|
||||
->andWhere($qb->expr()->lte('availability.dateTo', ':dateTo'))
|
||||
->setParameter('dateTo', $dateTo)
|
||||
;
|
||||
}
|
||||
|
||||
if (null !== $teamer = $filterDto->getTeamer()) {
|
||||
$qb
|
||||
->andWhere($qb->expr()->eq('availability.owner', ':teamer'))
|
||||
->setParameter('teamer', $teamer)
|
||||
;
|
||||
}
|
||||
|
||||
if (0 < count($jobProfiles = $filterDto->getJobProfiles())) {
|
||||
// a join on the job-profiles would multiply the availability whenever its
|
||||
// owner holds more than one of the selected profiles, which would break
|
||||
// the pagination count, so the owner is matched against a subquery instead
|
||||
$subQuery = $this
|
||||
->getEntityManager()
|
||||
->createQueryBuilder()
|
||||
->select('profileTeamer.id')
|
||||
->from(Teamer::class, 'profileTeamer')
|
||||
->innerJoin('profileTeamer.jobProfiles', 'filterJobProfile')
|
||||
->where('filterJobProfile IN (:jobProfiles)')
|
||||
;
|
||||
|
||||
$qb
|
||||
->andWhere($qb->expr()->in('availability.owner', $subQuery->getDQL()))
|
||||
->setParameter('jobProfiles', $jobProfiles)
|
||||
;
|
||||
}
|
||||
|
||||
return $qb->getQuery();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user