Channel Management, Drag & Drop

This commit is contained in:
Gogs
2026-07-08 15:58:53 +02:00
parent 7ad81baab6
commit d7bc3dffa9
7 changed files with 973 additions and 580 deletions
+17 -29
View File
@@ -4,34 +4,8 @@ class ChannelService
{
public function synchronizeChannels(array $cachedChannels, Config $config): void
{
$storedChannels = $config->getChannels();
$maxNumber = 0;
foreach ($storedChannels as $stored) {
$maxNumber = max($maxNumber, (int)($stored['number'] ?? 0));
}
foreach ($cachedChannels as $id => $channel) {
if (!isset($storedChannels[$id])) {
$maxNumber++;
$storedChannels[$id] = [
'uuid' => bin2hex(random_bytes(16)),
'name' => $channel['name'] ?? $id,
'icon' => $channel['icon'] ?? '',
'country' => '',
'language' => '',
'enabled' => true,
'favorite' => false,
'number' => $maxNumber,
'group' => 'Unknown',
];
} else {
$storedChannels[$id]['name'] = $channel['name'] ?? $storedChannels[$id]['name'];
}
}
$config->saveChannels($this->sortChannels($storedChannels));
// Alt-Methode bleibt absichtlich harmlos.
// Neue Sender werden jetzt vom SenderSyncService im XmlTvCacheService ergänzt.
}
public function saveChannelsFromPost(Config $config, array $post): void
@@ -48,12 +22,26 @@ class ChannelService
unset($channel);
$config->saveChannels($this->sortChannels($savedChannels));
@unlink('/var/www/cache/guide.json');
@unlink('/var/www/cache/guide.version');
}
public function getSortedChannels(Config $config): array
{
return $this->sortChannels($config->getChannels());
}
private function sortChannels(array $channels): array
{
uasort($channels, function ($a, $b) {
return ((int)($a['number'] ?? 999999)) <=> ((int)($b['number'] ?? 999999));
return [
(int)($a['number'] ?? 999999),
strtolower($a['name'] ?? '')
] <=> [
(int)($b['number'] ?? 999999),
strtolower($b['name'] ?? '')
];
});
return $channels;