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); $this->tagPageCacheForHotel($hotelCode);
$dateRange = DateUtility::getDateRange(null, null, $months); $dateRange = DateUtility::getDateRange(null, null, $months);
$period = $dateRange['period'];
$today = new \DateTimeImmutable('today'); $today = new \DateTimeImmutable('today');
$priceDataByDate = []; $priceDataByDate = [];
@@ -69,11 +70,7 @@ class AjaxCalendarController extends ActionController
// for config.cache_period. An additional application-level cache here would // for config.cache_period. An additional application-level cache here would
// key on exactly the same granularity (hotel + date range) and only stack a // 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. // second TTL on top, pushing worst-case staleness past the freshness budget.
$rawData = $this->myEpClient->getPriceConfigData( $rawData = $this->myEpClient->getPriceConfigData($hotelCode);
$hotelCode,
$dateRange['period']->getStartDate(),
$dateRange['period']->getEndDate()
);
$availableDates = []; $availableDates = [];
foreach ($rawData as $item) { 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) { foreach ($rawData as $item) {
$date = $item['date']; $date = $item['date'];
$dt = \DateTimeImmutable::createFromFormat('Y-m-d', $date); $dt = \DateTimeImmutable::createFromFormat('Y-m-d', $date);
@@ -89,6 +91,10 @@ class AjaxCalendarController extends ActionController
continue; continue;
} }
if (null === $lastDataDate || $dt > $lastDataDate) {
$lastDataDate = $dt;
}
$prevDate = $dt->modify('-1 day')->format('Y-m-d'); $prevDate = $dt->modify('-1 day')->format('Y-m-d');
$isAvailable = ($item['status'] ?? '') === 'OK'; $isAvailable = ($item['status'] ?? '') === 'OK';
$prevAvailable = isset($availableDates[$prevDate]); $prevAvailable = isset($availableDates[$prevDate]);
@@ -113,6 +119,13 @@ class AjaxCalendarController extends ActionController
'minNights' => (int)($item['minNights'] ?? 0), '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) { } catch (ApiException $e) {
$error = true; $error = true;
$errorMessage = $e->getMessage(); $errorMessage = $e->getMessage();
@@ -126,18 +139,14 @@ class AjaxCalendarController extends ActionController
$this->view->assignMultiple([ $this->view->assignMultiple([
'priceDataByDate' => $priceDataByDate, 'priceDataByDate' => $priceDataByDate,
'calendarMonths' => $this->buildCalendarMonths($dateRange['period']), 'calendarMonths' => $this->buildCalendarMonths($period),
'error' => $error, 'error' => $error,
'errorMessage' => $errorMessage, '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() ?? ''); $hotelCode = trim($hotel->getCode() ?? '');
$this->tagPageCacheForHotel($hotelCode); $this->tagPageCacheForHotel($hotelCode);
@@ -148,7 +157,7 @@ class AjaxCalendarController extends ActionController
]; ];
try { try {
$priceConfig['data'] = $this->myEpClient->getPriceConfigData($hotelCode, $apiDateFrom, $apiDateTo); $priceConfig['data'] = $this->myEpClient->getPriceConfigData($hotelCode);
} catch (ApiException $e) { } catch (ApiException $e) {
$priceConfig['success'] = false; $priceConfig['success'] = false;
$priceConfig['error'] = $e->getMessage(); $priceConfig['error'] = $e->getMessage();
@@ -144,13 +144,11 @@ class ApiClient implements LoggerAwareInterface
/** /**
* @throws ApiException * @throws ApiException
*/ */
public function getPriceConfigData(string $hotelCode, \DateTimeImmutable $dateFrom, \DateTimeImmutable $dateTo): array public function getPriceConfigData(string $hotelCode): array
{ {
return $this->requestJson('GET', 'contingents/calendar', [ return $this->requestJson('GET', 'contingents/calendar', [
'query' => [ 'query' => [
'hotelCode' => $hotelCode, 'hotelCode' => $hotelCode,
'dateFrom' => $dateFrom->format('Y-m-d'),
'dateTo' => $dateTo->format('Y-m-d'),
], ],
]); ]);
} }