45 lines
1.3 KiB
PHP
45 lines
1.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Repository\Groups;
|
|
|
|
use App\Entity\Groups\AccommodationPrice;
|
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
|
use Doctrine\Persistence\ManagerRegistry;
|
|
|
|
/**
|
|
* @extends ServiceEntityRepository<AccommodationPrice>
|
|
*/
|
|
class AccommodationPriceRepository extends ServiceEntityRepository
|
|
{
|
|
public function __construct(ManagerRegistry $registry)
|
|
{
|
|
parent::__construct($registry, AccommodationPrice::class);
|
|
}
|
|
|
|
/**
|
|
* Returns all AccommodationPrice records whose period overlaps with [dateFrom, dateTo]
|
|
* for the accommodation identified by the given hotel code.
|
|
*
|
|
* @return AccommodationPrice[]
|
|
*/
|
|
public function findByHotelCodeAndDateRange(
|
|
string $hotelCode,
|
|
\DateTimeImmutable $dateFrom,
|
|
\DateTimeImmutable $dateTo,
|
|
): array {
|
|
return $this->createQueryBuilder('ap')
|
|
->join('ap.accommodation', 'a')
|
|
->where('a.calendarCode = :hotelCode')
|
|
->andWhere('ap.dateFrom <= :dateTo')
|
|
->andWhere('ap.dateTo >= :dateFrom')
|
|
->setParameter('hotelCode', $hotelCode)
|
|
->setParameter('dateFrom', $dateFrom)
|
|
->setParameter('dateTo', $dateTo)
|
|
->orderBy('ap.dateFrom', 'ASC')
|
|
->getQuery()
|
|
->getResult();
|
|
}
|
|
}
|