fix: limit destination autocomplete results to upcoming dates
This commit is contained in:
@@ -24,12 +24,11 @@ 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->where(
|
||||
$qb->expr()->andX(
|
||||
$qb->expr()->isNull('destination.deletedAt'),
|
||||
$qb->expr()->orX(
|
||||
@@ -40,6 +39,16 @@ class DestinationRepository extends ServiceEntityRepository
|
||||
))
|
||||
)
|
||||
->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