Files
myep-team/src/Repository/DestinationRepository.php
T

102 lines
2.9 KiB
PHP

<?php
namespace App\Repository;
use App\Entity\Destination;
use App\Repository\Traits\QueryHelperTrait;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\ORM\Query;
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 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()
;
}
}