Consolidate 3

This commit is contained in:
Gogs
2026-07-09 15:58:10 +02:00
parent 9a892a8c5e
commit 265d7c1509
2 changed files with 107 additions and 37 deletions
+55
View File
@@ -0,0 +1,55 @@
<?php
class ProgrammeCard
{
public static function dashboardLive(array $item, string $id): string
{
$logoUrl = LogoService::getLogoUrl($item['channel_id']);
$percent = (int)($item['percent'] ?? 0);
return self::button(
$id,
$logoUrl,
$item['title'] ?? '',
($item['channel_name'] ?? '') . ' · noch ' . (int)($item['remaining_minutes'] ?? 0) . ' Min.',
$percent
);
}
public static function dashboardProgramme(array $item, string $id): string
{
$logoUrl = LogoService::getLogoUrl($item['channel_id']);
$programme = $item['programme'];
return self::button(
$id,
$logoUrl,
$programme['title'] ?? '',
$programme['start']->format('H:i') . ' · ' . ($item['channel']['name'] ?? '')
);
}
private static function button(
string $id,
string $logoUrl,
string $title,
string $meta,
?int $percent = null
): string {
ob_start();
?>
<button class="dashboard-programme-card dashboard-programme" type="button" data-programme-id="<?= htmlspecialchars($id) ?>">
<img src="<?= htmlspecialchars($logoUrl) ?>" alt="">
<strong><?= htmlspecialchars($title) ?></strong>
<span><?= htmlspecialchars($meta) ?></span>
<?php if ($percent !== null): ?>
<div class="dashboard-progress">
<div style="width: <?= $percent ?>%"></div>
</div>
<?php endif; ?>
</button>
<?php
return trim(ob_get_clean());
}
}
+52 -37
View File
@@ -1,21 +1,28 @@
<?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;
if (!$channel) {
continue;
}
foreach ($items as $p) {
$start = $p['start'];
if (!$start instanceof DateTimeInterface) continue;
if (!$start instanceof DateTimeInterface) {
continue;
}
if ($start >= $now && $start <= $now->modify('+30 minutes')) {
$id = ProgrammeIndexBuilder::id($channelId, $start, $p['title'] ?? '', $p['stop'] ?? null);
@@ -29,9 +36,11 @@ 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') <= '23:00') {
&& $start->format('H:i') <= '23:00'
) {
$id = ProgrammeIndexBuilder::id($channelId, $start, $p['title'] ?? '', $p['stop'] ?? null);
ProgrammeIndexBuilder::add($programmeIndex, $id, $channelId, $channel, $p);
@@ -46,7 +55,12 @@ foreach ($programmes as $channelId => $items) {
}
foreach ($currentProgrammes as $item) {
$id = ProgrammeIndexBuilder::id($item['channel_id'], $item['start'], $item['title'] ?? '', $item['stop'] ?? null);
$id = ProgrammeIndexBuilder::id(
$item['channel_id'],
$item['start'],
$item['title'] ?? '',
$item['stop'] ?? null
);
ProgrammeIndexBuilder::add($programmeIndex, $id, $item['channel_id'], [
'name' => $item['channel_name'],
@@ -58,7 +72,10 @@ foreach ($currentProgrammes as $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'])));
$favoritesNow = array_values(array_filter(
$currentProgrammes,
fn($item) => !empty($item['favorite'])
));
?>
<section class="dashboard-hero">
@@ -66,6 +83,7 @@ $favoritesNow = array_values(array_filter($currentProgrammes, fn($item) => !empt
<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>
@@ -75,15 +93,16 @@ $favoritesNow = array_values(array_filter($currentProgrammes, fn($item) => !empt
<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); ?>
<button class="dashboard-programme-card dashboard-programme" type="button" data-programme-id="<?= htmlspecialchars($id) ?>">
<img src="<?= htmlspecialchars(LogoService::getLogoUrl($item['channel_id'])) ?>" alt="">
<strong><?= htmlspecialchars($item['title']) ?></strong>
<span><?= htmlspecialchars($item['channel_name']) ?> · noch <?= (int)$item['remaining_minutes'] ?> Min.</span>
<div class="dashboard-progress">
<div style="width: <?= (int)$item['percent'] ?>%"></div>
</div>
</button>
<?php
$id = ProgrammeIndexBuilder::id(
$item['channel_id'],
$item['start'],
$item['title'] ?? '',
$item['stop'] ?? null
);
?>
<?= ProgrammeCard::dashboardLive($item, $id) ?>
<?php endforeach; ?>
</div>
</section>
@@ -93,11 +112,7 @@ $favoritesNow = array_values(array_filter($currentProgrammes, fn($item) => !empt
<div class="dashboard-card-grid">
<?php foreach (array_slice($upcoming, 0, 6) as $item): ?>
<button class="dashboard-programme-card dashboard-programme" type="button" data-programme-id="<?= htmlspecialchars($item['id']) ?>">
<img src="<?= htmlspecialchars(LogoService::getLogoUrl($item['channel_id'])) ?>" alt="">
<strong><?= htmlspecialchars($item['programme']['title']) ?></strong>
<span><?= $item['programme']['start']->format('H:i') ?> · <?= htmlspecialchars($item['channel']['name']) ?></span>
</button>
<?= ProgrammeCard::dashboardProgramme($item, $item['id']) ?>
<?php endforeach; ?>
</div>
@@ -109,17 +124,18 @@ $favoritesNow = array_values(array_filter($currentProgrammes, fn($item) => !empt
<section class="dashboard-panel">
<h3>⭐ Favoriten jetzt</h3>
<div class="dashboard-card-grid">
<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); ?>
<button class="dashboard-programme-card dashboard-programme" type="button" data-programme-id="<?= htmlspecialchars($id) ?>">
<img src="<?= htmlspecialchars(LogoService::getLogoUrl($item['channel_id'])) ?>" alt="">
<strong><?= htmlspecialchars($item['title']) ?></strong>
<span><?= htmlspecialchars($item['channel_name']) ?> · <?= (int)$item['percent'] ?>%</span>
<div class="dashboard-progress">
<div style="width: <?= (int)$item['percent'] ?>%"></div>
</div>
</button>
<?php
$id = ProgrammeIndexBuilder::id(
$item['channel_id'],
$item['start'],
$item['title'] ?? '',
$item['stop'] ?? null
);
?>
<?= ProgrammeCard::dashboardLive($item, $id) ?>
<?php endforeach; ?>
</div>
@@ -133,11 +149,7 @@ $favoritesNow = array_values(array_filter($currentProgrammes, fn($item) => !empt
<div class="dashboard-card-grid">
<?php foreach (array_slice($primetime, 0, 8) as $item): ?>
<button class="dashboard-programme-card dashboard-programme" type="button" data-programme-id="<?= htmlspecialchars($item['id']) ?>">
<img src="<?= htmlspecialchars(LogoService::getLogoUrl($item['channel_id'])) ?>" alt="">
<strong><?= htmlspecialchars($item['programme']['title']) ?></strong>
<span><?= $item['programme']['start']->format('H:i') ?> · <?= htmlspecialchars($item['channel']['name']) ?></span>
</button>
<?= ProgrammeCard::dashboardProgramme($item, $item['id']) ?>
<?php endforeach; ?>
</div>
@@ -148,7 +160,10 @@ $favoritesNow = array_values(array_filter($currentProgrammes, fn($item) => !empt
</div>
<script>
window.TVGUIDE_PROGRAMMES = <?= json_encode($programmeIndex, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) ?>;
window.TVGUIDE_PROGRAMMES = <?= json_encode(
$programmeIndex,
JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES
) ?>;
</script>
<?php require __DIR__ . '/partials/programme-modal.php'; ?>