Files
Atomcms-edit/app/Services/Community/RadioScheduleService.php
T
root 81e99933e4 refactor: improve code quality across controllers and services
- DRY FurniEditorController: extract duplicate try/catch blocks into handleApiError(),
  formatItemData(), buildUpdateData(), buildInsertData(), castValue() methods
- ProfileController: replace 45 lines of manual date formatting with Carbon's diffForHumans()
- Replace custom Password rule (180 lines) with Laravel's built-in Password::min() rule
- RadioController: extract RadioStreamService and RadioScheduleService, reducing from 608 to 323 lines
- Add RadioSettings enum to replace magic strings throughout radio feature
- Add CurrencyTypes::columnName() helper method
- Add consistent return types (JsonResponse, View, RedirectResponse) to all controller methods
2026-05-19 19:16:59 +02:00

70 lines
2.1 KiB
PHP
Executable File

<?php
namespace App\Services\Community;
use App\Models\RadioSchedule;
use App\Models\User;
use Illuminate\Support\Facades\Cache;
class RadioScheduleService
{
public function getCurrentDJ(?string $manualDjId = null): ?array
{
if (! empty($manualDjId)) {
$dj = Cache::remember("user_{$manualDjId}", 60, fn () => User::find($manualDjId));
if ($dj) {
return [
'username' => $dj->username,
'look' => $dj->look,
'show_name' => 'Live DJ',
'is_manual' => true,
];
}
}
$currentSlot = RadioSchedule::with('user:id,username,look')
->active()
->where('day', $this->getCurrentDay())
->whereTime('start_time', '<=', now()->format('H:i:s'))
->whereTime('end_time', '>=', now()->format('H:i:s'))
->first();
if ($currentSlot?->user) {
return [
'username' => $currentSlot->user->username,
'look' => $currentSlot->user->look,
'show_name' => $currentSlot->show_name,
'start_time' => $currentSlot->start_time->format('H:i'),
'end_time' => $currentSlot->end_time->format('H:i'),
'is_manual' => false,
];
}
return null;
}
public function getTodaySchedule(): \Illuminate\Database\Eloquent\Collection
{
return Cache::remember('radio_schedule_today', 60, fn () => RadioSchedule::with('user:id,username,look')
->active()
->today()
->orderBy('start_time')
->get());
}
public function getFullSchedule(): \Illuminate\Support\Collection
{
return Cache::remember('radio_schedule_all', 300, fn () => RadioSchedule::with('user:id,username,look')
->active()
->ordered()
->get()
->groupBy('day'));
}
private function getCurrentDay(): string
{
return strtolower(now()->format('l'));
}
}