Consolidation 2
This commit is contained in:
@@ -0,0 +1,53 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class ProgrammeIndexBuilder
|
||||||
|
{
|
||||||
|
public static function id(string $channelId, mixed $start, string $title, mixed $stop = null): string
|
||||||
|
{
|
||||||
|
$startKey = $start instanceof DateTimeInterface ? $start->getTimestamp() : (string)$start;
|
||||||
|
$stopKey = $stop instanceof DateTimeInterface ? $stop->getTimestamp() : (string)$stop;
|
||||||
|
|
||||||
|
return md5($channelId . '|' . $startKey . '|' . $stopKey . '|' . $title);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function add(
|
||||||
|
array &$index,
|
||||||
|
string $id,
|
||||||
|
string $channelId,
|
||||||
|
array $channel,
|
||||||
|
array $programme
|
||||||
|
): void {
|
||||||
|
$metadata = $programme['metadata'] ?? [];
|
||||||
|
|
||||||
|
$index[$id] = [
|
||||||
|
'id' => $id,
|
||||||
|
'channel_id' => $channelId,
|
||||||
|
'channel' => $channel['name'] ?? $channel['channel_name'] ?? $channelId,
|
||||||
|
'channel_number' => $channel['number'] ?? $channel['channel_number'] ?? 999999,
|
||||||
|
'favorite' => $channel['favorite'] ?? false,
|
||||||
|
'title' => $programme['title'] ?? '',
|
||||||
|
'subtitle' => $programme['subtitle'] ?? '',
|
||||||
|
'description' => $programme['desc'] ?? $programme['description'] ?? '',
|
||||||
|
'category' => $programme['category'] ?? '',
|
||||||
|
'metadata' => $metadata,
|
||||||
|
'year' => $programme['year'] ?? $metadata['year'] ?? '',
|
||||||
|
'rating' => $programme['rating'] ?? $metadata['age_rating'] ?? '',
|
||||||
|
'country' => $programme['country'] ?? $metadata['country'] ?? '',
|
||||||
|
'start' => self::formatTime($programme['start'] ?? null),
|
||||||
|
'stop' => self::formatTime($programme['stop'] ?? null),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function formatTime(mixed $value): string
|
||||||
|
{
|
||||||
|
if ($value instanceof DateTimeInterface) {
|
||||||
|
return $value->format('H:i');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_numeric($value)) {
|
||||||
|
return date('H:i', (int)$value);
|
||||||
|
}
|
||||||
|
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
}
|
||||||
+13
-50
@@ -1,5 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
require_once __DIR__ . '/../src/Services/LogoService.php';
|
require_once __DIR__ . '/../src/Services/LogoService.php';
|
||||||
|
require_once __DIR__ . '/../src/Services/ProgrammeIndexBuilder.php';
|
||||||
|
|
||||||
$tz = new DateTimeZone('Europe/Vienna');
|
$tz = new DateTimeZone('Europe/Vienna');
|
||||||
$now = new DateTimeImmutable('now', $tz);
|
$now = new DateTimeImmutable('now', $tz);
|
||||||
@@ -7,32 +8,6 @@ $upcoming = [];
|
|||||||
$primetime = [];
|
$primetime = [];
|
||||||
$programmeIndex = [];
|
$programmeIndex = [];
|
||||||
|
|
||||||
function dashboardProgrammeId(string $channelId, mixed $start, mixed $title): string {
|
|
||||||
$startKey = $start instanceof DateTimeInterface ? $start->getTimestamp() : (string)$start;
|
|
||||||
return md5($channelId . '|' . $startKey . '|' . $title);
|
|
||||||
}
|
|
||||||
|
|
||||||
function dashboardAddProgrammeIndex(array &$programmeIndex, string $id, string $channelId, array $channel, array $p): void {
|
|
||||||
$metadata = $p['metadata'] ?? [];
|
|
||||||
|
|
||||||
$programmeIndex[$id] = [
|
|
||||||
'id' => $id,
|
|
||||||
'channel_id' => $channelId,
|
|
||||||
'channel' => $channel['name'] ?? $channelId,
|
|
||||||
'channel_number' => $channel['number'] ?? 999999,
|
|
||||||
'favorite' => $channel['favorite'] ?? false,
|
|
||||||
'title' => $p['title'] ?? '',
|
|
||||||
'subtitle' => $p['subtitle'] ?? '',
|
|
||||||
'description' => $p['desc'] ?? $p['description'] ?? '',
|
|
||||||
'category' => $p['category'] ?? '',
|
|
||||||
'metadata' => $metadata,
|
|
||||||
'year' => $metadata['year'] ?? '',
|
|
||||||
'rating' => $metadata['age_rating'] ?? '',
|
|
||||||
'country' => $metadata['country'] ?? '',
|
|
||||||
'start' => $p['start'] instanceof DateTimeInterface ? $p['start']->format('H:i') : date('H:i', (int)($p['start'] ?? 0)),
|
|
||||||
'stop' => $p['stop'] instanceof DateTimeInterface ? $p['stop']->format('H:i') : date('H:i', (int)($p['stop'] ?? 0)),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($programmes as $channelId => $items) {
|
foreach ($programmes as $channelId => $items) {
|
||||||
$channel = $channels[$channelId] ?? null;
|
$channel = $channels[$channelId] ?? null;
|
||||||
@@ -43,8 +18,8 @@ foreach ($programmes as $channelId => $items) {
|
|||||||
if (!$start instanceof DateTimeInterface) continue;
|
if (!$start instanceof DateTimeInterface) continue;
|
||||||
|
|
||||||
if ($start >= $now && $start <= $now->modify('+30 minutes')) {
|
if ($start >= $now && $start <= $now->modify('+30 minutes')) {
|
||||||
$id = dashboardProgrammeId($channelId, $start, $p['title'] ?? '');
|
$id = ProgrammeIndexBuilder::id($channelId, $start, $p['title'] ?? '', $p['stop'] ?? null);
|
||||||
dashboardAddProgrammeIndex($programmeIndex, $id, $channelId, $channel, $p);
|
ProgrammeIndexBuilder::add($programmeIndex, $id, $channelId, $channel, $p);
|
||||||
|
|
||||||
$upcoming[] = [
|
$upcoming[] = [
|
||||||
'id' => $id,
|
'id' => $id,
|
||||||
@@ -57,8 +32,8 @@ foreach ($programmes as $channelId => $items) {
|
|||||||
if ($start->format('Y-m-d') === $now->format('Y-m-d')
|
if ($start->format('Y-m-d') === $now->format('Y-m-d')
|
||||||
&& $start->format('H:i') >= '20:00'
|
&& $start->format('H:i') >= '20:00'
|
||||||
&& $start->format('H:i') <= '23:00') {
|
&& $start->format('H:i') <= '23:00') {
|
||||||
$id = dashboardProgrammeId($channelId, $start, $p['title'] ?? '');
|
$id = ProgrammeIndexBuilder::id($channelId, $start, $p['title'] ?? '', $p['stop'] ?? null);
|
||||||
dashboardAddProgrammeIndex($programmeIndex, $id, $channelId, $channel, $p);
|
ProgrammeIndexBuilder::add($programmeIndex, $id, $channelId, $channel, $p);
|
||||||
|
|
||||||
$primetime[] = [
|
$primetime[] = [
|
||||||
'id' => $id,
|
'id' => $id,
|
||||||
@@ -71,25 +46,13 @@ foreach ($programmes as $channelId => $items) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach ($currentProgrammes as $item) {
|
foreach ($currentProgrammes as $item) {
|
||||||
$id = dashboardProgrammeId($item['channel_id'], $item['start'], $item['title'] ?? '');
|
$id = ProgrammeIndexBuilder::id($item['channel_id'], $item['start'], $item['title'] ?? '', $item['stop'] ?? null);
|
||||||
|
|
||||||
$programmeIndex[$id] = [
|
ProgrammeIndexBuilder::add($programmeIndex, $id, $item['channel_id'], [
|
||||||
'id' => $id,
|
'name' => $item['channel_name'],
|
||||||
'channel_id' => $item['channel_id'],
|
'number' => $item['channel_number'],
|
||||||
'channel' => $item['channel_name'],
|
|
||||||
'channel_number' => $item['channel_number'],
|
|
||||||
'favorite' => $item['favorite'],
|
'favorite' => $item['favorite'],
|
||||||
'title' => $item['title'],
|
], $item);
|
||||||
'subtitle' => $item['subtitle'],
|
|
||||||
'description' => $item['description'],
|
|
||||||
'category' => $item['category'],
|
|
||||||
'metadata' => $item['metadata'] ?? [],
|
|
||||||
'year' => $item['year'] ?? '',
|
|
||||||
'rating' => $item['rating'] ?? '',
|
|
||||||
'country' => $item['country'] ?? '',
|
|
||||||
'start' => date('H:i', $item['start']),
|
|
||||||
'stop' => date('H:i', $item['stop']),
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
usort($upcoming, fn($a, $b) => $a['programme']['start'] <=> $b['programme']['start']);
|
usort($upcoming, fn($a, $b) => $a['programme']['start'] <=> $b['programme']['start']);
|
||||||
@@ -112,7 +75,7 @@ $favoritesNow = array_values(array_filter($currentProgrammes, fn($item) => !empt
|
|||||||
|
|
||||||
<div class="dashboard-card-grid" data-dashboard-now>
|
<div class="dashboard-card-grid" data-dashboard-now>
|
||||||
<?php foreach (array_slice($currentProgrammes, 0, 6) as $item): ?>
|
<?php foreach (array_slice($currentProgrammes, 0, 6) as $item): ?>
|
||||||
<?php $id = dashboardProgrammeId($item['channel_id'], $item['start'], $item['title'] ?? ''); ?>
|
<?php $id = ProgrammeIndexBuilder::id($item['channel_id'], $item['start'], $item['title'] ?? '', $item['stop'] ?? null); ?>
|
||||||
<button class="dashboard-programme-card dashboard-programme" type="button" data-programme-id="<?= htmlspecialchars($id) ?>">
|
<button class="dashboard-programme-card dashboard-programme" type="button" data-programme-id="<?= htmlspecialchars($id) ?>">
|
||||||
<img src="<?= htmlspecialchars(LogoService::getLogoUrl($item['channel_id'])) ?>" alt="">
|
<img src="<?= htmlspecialchars(LogoService::getLogoUrl($item['channel_id'])) ?>" alt="">
|
||||||
<strong><?= htmlspecialchars($item['title']) ?></strong>
|
<strong><?= htmlspecialchars($item['title']) ?></strong>
|
||||||
@@ -128,7 +91,7 @@ $favoritesNow = array_values(array_filter($currentProgrammes, fn($item) => !empt
|
|||||||
<section class="dashboard-panel">
|
<section class="dashboard-panel">
|
||||||
<h3>⏰ Beginnt gleich</h3>
|
<h3>⏰ Beginnt gleich</h3>
|
||||||
|
|
||||||
<div class="dashboard-card-grid" data-dashboard-favorites>
|
<div class="dashboard-card-grid">
|
||||||
<?php foreach (array_slice($upcoming, 0, 6) as $item): ?>
|
<?php foreach (array_slice($upcoming, 0, 6) as $item): ?>
|
||||||
<button class="dashboard-programme-card dashboard-programme" type="button" data-programme-id="<?= htmlspecialchars($item['id']) ?>">
|
<button class="dashboard-programme-card dashboard-programme" type="button" data-programme-id="<?= htmlspecialchars($item['id']) ?>">
|
||||||
<img src="<?= htmlspecialchars(LogoService::getLogoUrl($item['channel_id'])) ?>" alt="">
|
<img src="<?= htmlspecialchars(LogoService::getLogoUrl($item['channel_id'])) ?>" alt="">
|
||||||
@@ -148,7 +111,7 @@ $favoritesNow = array_values(array_filter($currentProgrammes, fn($item) => !empt
|
|||||||
|
|
||||||
<div class="dashboard-card-grid">
|
<div class="dashboard-card-grid">
|
||||||
<?php foreach (array_slice($favoritesNow, 0, 6) as $item): ?>
|
<?php foreach (array_slice($favoritesNow, 0, 6) as $item): ?>
|
||||||
<?php $id = dashboardProgrammeId($item['channel_id'], $item['start'], $item['title'] ?? ''); ?>
|
<?php $id = ProgrammeIndexBuilder::id($item['channel_id'], $item['start'], $item['title'] ?? '', $item['stop'] ?? null); ?>
|
||||||
<button class="dashboard-programme-card dashboard-programme" type="button" data-programme-id="<?= htmlspecialchars($id) ?>">
|
<button class="dashboard-programme-card dashboard-programme" type="button" data-programme-id="<?= htmlspecialchars($id) ?>">
|
||||||
<img src="<?= htmlspecialchars(LogoService::getLogoUrl($item['channel_id'])) ?>" alt="">
|
<img src="<?= htmlspecialchars(LogoService::getLogoUrl($item['channel_id'])) ?>" alt="">
|
||||||
<strong><?= htmlspecialchars($item['title']) ?></strong>
|
<strong><?= htmlspecialchars($item['title']) ?></strong>
|
||||||
|
|||||||
Reference in New Issue
Block a user