feat: extend event toolkit and polish guest pwa
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Support;
|
||||
|
||||
use App\Models\InviteLayout;
|
||||
|
||||
class JoinTokenLayoutRegistry
|
||||
{
|
||||
/**
|
||||
@@ -123,6 +125,18 @@ class JoinTokenLayoutRegistry
|
||||
*/
|
||||
public static function all(): array
|
||||
{
|
||||
$customLayouts = InviteLayout::query()
|
||||
->where('is_active', true)
|
||||
->orderBy('name')
|
||||
->get();
|
||||
|
||||
if ($customLayouts->isNotEmpty()) {
|
||||
return $customLayouts
|
||||
->map(fn (InviteLayout $layout) => self::normalize(self::fromModel($layout)))
|
||||
->values()
|
||||
->all();
|
||||
}
|
||||
|
||||
return array_values(array_map(fn ($layout) => self::normalize($layout), self::LAYOUTS));
|
||||
}
|
||||
|
||||
@@ -131,6 +145,15 @@ class JoinTokenLayoutRegistry
|
||||
*/
|
||||
public static function find(string $id): ?array
|
||||
{
|
||||
$custom = InviteLayout::query()
|
||||
->where('slug', $id)
|
||||
->where('is_active', true)
|
||||
->first();
|
||||
|
||||
if ($custom) {
|
||||
return self::normalize(self::fromModel($custom));
|
||||
}
|
||||
|
||||
$layout = self::LAYOUTS[$id] ?? null;
|
||||
|
||||
return $layout ? self::normalize($layout) : null;
|
||||
@@ -151,6 +174,13 @@ class JoinTokenLayoutRegistry
|
||||
'accent' => '#6366F1',
|
||||
'secondary' => '#CBD5F5',
|
||||
'badge' => '#2563EB',
|
||||
'badge_label' => 'Digitale Gästebox',
|
||||
'instructions_heading' => "So funktioniert's",
|
||||
'link_heading' => 'Alternative zum Einscannen',
|
||||
'cta_label' => 'Scan mich & starte direkt',
|
||||
'cta_caption' => 'Scan mich & starte direkt',
|
||||
'link_label' => null,
|
||||
'logo_url' => null,
|
||||
'qr' => [
|
||||
'size_px' => 320,
|
||||
],
|
||||
@@ -160,11 +190,50 @@ class JoinTokenLayoutRegistry
|
||||
],
|
||||
'background_gradient' => null,
|
||||
'instructions' => [],
|
||||
'formats' => ['pdf', 'svg'],
|
||||
];
|
||||
|
||||
return array_replace_recursive($defaults, $layout);
|
||||
}
|
||||
|
||||
private static function fromModel(InviteLayout $layout): array
|
||||
{
|
||||
$preview = $layout->preview ?? [];
|
||||
$options = $layout->layout_options ?? [];
|
||||
$instructions = $layout->instructions ?? [];
|
||||
|
||||
return array_filter([
|
||||
'id' => $layout->slug,
|
||||
'name' => $layout->name,
|
||||
'subtitle' => $layout->subtitle,
|
||||
'description' => $layout->description,
|
||||
'paper' => $layout->paper,
|
||||
'orientation' => $layout->orientation,
|
||||
'background' => $preview['background'] ?? null,
|
||||
'background_gradient' => $preview['background_gradient'] ?? null,
|
||||
'text' => $preview['text'] ?? null,
|
||||
'accent' => $preview['accent'] ?? null,
|
||||
'secondary' => $preview['secondary'] ?? null,
|
||||
'badge' => $preview['badge'] ?? null,
|
||||
'badge_label' => $options['badge_label'] ?? null,
|
||||
'instructions_heading' => $options['instructions_heading'] ?? null,
|
||||
'link_heading' => $options['link_heading'] ?? null,
|
||||
'cta_label' => $options['cta_label'] ?? null,
|
||||
'cta_caption' => $options['cta_caption'] ?? null,
|
||||
'link_label' => $options['link_label'] ?? null,
|
||||
'logo_url' => $options['logo_url'] ?? null,
|
||||
'qr' => array_filter([
|
||||
'size_px' => $preview['qr']['size_px'] ?? $options['qr']['size_px'] ?? $preview['qr_size_px'] ?? $options['qr_size_px'] ?? null,
|
||||
]),
|
||||
'svg' => array_filter([
|
||||
'width' => $preview['svg']['width'] ?? $options['svg']['width'] ?? $preview['svg_width'] ?? $options['svg_width'] ?? null,
|
||||
'height' => $preview['svg']['height'] ?? $options['svg']['height'] ?? $preview['svg_height'] ?? $options['svg_height'] ?? null,
|
||||
]),
|
||||
'formats' => $options['formats'] ?? ['pdf', 'svg'],
|
||||
'instructions' => $instructions,
|
||||
], fn ($value) => $value !== null && $value !== []);
|
||||
}
|
||||
|
||||
/**
|
||||
* Map layouts into an API-ready response structure, attaching URLs.
|
||||
*
|
||||
@@ -174,7 +243,7 @@ class JoinTokenLayoutRegistry
|
||||
public static function toResponse(callable $urlResolver): array
|
||||
{
|
||||
return array_map(function (array $layout) use ($urlResolver) {
|
||||
$formats = ['pdf', 'svg'];
|
||||
$formats = $layout['formats'] ?? ['pdf', 'svg'];
|
||||
|
||||
return [
|
||||
'id' => $layout['id'],
|
||||
@@ -194,4 +263,4 @@ class JoinTokenLayoutRegistry
|
||||
];
|
||||
}, self::all());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user