* * @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 getListQueryForCustom(): Query { $qb = $this->createQueryBuilder('destination'); return $qb ->where( $qb->expr()->andX( $qb->expr()->isNull('destination.deletedAt'), $qb->expr()->isNull('destination.busProId')) ) ->getQuery() ; } public function getAutocompletionData(string $search, bool $upcomingOnly = true): array { $qb = $this->createQueryBuilder('destination'); $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') )) ) ->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() ->getResult() ; $data = [ [ 'value' => '', 'text' => '...', ], ]; foreach ($dates as $date) { $data[] = [ 'value' => $date->getId(), 'text' => (string) $date, ]; } return $data; } public function getHotels(): array { $qb = $this->createQueryBuilder('destination'); return $qb ->select('destination.hotel', 'destination.hotelCode', 'destination.hotelBusProId') ->groupBy('destination.hotelBusProId') ->orderBy('destination.hotel', 'ASC') ->getQuery() ->getArrayResult() ; } }