'Belegungsbeschreibung', 'guest_first_name' => 'Gastvorname / Namensbestandteil', 'guest_full_name' => 'Vollständiger Gastname', 'booking_reference' => 'Buchungsreferenz', 'note' => 'Zusätzliche Textinformation', 'property_name' => 'Wohnungsname', 'channel_name' => 'Bekannter Ursprung / Importkanal', 'arrival' => 'Anreise', 'departure' => 'Abreise', 'nights' => 'Anzahl Nächte']; public const ICAL_FIELDS = ['SUMMARY' => 'SUMMARY – Bezeichnung', 'DESCRIPTION' => 'DESCRIPTION – Beschreibung', 'LOCATION' => 'LOCATION – Ort / Wohnung']; /** @return array */ public function properties(Channel $channel, Booking|BlockedPeriod $occupation): array { $context = $this->context($occupation); if (! $channel->ical_export_names) { unset($context['guest_first_name'], $context['guest_full_name']); } $properties = ['SUMMARY' => 'Belegt']; foreach ($channel->ical_export_mapping ?? [] as $mapping) { if (! isset(self::ICAL_FIELDS[$mapping['field'] ?? ''])) { continue; } $parts = []; foreach ($mapping['items'] ?? [] as $item) { if (isset(self::FIELDS[$item]) && filled($context[$item] ?? null)) { $parts[] = $context[$item]; } } if ($parts !== []) { $properties[$mapping['field']] = implode($mapping['separator'] ?? ' – ', $parts); } } return $properties; } /** @return array */ public function context(Booking|BlockedPeriod $occupation): array { $booking = $occupation instanceof Booking; $start = $booking ? $occupation->arrival : $occupation->starts_on; $end = $booking ? $occupation->departure : $occupation->ends_on; $context = ['occupation_label' => $booking ? 'Buchung' : (ICalRuleEngine::TYPES[$occupation->ical_event_type] ?? 'Belegt'), 'property_name' => $occupation->property->name, 'arrival' => $start->format('d.m.Y'), 'departure' => $end->format('d.m.Y'), 'nights' => (string) (int) $start->diffInDays($end), 'channel_name' => $booking ? null : ($occupation->originChannel?->name ?? $occupation->channel?->name)]; if ($booking) { return [...$context, 'guest_first_name' => $occupation->guest?->first_name, 'guest_full_name' => $occupation->guest?->full_name, 'booking_reference' => $occupation->reference]; } $fields = array_intersect_key($occupation->ical_interpretation['fields'] ?? [], self::FIELDS); return [...$context, ...$fields]; } }