Compare commits

..
3 Commits
5 changed files with 78 additions and 28 deletions

No files matched your search

@@ -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();
@@ -221,34 +221,64 @@ class ApiMiddleware implements MiddlewareInterface
$icons = [];
if (($hotel['beds_count'] ?? 0) > 0) {
$icons['bed'] = sprintf('%d Betten', $hotel['beds_count']);
$icons[] = [
'icon' => 'bed',
'label' => sprintf('%d Betten', $hotel['beds_count']),
];
}
if (($hotel['parking_count'] ?? 0) > 0) {
$icons['parking'] = sprintf('%d Parkplätze', $hotel['parking_count']);
$icons[] = [
'icon' => 'parking',
'label' => sprintf('%d Parkplätze', $hotel['parking_count']),
];
}
if ($hotel['altitude'] ?? null) {
$icons['mountain'] = $hotel['altitude'];
$icons[] = [
'icon' => 'mountain',
'label' => $hotel['altitude'],
];
}
if ($hotel['distance_bus'] ?? null) {
$icons['bus'] = $hotel['distance_bus'];
$icons[] = [
'icon' => 'bus',
'label' => $hotel['distance_bus'],
];
}
if ($hotel['distance_lift'] ?? null) {
$icons['lift'] = $hotel['distance_lift'];
$icons[] = [
'icon' => 'lift',
'label' => $hotel['distance_lift'],
];
}
if ($hotel['shower'] ?? null) {
$icons['shower'] = $hotel['shower'];
$icons[] = [
'icon' => 'shower',
'label' => $hotel['shower'],
];
}
if ($hotel['partyroom'] ?? false) {
$icons['party'] = 'Partyzimmer';
$icons[] = [
'icon' => 'party',
'label' => 'Partyzimmer',
];
}
if ($hotel['gamesroom'] ?? false) {
$icons['dice'] = 'Spielezimmer';
$icons[] = [
'icon' => 'dice',
'label' => 'Spielezimmer',
];
}
if ($hotel['sauna'] ?? false) {
$icons['sauna'] = 'Sauna';
$icons[] = [
'icon' => 'sauna',
'label' => 'Sauna',
];
}
if ($hotel['wifi'] ?? false) {
$icons['wifi'] = 'WiFi';
$icons[] = [
'icon' => 'wifi',
'label' => 'WiFi',
];
}
return [
@@ -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'),
],
]);
}
@@ -53,6 +53,15 @@
</config>
</TCEforms>
</settings.hideMoreLink>
<settings.hideHeader>
<TCEforms>
<exclude>0</exclude>
<label>Header ausblenden:</label>
<config>
<type>check</type>
</config>
</TCEforms>
</settings.hideHeader>
</el>
</ROOT>
</sDEF>
@@ -6,9 +6,13 @@
<f:layout name="Default"/>
<f:section name="Main">
<f:render partial="SubpageHeader"
arguments="{images: concept.headerImages, topline: concept.headerSubtitle, headline: concept.headerTitle, settings: settings}"/>
<f:cObject typoscriptObjectPath="lib.breadcrumb"/>
<f:if condition="{settings.hideHeader}">
<f:else>
<f:render partial="SubpageHeader"
arguments="{images: concept.headerImages, topline: concept.headerSubtitle, headline: concept.headerTitle, settings: settings}"/>
<f:cObject typoscriptObjectPath="lib.breadcrumb"/>
</f:else>
</f:if>
<div class="container">
<f:render partial="Header/Header"
arguments="{layout: 8, subheader: concept.name, header: concept.headline}"/>