151 lines
5 KiB
PHP
151 lines
5 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Display;
|
|
use Illuminate\Http\JsonResponse;
|
|
|
|
class DisplayVersionApiController extends Controller
|
|
{
|
|
public function config(Display $display): JsonResponse
|
|
{
|
|
if (! $display->is_active) {
|
|
return response()->json(['error' => 'Display not configured'], 404);
|
|
}
|
|
|
|
$display->load('versions');
|
|
|
|
if ($display->versions->isEmpty()) {
|
|
return response()->json(['error' => 'Display not configured'], 404);
|
|
}
|
|
|
|
$playlist = [];
|
|
|
|
foreach ($display->versions as $version) {
|
|
$items = $version->activeItems()->get();
|
|
|
|
$entry = match ($version->type->value) {
|
|
'video-display' => $this->videoDisplayData($version, $items),
|
|
'b2in' => $this->b2inData($version, $items),
|
|
'offers' => $this->offersData($version, $items),
|
|
default => null,
|
|
};
|
|
|
|
if ($entry) {
|
|
$playlist[] = $entry;
|
|
}
|
|
}
|
|
|
|
return response()->json([
|
|
'playlist' => $playlist,
|
|
'updated_at' => $display->versions->max('updated_at')?->toIso8601String(),
|
|
]);
|
|
}
|
|
|
|
public function check(Display $display): JsonResponse
|
|
{
|
|
if (! $display->is_active) {
|
|
return response()->json(['error' => 'Display not configured'], 404);
|
|
}
|
|
|
|
$display->load('versions');
|
|
|
|
if ($display->versions->isEmpty()) {
|
|
return response()->json(['error' => 'Display not configured'], 404);
|
|
}
|
|
|
|
return response()->json([
|
|
'updated_at' => $display->versions->max('updated_at')?->toIso8601String(),
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
private function videoDisplayData($version, $items): array
|
|
{
|
|
$videos = $items->where('item_type', 'video')->values()->map(fn ($item) => [
|
|
'src' => 'assets/'.($item->content['filename'] ?? ''),
|
|
'position' => $item->content['position'] ?? 25,
|
|
]);
|
|
|
|
$footerContent = $items->where('item_type', 'footer')->values()->map(function ($item) {
|
|
$data = [
|
|
'headline' => $item->content['headline'] ?? '',
|
|
'subline' => $item->content['subline'] ?? '',
|
|
];
|
|
|
|
if (! empty($item->content['url'])) {
|
|
$data['url'] = $item->content['url'];
|
|
}
|
|
|
|
return $data;
|
|
});
|
|
|
|
return [
|
|
'type' => 'video-display',
|
|
'version_name' => $version->name,
|
|
'videoPlaylist' => $videos,
|
|
'footerContent' => $footerContent,
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
private function b2inData($version, $items): array
|
|
{
|
|
$mediaItems = $items->where('item_type', 'media')->values()->map(fn ($item) => [
|
|
'id' => $item->id,
|
|
'category' => $item->content['category'] ?? 'immobilien',
|
|
'media_type' => $item->content['media_type'] ?? 'image',
|
|
'media_url' => $item->content['media_url'] ?? '',
|
|
'headline' => $item->content['headline'] ?? '',
|
|
'subline' => $item->content['subline'] ?? '',
|
|
'duration_seconds' => $item->content['duration_seconds'] ?? 10,
|
|
'sort_order' => $item->sort_order,
|
|
'is_active' => true,
|
|
]);
|
|
|
|
return [
|
|
'type' => 'b2in',
|
|
'version_name' => $version->name,
|
|
'settings' => $version->settings ?? [],
|
|
'items' => $mediaItems,
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
private function offersData($version, $items): array
|
|
{
|
|
$slides = $items->where('item_type', 'slide')->values()->map(fn ($item) => [
|
|
'type' => $item->content['type'] ?? 'product-hero',
|
|
'duration' => $item->content['duration'] ?? 8000,
|
|
'image_url' => $item->content['image_url'] ?? '',
|
|
'badge_text' => $item->content['badge_text'] ?? '',
|
|
'eyebrow' => $item->content['eyebrow'] ?? '',
|
|
'title' => $item->content['title'] ?? '',
|
|
'subline' => $item->content['subline'] ?? '',
|
|
'price' => $item->content['price'] ?? '',
|
|
'original_price' => $item->content['original_price'] ?? '',
|
|
'tag_text' => $item->content['tag_text'] ?? '',
|
|
'bullets' => $item->content['bullets'] ?? [],
|
|
'disclaimer' => $item->content['disclaimer'] ?? '',
|
|
'qr_url' => $item->content['qr_url'] ?? '',
|
|
'qr_title' => $item->content['qr_title'] ?? '',
|
|
'contact' => $item->content['contact'] ?? '',
|
|
'show_brand_text' => $item->content['show_brand_text'] ?? false,
|
|
'brand_tagline' => $item->content['brand_tagline'] ?? '',
|
|
]);
|
|
|
|
return [
|
|
'type' => 'offers',
|
|
'version_name' => $version->name,
|
|
'settings' => $version->settings ?? [],
|
|
'slides' => $slides,
|
|
];
|
|
}
|
|
}
|