Favorites

This commit is contained in:
Gogs
2026-07-07 11:32:03 +02:00
parent f3d25f20d3
commit c2da564dd6
5 changed files with 127 additions and 87 deletions
+23 -2
View File
@@ -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;
}
}