61 lines
1.8 KiB
PHP
61 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Repository;
|
|
|
|
use App\Entity\Destination;
|
|
use App\Repository\Traits\QueryHelperTrait;
|
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
|
use Doctrine\Persistence\ManagerRegistry;
|
|
|
|
/**
|
|
* @extends ServiceEntityRepository<Destination>
|
|
*
|
|
* @method Destination|null find($id, $lockMode = null, $lockVersion = null)
|
|
* @method Destination|null findOneBy(array $criteria, array $orderBy = null)
|
|
* @method Destination[] findAll()
|
|
* @method Destination[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
|
*/
|
|
class DestinationRepository extends ServiceEntityRepository
|
|
{
|
|
use QueryHelperTrait;
|
|
|
|
public function __construct(ManagerRegistry $registry)
|
|
{
|
|
parent::__construct($registry, Destination::class);
|
|
}
|
|
|
|
public function getAutocompletionData(string $search): array
|
|
{
|
|
$qb = $this->createQueryBuilder('destination');
|
|
|
|
$dates = $qb
|
|
->where($qb->expr()->orX(
|
|
$qb->expr()->like('destination.product', ':product'),
|
|
$qb->expr()->like('destination.hotel', ':hotel')
|
|
))
|
|
->setParameter('product', '%'.$this->escapeLikeWildcards($search).'%')
|
|
->setParameter('hotel', '%'.$this->escapeLikeWildcards($search).'%')
|
|
->orderBy('destination.dateFrom', 'ASC')
|
|
->addOrderBy('destination.product', 'ASC')
|
|
->getQuery()
|
|
->getResult()
|
|
;
|
|
|
|
$data = [
|
|
[
|
|
'value' => '',
|
|
'text' => '...',
|
|
],
|
|
];
|
|
|
|
foreach ($dates as $date) {
|
|
$data[] = [
|
|
'value' => $date->getId(),
|
|
'text' => (string) $date,
|
|
];
|
|
}
|
|
|
|
return $data;
|
|
}
|
|
}
|