* * @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; } }