You've already forked Atomcms-edit
71 lines
2.1 KiB
PHP
Executable File
71 lines
2.1 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Services\Community;
|
|
|
|
use App\Models\RadioSchedule;
|
|
use App\Models\User;
|
|
use Illuminate\Support\Collection;
|
|
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(): 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'));
|
|
}
|
|
}
|