Files
2026-07-09 15:58:10 +02:00

170 lines
4.8 KiB
PHP

<?php
require_once __DIR__ . '/../src/Services/LogoService.php';
require_once __DIR__ . '/../src/Services/ProgrammeIndexBuilder.php';
require_once __DIR__ . '/../src/View/ProgrammeCard.php';
$tz = new DateTimeZone('Europe/Vienna');
$now = new DateTimeImmutable('now', $tz);
$upcoming = [];
$primetime = [];
$programmeIndex = [];
foreach ($programmes as $channelId => $items) {
$channel = $channels[$channelId] ?? null;
if (!$channel) {
continue;
}
foreach ($items as $p) {
$start = $p['start'];
if (!$start instanceof DateTimeInterface) {
continue;
}
if ($start >= $now && $start <= $now->modify('+30 minutes')) {
$id = ProgrammeIndexBuilder::id($channelId, $start, $p['title'] ?? '', $p['stop'] ?? null);
ProgrammeIndexBuilder::add($programmeIndex, $id, $channelId, $channel, $p);
$upcoming[] = [
'id' => $id,
'channel_id' => $channelId,
'channel' => $channel,
'programme' => $p,
];
}
if (
$start->format('Y-m-d') === $now->format('Y-m-d')
&& $start->format('H:i') >= '20:00'
&& $start->format('H:i') <= '23:00'
) {
$id = ProgrammeIndexBuilder::id($channelId, $start, $p['title'] ?? '', $p['stop'] ?? null);
ProgrammeIndexBuilder::add($programmeIndex, $id, $channelId, $channel, $p);
$primetime[] = [
'id' => $id,
'channel_id' => $channelId,
'channel' => $channel,
'programme' => $p,
];
}
}
}
foreach ($currentProgrammes as $item) {
$id = ProgrammeIndexBuilder::id(
$item['channel_id'],
$item['start'],
$item['title'] ?? '',
$item['stop'] ?? null
);
ProgrammeIndexBuilder::add($programmeIndex, $id, $item['channel_id'], [
'name' => $item['channel_name'],
'number' => $item['channel_number'],
'favorite' => $item['favorite'],
], $item);
}
usort($upcoming, fn($a, $b) => $a['programme']['start'] <=> $b['programme']['start']);
usort($primetime, fn($a, $b) => $a['programme']['start'] <=> $b['programme']['start']);
$favoritesNow = array_values(array_filter(
$currentProgrammes,
fn($item) => !empty($item['favorite'])
));
?>
<section class="dashboard-hero">
<div>
<h2>TVGuide</h2>
<p>Dein Überblick für jetzt, gleich und heute Abend.</p>
</div>
<a class="button-link" href="/?view=day">Tagesansicht öffnen</a>
</section>
<div class="dashboard-grid">
<section class="dashboard-panel">
<h3>🔥 Jetzt läuft</h3>
<div class="dashboard-card-grid" data-dashboard-now>
<?php foreach (array_slice($currentProgrammes, 0, 6) as $item): ?>
<?php
$id = ProgrammeIndexBuilder::id(
$item['channel_id'],
$item['start'],
$item['title'] ?? '',
$item['stop'] ?? null
);
?>
<?= ProgrammeCard::dashboardLive($item, $id) ?>
<?php endforeach; ?>
</div>
</section>
<section class="dashboard-panel">
<h3>⏰ Beginnt gleich</h3>
<div class="dashboard-card-grid">
<?php foreach (array_slice($upcoming, 0, 6) as $item): ?>
<?= ProgrammeCard::dashboardProgramme($item, $item['id']) ?>
<?php endforeach; ?>
</div>
<?php if (!$upcoming): ?>
<div class="empty compact">In den nächsten 30 Minuten beginnt keine Sendung.</div>
<?php endif; ?>
</section>
<section class="dashboard-panel">
<h3>⭐ Favoriten jetzt</h3>
<div class="dashboard-card-grid" data-dashboard-favorites>
<?php foreach (array_slice($favoritesNow, 0, 6) as $item): ?>
<?php
$id = ProgrammeIndexBuilder::id(
$item['channel_id'],
$item['start'],
$item['title'] ?? '',
$item['stop'] ?? null
);
?>
<?= ProgrammeCard::dashboardLive($item, $id) ?>
<?php endforeach; ?>
</div>
<?php if (!$favoritesNow): ?>
<div class="empty compact">Aktuell läuft auf deinen Favoriten nichts.</div>
<?php endif; ?>
</section>
<section class="dashboard-panel">
<h3>📺 Heute Abend</h3>
<div class="dashboard-card-grid">
<?php foreach (array_slice($primetime, 0, 8) as $item): ?>
<?= ProgrammeCard::dashboardProgramme($item, $item['id']) ?>
<?php endforeach; ?>
</div>
<?php if (!$primetime): ?>
<div class="empty compact">Für heute Abend wurden keine Sendungen gefunden.</div>
<?php endif; ?>
</section>
</div>
<script>
window.TVGUIDE_PROGRAMMES = <?= json_encode(
$programmeIndex,
JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES
) ?>;
</script>
<?php require __DIR__ . '/partials/programme-modal.php'; ?>