, settings: list}> */ public const BLOCKS = [ 'intake' => ['label' => 'Eingang und Gastdaten', 'phase' => 'P01', 'area' => null, 'modules' => ['intake.record', 'guest.details', 'guest.data_request', 'guest.address_check', 'guest.loyalty_status', 'pricing.loyalty_discount'], 'settings' => [ProcessSetting::FormRequiresAddress, ProcessSetting::DataRequest, ProcessSetting::DataRequestReminderHours]], 'availability' => ['label' => 'Verfügbarkeit und Reservierung', 'phase' => 'P01', 'area' => null, 'modules' => ['availability.check', 'hold', 'binding.portal', 'channels.block'], 'settings' => [ProcessSetting::PreReservation, ProcessSetting::HoldHours, ProcessSetting::ClarificationHoldAutoMinutes]], 'answer' => ['label' => 'Antwort und Angebot', 'phase' => 'P02', 'area' => TemplateArea::InquiryAnswer, 'modules' => ['offer.information', 'offer.binding', 'offer.acceptance'], 'settings' => [ProcessSetting::InquiryAnswer, ProcessSetting::Processing, ProcessSetting::GuestLinkValidDays]], 'portal_wait' => ['label' => 'Bestätigung des Portals', 'phase' => 'P02', 'area' => null, 'modules' => ['portal.confirmation'], 'settings' => [ProcessSetting::AwaitPortalConfirmation, ProcessSetting::PortalConfirmationWaitHours]], 'documents' => ['label' => 'Dokumentation', 'phase' => 'P03', 'area' => TemplateArea::ContractDocuments, 'modules' => ['documents.send', 'documents.booking_notice', 'documents.stay_confirmation'], 'settings' => [ProcessSetting::Documents, ProcessSetting::ContractDelivery, ProcessSetting::BookingNotice, ProcessSetting::ContractTemplate]], 'finance' => ['label' => 'Finanzabwicklung', 'phase' => 'P03', 'area' => TemplateArea::Collection, 'modules' => ['payments.monitor', 'payments.internal', 'portal.payout'], 'settings' => [ProcessSetting::Payments]], 'communication' => ['label' => 'Gastkommunikation und Aufenthalt', 'phase' => 'P04', 'area' => TemplateArea::GuestCommunication, 'modules' => ['arrival.details', 'arrival.info', 'stay', 'review.request'], 'settings' => [ProcessSetting::GuestMessages, ProcessSetting::ArrivalInfoSender, ProcessSetting::ArrivalInfoDaysBefore, ProcessSetting::ReviewRequestSender]], 'closure' => ['label' => 'Aufgaben und Abschluss', 'phase' => 'P05', 'area' => null, 'modules' => ['case.tasks', 'change.proposal', 'case.closure', 'case.settlement'], 'settings' => []], ]; public const OTHER = 'other'; public function __construct(private ProcessCatalogue $catalogue) {} /** * The blocks of the course the preview rows describe. A block without a step in the plan is left out. * * @param list $rows ChannelProcessConfiguration::preview * @return array, modules: list, active: bool, waits_for: list}>, after: list, independent: bool, events: list, scheduled: list, conditional: list, may_wait: list}> */ public function of(array $rows): array { $blockOf = []; foreach (self::BLOCKS as $key => $block) { foreach ($block['modules'] as $module) { $blockOf[$module] = $key; } } $other = ['label' => 'Weitere Schritte', 'phase' => 'P03', 'area' => null, 'modules' => [], 'settings' => []]; $blocks = []; foreach ($rows as $row) { $key = $blockOf[$row['module']] ?? self::OTHER; $blocks[$key] ??= [...(self::BLOCKS[$key] ?? $other), 'key' => $key, 'modules' => []]; $blocks[$key]['modules'][] = $row; } // Presentation order is the table's, the plan decides which blocks exist. $blocks = array_merge(array_intersect_key(array_flip([...array_keys(self::BLOCKS), self::OTHER]), $blocks), $blocks); $active = []; foreach ($rows as $row) { if ($row['on']) { $active[$row['module']] = $row; } } foreach ($blocks as $key => &$block) { $block['active'] = collect($block['modules'])->contains('on', true); $block = [...$block, 'waits_for' => [], 'after' => [], 'events' => [], 'scheduled' => [], 'conditional' => [], 'may_wait' => []]; foreach ($block['modules'] as $row) { $definition = $this->catalogue->modules()[$row['module']]::definition(); if (! $row['on']) { continue; } foreach ($definition->requires as $dependency) { $targetBlock = $blockOf[$dependency->module] ?? self::OTHER; if ($dependency->module === 'intake.record' || ! isset($active[$dependency->module]) || $targetBlock === $key) { continue; } $list = $dependency->hard ? 'waits_for' : 'after'; $label = $blocks[$targetBlock]['label'] ?? self::BLOCKS[$targetBlock]['label'] ?? $other['label']; $entry = $block[$list][$targetBlock] ?? ['block' => $targetBlock, 'label' => $label, 'steps' => []]; $entry['steps'][] = $active[$dependency->module]['label']; $block[$list][$targetBlock] = $entry; } if ($definition->toggle === ModuleDefinition::TOGGLE_EVENT_DRIVEN) { $block['events'][] = $row['label']; } elseif ($definition->triggers !== [] && collect($definition->triggers)->every(fn (string $trigger): bool => str_starts_with($trigger, 'schedule:'))) { $block['scheduled'][] = $row['label']; } if ($definition->toggle === ModuleDefinition::TOGGLE_CONDITIONAL) { $block['conditional'][] = ['label' => $row['label'], 'reason' => $definition->condition]; } foreach ($definition->waits as $wait) { $block['may_wait'][] = ['guest' => 'den Gast', 'portal' => 'das Portal', 'landlord' => 'Sie', 'time' => 'eine Frist'][$wait] ?? $wait; } } $block['waits_for'] = array_values($block['waits_for']); $block['after'] = array_values($block['after']); $block['may_wait'] = array_values(array_unique($block['may_wait'])); $block['independent'] = $block['active'] && $block['waits_for'] === []; } unset($block); return $blocks; } }