diff --git a/packages/ep_products/Classes/Service/IcalService.php b/packages/ep_products/Classes/Service/IcalService.php index 1877571..cafbef8 100644 --- a/packages/ep_products/Classes/Service/IcalService.php +++ b/packages/ep_products/Classes/Service/IcalService.php @@ -10,18 +10,21 @@ use Psr\Log\LoggerAwareInterface; use Psr\Log\LoggerAwareTrait; /** - * Contingent feed of a hotel for the booking portals, with the events of TYPO3 10 + * Contingent feed of a hotel for the booking portals * * The availability comes from MyE&P (contingents/availability, the bpn-connect snapshot without the - * price rule of contingents/calendar); TYPO3 10 read it from bpn-connect directly. Every run of - * BLOCKED or ON_REQUEST days with one status becomes one "Unavailable" event, as bpn-connect's - * ranges did. + * price rule of contingents/calendar). Like the sidebar calendar, it has three levels: every run of + * BLOCKED days becomes an "Unavailable" event, every run of ON_REQUEST days (partly available) a + * "Part-occupied:N" event, the format of TYPO3 10 until June 2026; OK days get no event. TYPO3 10 + * took N from the booked beds of the XML import, which no longer exists, so N stands in for it: + * half of the hotel's beds, at least 1. */ class IcalService implements LoggerAwareInterface { use LoggerAwareTrait; private const string SUMMARY_UNAVAILABLE = 'Unavailable'; + private const string SUMMARY_PART_OCCUPIED = 'Part-occupied:%d'; public function __construct( private readonly ApiClient $apiClient, @@ -48,19 +51,20 @@ class IcalService implements LoggerAwareInterface $vcalendar = Vcalendar::factory([Vcalendar::UNIQUE_ID => 'www.ep-reisen.de']); $vcalendar->setXprop(Vcalendar::X_WR_TIMEZONE, 'Europe/Berlin'); + $partOccupiedSummary = sprintf(self::SUMMARY_PART_OCCUPIED, max(1, intdiv((int)$hotel->getBedsCount(), 2))); foreach ($this->buildRanges($calendarRows) as $range) { $vcalendar ->newVevent() ->setDtstart($range['from']) ->setDtend($range['to']->modify('+1 day')) - ->setSummary(self::SUMMARY_UNAVAILABLE); + ->setSummary('ON_REQUEST' === $range['status'] ? $partOccupiedSummary : self::SUMMARY_UNAVAILABLE); } return $vcalendar->vtimezonePopulate()->createCalendar(); } /** - * @return array unavailable runs, both ends inclusive + * @return array BLOCKED / ON_REQUEST runs, both ends inclusive */ private function buildRanges(array $calendarRows): array { @@ -96,7 +100,7 @@ class IcalService implements LoggerAwareInterface $ranges[] = $current; } - return array_map(fn (array $range): array => ['from' => $range['from'], 'to' => $range['to']], $ranges); + return $ranges; } private function normalizeStatus(string $status): string