From 444ad56464112a44dc228532a612052379566cc4 Mon Sep 17 00:00:00 2001 From: Mischa Spelt Date: Mon, 4 Jan 2021 20:34:57 +0100 Subject: [PATCH] OnAir including currently playing from st1 --- .../Http/Controllers/ProgramController.php | 69 ++++++++++++------- 1 file changed, 45 insertions(+), 24 deletions(-) diff --git a/api/app/Http/Controllers/ProgramController.php b/api/app/Http/Controllers/ProgramController.php index 6c5b0ae..132c211 100644 --- a/api/app/Http/Controllers/ProgramController.php +++ b/api/app/Http/Controllers/ProgramController.php @@ -245,9 +245,9 @@ QUERY; } - private function getTrack($next = false) { + private function getTrack($studio = 'nonstop', $next = false) { $prefix = $next ? "next" : "current"; - $data = app('db')->select("SELECT {$prefix}_start AS start, {$prefix}_itemcode AS itemCode, {$prefix}_title AS title, {$prefix}_artist AS artist, {$prefix}_duration AS duration FROM `now_playing`"); + $data = app('db')->select("SELECT {$prefix}_start AS start, {$prefix}_itemcode AS itemCode, {$prefix}_title AS title, {$prefix}_artist AS artist, {$prefix}_duration AS duration FROM `now_playing` WHERE `studio` = :studio", ['studio' => $studio]); return new \Model\Track($data[0]); } @@ -279,21 +279,31 @@ QUERY; $schema = $this->createSchedule($start, $einde); $program = $schema['schedule'][0]['program']; - if($program->nonstop) { - $current = $this->getTrack(); - $next = $this->getTrack(/* next: */ true); - $current->ends($next->start); - if($current->isLayout() /* || $current->secondsRemaining() < 0 */) { - if(!$next->isLayout()) { - $current = $next; - } - } - - return response()->json(['inProgram' => false, 'stream' => $this->isStreamEnabled(), 'current' => $current, 'program' => $program]); - } else { - $canStream = $this->isStreamEnabled(); - return response()->json(['inProgram' => true, 'stream' => $canStream, 'program' => $program]); + $activeStudioQuery = app('db')->select("SELECT `studio` FROM `programs_schedule_webcam` WHERE `active` = 1"); + if(!count($activeStudioQuery) || !($activeStudio = $activeStudioQuery[0]->studio)) { + $activeStudio = 'nonstop'; } + + $current = $this->getTrack($activeStudio); + $next = $this->getTrack($activeStudio, /* next: */ true); + $current->ends($next->start); + if($current->isLayout() /* || $current->secondsRemaining() < 0 */) { + if(!$next->isLayout()) { + $current = $next; + } + } + + $data = [ + 'inProgram' => !$program->nonstop, + 'program' => $program, + 'stream' => $this->isStreamEnabled(), + ]; + + if($current && !$current->isLayout() && $current->title) { + $data['current'] = $current; + } + + return response()->json($data); } public function onair_text(Request $request) { @@ -302,9 +312,19 @@ QUERY; $schema = $this->createSchedule($start, $einde); $program = $schema['schedule'][0]['program']; - if(!$program->nonstop) { - $current = $this->getTrack(); - $next = $this->getTrack(/* next: */ true); + $activeStudioQuery = app('db')->select("SELECT `studio` FROM `programs_schedule_webcam` WHERE `active` = 1"); + if(!count($activeStudioQuery) || !($activeStudio = $activeStudioQuery[0]->studio)) { + $activeStudio = 'nonstop'; + } + + $text = []; + if(!$program->nonstop) { + $text[] = $program->name; + } + + if($activeStudio) { + $current = $this->getTrack($activeStudio); + $next = $this->getTrack($activeStudio, /* next: */ true); $current->ends($next->start); if($current->isLayout() /* || $current->secondsRemaining() < 0 */) { if(!$next->isLayout()) { @@ -312,12 +332,13 @@ QUERY; } } - return $request->get('program_only', false) - ? $program->name - : $program->name . " - " . $current->title . " - " . $current->artist; - } else { - return $program->name; + if(!$request->get('program_only', false) && !($current->isLayout())) { + if($current->title) $text[] = $current->title; + if($current->artist) $text[] = $currenet->artist; } + } + + return join(' - ', $text); } /**