feat: remove date constraints from price calendar

This commit is contained in:
2026-08-26 13:33:10 +02:00
parent 0bdc6c873b
commit d7219ec341
2 changed files with 22 additions and 15 deletions
@@ -57,6 +57,7 @@ class AjaxCalendarController extends ActionController
$this->tagPageCacheForHotel($hotelCode);
$dateRange = DateUtility::getDateRange(null, null, $months);
$period = $dateRange['period'];
$today = new \DateTimeImmutable('today');
$priceDataByDate = [];
@@ -69,11 +70,7 @@ class AjaxCalendarController extends ActionController
// for config.cache_period. An additional application-level cache here would
// key on exactly the same granularity (hotel + date range) and only stack a
// second TTL on top, pushing worst-case staleness past the freshness budget.
$rawData = $this->myEpClient->getPriceConfigData(
$hotelCode,
$dateRange['period']->getStartDate(),
$dateRange['period']->getEndDate()
);
$rawData = $this->myEpClient->getPriceConfigData($hotelCode);
$availableDates = [];
foreach ($rawData as $item) {
@@ -82,6 +79,11 @@ class AjaxCalendarController extends ActionController
}
}
// The API no longer honours a date-range constraint, so it may return data
// further out than the default $months grid covers. Grow the grid to match
// whatever the API actually returned rather than silently dropping the tail.
$lastDataDate = null;
foreach ($rawData as $item) {
$date = $item['date'];
$dt = \DateTimeImmutable::createFromFormat('Y-m-d', $date);
@@ -89,6 +91,10 @@ class AjaxCalendarController extends ActionController
continue;
}
if (null === $lastDataDate || $dt > $lastDataDate) {
$lastDataDate = $dt;
}
$prevDate = $dt->modify('-1 day')->format('Y-m-d');
$isAvailable = ($item['status'] ?? '') === 'OK';
$prevAvailable = isset($availableDates[$prevDate]);
@@ -113,6 +119,13 @@ class AjaxCalendarController extends ActionController
'minNights' => (int)($item['minNights'] ?? 0),
];
}
if (null !== $lastDataDate) {
$dataEnd = $lastDataDate->modify('first day of next month')->setTime(0, 0, 0);
if ($dataEnd > $period->getEndDate()) {
$period = new \League\Period\Period($period->getStartDate(), $dataEnd);
}
}
} catch (ApiException $e) {
$error = true;
$errorMessage = $e->getMessage();
@@ -126,18 +139,14 @@ class AjaxCalendarController extends ActionController
$this->view->assignMultiple([
'priceDataByDate' => $priceDataByDate,
'calendarMonths' => $this->buildCalendarMonths($dateRange['period']),
'calendarMonths' => $this->buildCalendarMonths($period),
'error' => $error,
'errorMessage' => $errorMessage,
]);
}
public function priceConfigAction(Hotel $hotel, string $year = null, string $month = null, int $months = 12)
public function priceConfigAction(Hotel $hotel): void
{
$dateRange = DateUtility::getDateRange($year, $month, $months);
$apiDateFrom = $dateRange['period']->getStartDate();
$apiDateTo = $dateRange['period']->getEndDate();
$hotelCode = trim($hotel->getCode() ?? '');
$this->tagPageCacheForHotel($hotelCode);
@@ -148,7 +157,7 @@ class AjaxCalendarController extends ActionController
];
try {
$priceConfig['data'] = $this->myEpClient->getPriceConfigData($hotelCode, $apiDateFrom, $apiDateTo);
$priceConfig['data'] = $this->myEpClient->getPriceConfigData($hotelCode);
} catch (ApiException $e) {
$priceConfig['success'] = false;
$priceConfig['error'] = $e->getMessage();
@@ -144,13 +144,11 @@ class ApiClient implements LoggerAwareInterface
/**
* @throws ApiException
*/
public function getPriceConfigData(string $hotelCode, \DateTimeImmutable $dateFrom, \DateTimeImmutable $dateTo): array
public function getPriceConfigData(string $hotelCode): array
{
return $this->requestJson('GET', 'contingents/calendar', [
'query' => [
'hotelCode' => $hotelCode,
'dateFrom' => $dateFrom->format('Y-m-d'),
'dateTo' => $dateTo->format('Y-m-d'),
],
]);
}