Favorites
This commit is contained in:
@@ -17,7 +17,7 @@
|
||||
"country": "",
|
||||
"language": "",
|
||||
"enabled": true,
|
||||
"favorite": false,
|
||||
"favorite": true,
|
||||
"number": 2,
|
||||
"group": "Unknown"
|
||||
}
|
||||
|
||||
+7
-81
@@ -1,11 +1,14 @@
|
||||
<?php
|
||||
|
||||
require_once '/var/www/src/Config.php';
|
||||
require_once '/var/www/src/XmlTv.php';
|
||||
require_once '/var/www/src/View.php';
|
||||
|
||||
require_once '/var/www/src/Services/ChannelService.php';
|
||||
require_once '/var/www/src/Services/XmlTvCacheService.php';
|
||||
require_once '/var/www/src/Services/ProgrammeService.php';
|
||||
require_once '/var/www/src/View.php';
|
||||
|
||||
require_once '/var/www/src/XmlTv.php';
|
||||
require_once '/var/www/src/Controllers/HomeController.php';
|
||||
|
||||
$config = new Config(
|
||||
'/var/www/config/config.json',
|
||||
@@ -17,82 +20,5 @@ $xmltv = new XmlTv(
|
||||
$config->get('timezone', 'Europe/Vienna')
|
||||
);
|
||||
|
||||
$xmltv->synchronizeChannels($config);
|
||||
|
||||
$view = $_GET['view'] ?? $config->get('default_view', 'today');
|
||||
|
||||
if ($view === 'channels' && $_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$savedChannels = $config->getChannels();
|
||||
|
||||
foreach ($savedChannels as $id => &$channel) {
|
||||
$channel['enabled'] = isset($_POST['enabled'][$id]);
|
||||
$channel['favorite'] = isset($_POST['favorite'][$id]);
|
||||
$channel['number'] = (int)($_POST['number'][$id] ?? $channel['number'] ?? 999999);
|
||||
$channel['group'] = trim($_POST['group'][$id] ?? $channel['group'] ?? 'Unknown');
|
||||
}
|
||||
|
||||
unset($channel);
|
||||
|
||||
uasort($savedChannels, function ($a, $b) {
|
||||
return ((int)($a['number'] ?? 999999)) <=> ((int)($b['number'] ?? 999999));
|
||||
});
|
||||
|
||||
$config->saveChannels($savedChannels);
|
||||
|
||||
header('Location: /?view=channels&saved=1');
|
||||
exit;
|
||||
}
|
||||
|
||||
[$channels, $programmes] = $xmltv->load($config);
|
||||
|
||||
$currentProgrammes = $xmltv->getCurrentProgrammes($config);
|
||||
|
||||
$tz = new DateTimeZone($config->get('timezone', 'Europe/Vienna'));
|
||||
$selectedDate = $_GET['date'] ?? (new DateTime('now', $tz))->format('Y-m-d');
|
||||
|
||||
$selectedChannel = $_GET['channel'] ?? null;
|
||||
if ($selectedChannel === '') {
|
||||
$selectedChannel = null;
|
||||
}
|
||||
|
||||
if (!preg_match('/^\d{4}-\d{2}-\d{2}$/', $selectedDate)) {
|
||||
$selectedDate = date('Y-m-d');
|
||||
}
|
||||
|
||||
$dayProgrammes = $xmltv->getDayProgrammes($config, $selectedDate, $selectedChannel);
|
||||
|
||||
$tz = new DateTimeZone($config->get('timezone', 'Europe/Vienna'));
|
||||
$nowDateTime = new DateTime('now', $tz);
|
||||
|
||||
$isToday = ($selectedDate === $nowDateTime->format('Y-m-d'));
|
||||
|
||||
$nowMinute = null;
|
||||
|
||||
if ($isToday) {
|
||||
$nowMinute =
|
||||
((int)$nowDateTime->format('H') * 60) +
|
||||
(int)$nowDateTime->format('i');
|
||||
}
|
||||
|
||||
$contentTemplate = match ($view) {
|
||||
'channels' => '/var/www/templates/channels.php',
|
||||
'now' => '/var/www/templates/now.php',
|
||||
'day' => '/var/www/templates/day.php',
|
||||
default => '/var/www/templates/home.php',
|
||||
};
|
||||
|
||||
View::render('layout', [
|
||||
'title' => $config->get('title', 'TVGuide'),
|
||||
'channels' => $channels,
|
||||
'programmes' => $programmes,
|
||||
'contentTemplate' => $contentTemplate,
|
||||
'view' => $view,
|
||||
'channelConfig' => $config->getChannels(),
|
||||
'saved' => isset($_GET['saved']),
|
||||
'currentProgrammes' => $currentProgrammes,
|
||||
'selectedDate' => $selectedDate,
|
||||
'selectedChannel' => $selectedChannel,
|
||||
'dayProgrammes' => $dayProgrammes,
|
||||
'isToday' => $isToday,
|
||||
'nowMinute' => $nowMinute,
|
||||
]);
|
||||
$controller = new HomeController($config, $xmltv);
|
||||
$controller->handle($_GET, $_POST, $_SERVER['REQUEST_METHOD']);
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
class HomeController
|
||||
{
|
||||
public function __construct(
|
||||
private Config $config,
|
||||
private XmlTv $xmltv,
|
||||
private ChannelService $channelService = new ChannelService()
|
||||
) {
|
||||
}
|
||||
|
||||
public function handle(array $get, array $post, string $method): void
|
||||
{
|
||||
$this->xmltv->synchronizeChannels($this->config);
|
||||
|
||||
$view = $get['view'] ?? $this->config->get('default_view', 'today');
|
||||
|
||||
if ($view === 'channels' && $method === 'POST') {
|
||||
$this->channelService->saveChannelsFromPost($this->config, $post);
|
||||
header('Location: /?view=channels&saved=1');
|
||||
exit;
|
||||
}
|
||||
|
||||
[$channels, $programmes] = $this->xmltv->load($this->config);
|
||||
|
||||
$currentProgrammes = $this->xmltv->getCurrentProgrammes($this->config);
|
||||
|
||||
$tz = new DateTimeZone($this->config->get('timezone', 'Europe/Vienna'));
|
||||
$selectedDate = $get['date'] ?? (new DateTime('now', $tz))->format('Y-m-d');
|
||||
|
||||
$selectedChannel = $get['channel'] ?? null;
|
||||
if ($selectedChannel === '') {
|
||||
$selectedChannel = null;
|
||||
}
|
||||
|
||||
if (!preg_match('/^\d{4}-\d{2}-\d{2}$/', $selectedDate)) {
|
||||
$selectedDate = (new DateTime('now', $tz))->format('Y-m-d');
|
||||
}
|
||||
|
||||
$dayProgrammes = $this->xmltv->getDayProgrammes($this->config, $selectedDate, $selectedChannel);
|
||||
|
||||
$nowDateTime = new DateTime('now', $tz);
|
||||
$isToday = ($selectedDate === $nowDateTime->format('Y-m-d'));
|
||||
|
||||
$nowMinute = null;
|
||||
if ($isToday) {
|
||||
$nowMinute =
|
||||
((int)$nowDateTime->format('H') * 60) +
|
||||
(int)$nowDateTime->format('i');
|
||||
}
|
||||
|
||||
if ($view === 'favorites') {
|
||||
$currentProgrammes = array_values(array_filter(
|
||||
$currentProgrammes,
|
||||
fn($item) => !empty($item['favorite'])
|
||||
));
|
||||
}
|
||||
|
||||
$contentTemplate = match ($view) {
|
||||
'channels' => '/var/www/templates/channels.php',
|
||||
'now' => '/var/www/templates/now.php',
|
||||
'favorites' => '/var/www/templates/now.php',
|
||||
'day' => '/var/www/templates/day.php',
|
||||
default => '/var/www/templates/home.php',
|
||||
};
|
||||
|
||||
View::render('layout', [
|
||||
'title' => $this->config->get('title', 'TVGuide'),
|
||||
'channels' => $channels,
|
||||
'programmes' => $programmes,
|
||||
'contentTemplate' => $contentTemplate,
|
||||
'view' => $view,
|
||||
'channelConfig' => $this->config->getChannels(),
|
||||
'saved' => isset($get['saved']),
|
||||
'currentProgrammes' => $currentProgrammes,
|
||||
'selectedDate' => $selectedDate,
|
||||
'selectedChannel' => $selectedChannel,
|
||||
'dayProgrammes' => $dayProgrammes,
|
||||
'isToday' => $isToday,
|
||||
'nowMinute' => $nowMinute,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -31,10 +31,31 @@ class ChannelService
|
||||
}
|
||||
}
|
||||
|
||||
uasort($storedChannels, function ($a, $b) {
|
||||
$config->saveChannels($this->sortChannels($storedChannels));
|
||||
}
|
||||
|
||||
public function saveChannelsFromPost(Config $config, array $post): void
|
||||
{
|
||||
$savedChannels = $config->getChannels();
|
||||
|
||||
foreach ($savedChannels as $id => &$channel) {
|
||||
$channel['enabled'] = isset($post['enabled'][$id]);
|
||||
$channel['favorite'] = isset($post['favorite'][$id]);
|
||||
$channel['number'] = (int)($post['number'][$id] ?? $channel['number'] ?? 999999);
|
||||
$channel['group'] = trim($post['group'][$id] ?? $channel['group'] ?? 'Unknown');
|
||||
}
|
||||
|
||||
unset($channel);
|
||||
|
||||
$config->saveChannels($this->sortChannels($savedChannels));
|
||||
}
|
||||
|
||||
private function sortChannels(array $channels): array
|
||||
{
|
||||
uasort($channels, function ($a, $b) {
|
||||
return ((int)($a['number'] ?? 999999)) <=> ((int)($b['number'] ?? 999999));
|
||||
});
|
||||
|
||||
$config->saveChannels($storedChannels);
|
||||
return $channels;
|
||||
}
|
||||
}
|
||||
|
||||
+13
-3
@@ -1,10 +1,20 @@
|
||||
<?php $isFavoritesView = ($view ?? '') === 'favorites'; ?>
|
||||
|
||||
<section class="page-heading">
|
||||
<h2>Jetzt läuft</h2>
|
||||
<p>Aktuelle Sendungen auf deinen aktivierten Sendern.</p>
|
||||
<h2><?= $isFavoritesView ? 'Favoriten' : 'Jetzt läuft' ?></h2>
|
||||
<p>
|
||||
<?= $isFavoritesView
|
||||
? 'Aktuelle Sendungen auf deinen Favoriten-Sendern.'
|
||||
: 'Aktuelle Sendungen auf deinen aktivierten Sendern.' ?>
|
||||
</p>
|
||||
</section>
|
||||
|
||||
<?php if (!$currentProgrammes): ?>
|
||||
<div class="empty">Aktuell wurden keine laufenden Sendungen gefunden.</div>
|
||||
<div class="empty">
|
||||
<?= $isFavoritesView
|
||||
? 'Aktuell läuft auf deinen Favoriten keine Sendung.'
|
||||
: 'Aktuell wurden keine laufenden Sendungen gefunden.' ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="now-grid">
|
||||
|
||||
Reference in New Issue
Block a user