fix: limit destination autocomplete results to upcoming dates
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user