Deploy Ladill Events / deploy (push) Successful in 41s
Programme sync to Meet rooms, wallet-billed mass comms, webhook lifecycle updates, and registration access bridge with join-window gating on public pages. Co-authored-by: Cursor <cursoragent@cursor.com>
75 lines
2.1 KiB
PHP
75 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Events;
|
|
|
|
use App\Models\QrCode;
|
|
use Illuminate\Support\Collection;
|
|
|
|
class EventProgrammeService
|
|
{
|
|
/** @return array{title: string, days: list<array<string, mixed>>}|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<string> $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<array<string, mixed>> $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<int, QrCode> */
|
|
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);
|
|
}
|
|
}
|