>}|null */ public function snapshot(?QrCode $programme): ?array { if (! $programme || $programme->type !== QrCode::TYPE_ITINERARY) { return null; } $content = $programme->content(); return [ 'title' => (string) ($content['title'] ?? $programme->label), 'subtitle' => (string) ($content['subtitle'] ?? ''), 'location' => (string) ($content['location'] ?? ''), 'days' => array_values((array) ($content['days'] ?? [])), ]; } /** @param list $itemRefs */ public function itemsForRefs(?array $snapshot, array $itemRefs): array { if (! $snapshot) { return []; } $refs = array_flip($itemRefs); $matched = []; foreach ((array) ($snapshot['days'] ?? []) as $day) { foreach ((array) ($day['items'] ?? []) as $item) { $ref = (string) ($item['ref'] ?? ''); if ($ref !== '' && isset($refs[$ref])) { $matched[] = $item; } } } return $matched; } /** @param list> $items */ public function hostsFromItems(array $items): array { return collect($items) ->pluck('host') ->filter(fn ($host) => is_string($host) && trim($host) !== '') ->map(fn ($host) => trim($host)) ->unique() ->values() ->all(); } /** @return Collection */ public function eventsLinkedToProgramme(QrCode $programme): Collection { if ($programme->type !== QrCode::TYPE_ITINERARY) { return collect(); } return QrCode::query() ->where('user_id', $programme->user_id) ->where('type', QrCode::TYPE_EVENT) ->get() ->filter(fn (QrCode $event) => (int) ($event->content()['programme_qr_id'] ?? 0) === $programme->id); } }