fix: limit destination autocomplete results to upcoming dates

This commit is contained in:
Björn Fromme
2024-01-13 11:44:58 +01:00
parent 1654ab9903
commit b279646780
+21 -12
View File
@@ -24,22 +24,31 @@ class DestinationRepository extends ServiceEntityRepository
parent::__construct($registry, Destination::class);
}
public function getAutocompletionData(string $search): array
public function getAutocompletionData(string $search, bool $upcomingOnly = true): array
{
$qb = $this->createQueryBuilder('destination');
$dates = $qb
->where(
$qb->expr()->andX(
$qb->expr()->isNull('destination.deletedAt'),
$qb->expr()->orX(
$qb->expr()->like('destination.product', ':search'),
$qb->expr()->like('destination.hotel', ':search'),
$qb->expr()->like('DATE_FORMAT(destination.dateFrom, \'%d.%m.%y\')', ':search'),
$qb->expr()->like('DATE_FORMAT(destination.dateTo, \'%d.%m.%y\')', ':search')
))
)
$qb->where(
$qb->expr()->andX(
$qb->expr()->isNull('destination.deletedAt'),
$qb->expr()->orX(
$qb->expr()->like('destination.product', ':search'),
$qb->expr()->like('destination.hotel', ':search'),
$qb->expr()->like('DATE_FORMAT(destination.dateFrom, \'%d.%m.%y\')', ':search'),
$qb->expr()->like('DATE_FORMAT(destination.dateTo, \'%d.%m.%y\')', ':search')
))
)
->setParameter('search', '%'.$this->escapeLikeWildcards($search).'%')
;
if (true === $upcomingOnly) {
$qb
->andWhere($qb->expr()->gt('destination.dateFrom', ':now'))
->setParameter('now', new \DateTimeImmutable())
;
}
$dates = $qb
->orderBy('destination.dateFrom', 'ASC')
->addOrderBy('destination.product', 'ASC')
->getQuery()