>}|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) ->flatMap(function ($item) { if (! is_array($item)) { return []; } $email = strtolower(trim((string) ($item['host_speaker_email'] ?? ''))); if ($email !== '' && filter_var($email, FILTER_VALIDATE_EMAIL)) { return [$email]; } $host = trim((string) ($item['host'] ?? '')); if ($host !== '' && filter_var($host, FILTER_VALIDATE_EMAIL)) { return [$host]; } if ($host !== '') { return [$host]; } return []; }) ->unique() ->values() ->all(); } /** @return list */ public function speakerOptionsForProgramme(QrCode $programme): array { $options = []; foreach ($this->eventsLinkedToProgramme($programme) as $event) { foreach ((array) ($event->content()['speakers'] ?? []) as $speaker) { if (! is_array($speaker)) { continue; } $email = trim((string) ($speaker['email'] ?? '')); $name = trim((string) ($speaker['name'] ?? '')); if ($email === '' || ! filter_var($email, FILTER_VALIDATE_EMAIL) || $name === '') { continue; } $options[strtolower($email)] = [ 'email' => $email, 'name' => $name, ]; } } return array_values($options); } /** @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); } }