'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 { // Own use, private stays and blocks (A6) are exported exactly like the manual blocks they replace: no reference; // a guest's name only where the channel exports names at all. if ($occupation instanceof Booking && $occupation->isInternal()) { $guest = $occupation->guest?->anonymized_at === null ? $occupation->guest : null; return ['occupation_label' => 'Belegt', 'property_name' => $occupation->property->name, 'arrival' => $occupation->arrival->format('d.m.Y'), 'departure' => $occupation->departure->format('d.m.Y'), 'nights' => (string) (int) $occupation->arrival->diffInDays($occupation->departure), 'channel_name' => null, ...($guest !== null ? ['guest_first_name' => $guest->first_name, 'guest_full_name' => filled($guest->last_name) ? $guest->full_name : null] : [])]; } $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); if ($occupation->guest !== null) { $fields['guest_first_name'] = $occupation->guest->anonymized_at === null ? $occupation->guest->first_name : null; $fields['guest_full_name'] = $occupation->guest->anonymized_at === null && filled($occupation->guest->last_name) ? $occupation->guest->full_name : null; } return [...$context, ...$fields]; } }