feat: derive calendar date range from price configurations
This commit is contained in:
1 parent
61e020c3d0
commit
80d734e7d6
6 files changed
+260
-25
No files matched your search
@@ -41,4 +41,33 @@ class AccommodationPriceRepository extends ServiceEntityRepository
|
||||
->getQuery()
|
||||
->getResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* The outer bounds of every persisted price period for the accommodation, or null when it has none.
|
||||
*
|
||||
* @return array{from: \DateTimeImmutable, to: \DateTimeImmutable}|null
|
||||
*/
|
||||
public function findPricedDateBoundsByHotelCode(string $hotelCode): ?array
|
||||
{
|
||||
/** @var array{minFrom: string|null, maxTo: string|null} $bounds */
|
||||
$bounds = $this->createQueryBuilder('ap')
|
||||
->select('MIN(ap.dateFrom) AS minFrom', 'MAX(ap.dateTo) AS maxTo')
|
||||
->join('ap.accommodation', 'a')
|
||||
->where('a.calendarCode = :hotelCode')
|
||||
->setParameter('hotelCode', $hotelCode)
|
||||
->getQuery()
|
||||
->getSingleResult();
|
||||
|
||||
// An aggregate over no rows still returns one row, with both bounds null.
|
||||
if (null === $bounds['minFrom'] || null === $bounds['maxTo']) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Both columns are DATE_IMMUTABLE, so the aggregates come back as Y-m-d and land at 00:00 -
|
||||
// the same normalisation the day-by-day comparisons downstream expect.
|
||||
return [
|
||||
'from' => new \DateTimeImmutable($bounds['minFrom']),
|
||||
'to' => new \DateTimeImmutable($bounds['maxTo']),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user