libretime/legacy/application/models/Dashboard.php

160 lines
5.7 KiB
PHP
Raw Permalink Normal View History

<?php
class Application_Model_Dashboard
{
public static function GetPreviousItem($p_timeNow)
{
// get previous show and previous item in the schedule table.
// Compare the two and if the last show was recorded and started
// after the last item in the schedule table, then return the show's
// name. Else return the last item from the schedule.
$showInstance = Application_Model_ShowInstance::GetLastShowInstance($p_timeNow);
$row = Application_Model_Schedule::GetLastScheduleItem($p_timeNow);
if (is_null($showInstance)) {
if (count($row) == 0) {
return null;
}
2021-10-11 16:10:47 +02:00
2022-07-07 20:01:15 +02:00
return [
'name' => $row[0]['artist_name'] . ' - ' . $row[0]['track_title'],
2021-10-11 16:10:47 +02:00
'starts' => $row[0]['starts'],
2022-07-07 20:01:15 +02:00
'ends' => $row[0]['ends'],
];
2021-10-11 16:10:47 +02:00
}
if (count($row) == 0) {
if ($showInstance->isRecorded()) {
// last item is a show instance
2022-07-07 20:01:15 +02:00
return [
'name' => $showInstance->getName(),
2021-10-11 16:10:47 +02:00
'starts' => $showInstance->getShowInstanceStart(),
2022-07-07 20:01:15 +02:00
'ends' => $showInstance->getShowInstanceEnd(),
];
}
2021-10-11 16:10:47 +02:00
return null;
}
// return the one that started later.
2021-10-11 16:10:47 +02:00
if ($row[0]['starts'] >= $showInstance->getShowInstanceStart()) {
2022-07-07 20:01:15 +02:00
return [
'name' => $row[0]['artist_name'] . ' - ' . $row[0]['track_title'],
2021-10-11 16:10:47 +02:00
'starts' => $row[0]['starts'],
2022-07-07 20:01:15 +02:00
'ends' => $row[0]['ends'],
];
}
2021-10-11 16:10:47 +02:00
2022-07-07 20:01:15 +02:00
return [
'name' => $showInstance->getName(),
2021-10-11 16:10:47 +02:00
'starts' => $showInstance->getShowInstanceStart(),
2022-07-07 20:01:15 +02:00
'ends' => $showInstance->getShowInstanceEnd(),
];
}
public static function GetCurrentItem($p_timeNow)
{
// get previous show and previous item in the schedule table.
// Compare the two and if the last show was recorded and started
// after the last item in the schedule table, then return the show's
// name. Else return the last item from the schedule.
2021-10-11 16:10:47 +02:00
$row = [];
$showInstance = Application_Model_ShowInstance::GetCurrentShowInstance($p_timeNow);
if (!is_null($showInstance)) {
$instanceId = $showInstance->getShowInstanceId();
$row = Application_Model_Schedule::GetCurrentScheduleItem($p_timeNow, $instanceId);
}
if (is_null($showInstance)) {
if (count($row) == 0) {
return null;
}
2021-10-11 16:10:47 +02:00
/* Should never reach here, but lets return the track information
* just in case we allow tracks to be scheduled without a show
* in the future.
*/
2022-07-07 20:01:15 +02:00
return [
'name' => $row[0]['artist_name'] . ' - ' . $row[0]['track_title'],
2021-10-11 16:10:47 +02:00
'artwork_data' => $row[0]['artwork_data'],
'starts' => $row[0]['starts'],
2022-07-07 20:01:15 +02:00
'ends' => $row[0]['ends'],
];
2021-10-11 16:10:47 +02:00
}
if (count($row) == 0) {
// last item is a show instance
2021-10-11 16:10:47 +02:00
if ($showInstance->isRecorded()) {
2022-07-07 20:01:15 +02:00
return [
'name' => $showInstance->getName(),
2021-10-11 16:10:47 +02:00
'starts' => $showInstance->getShowInstanceStart(),
'ends' => $showInstance->getShowInstanceEnd(),
'media_item_played' => false,
2022-07-07 20:01:15 +02:00
'record' => true,
];
}
2021-10-11 16:10:47 +02:00
return null;
}
2021-10-11 16:10:47 +02:00
2022-07-07 20:01:15 +02:00
return [
'name' => $row[0]['artist_name'] . ' - ' . $row[0]['track_title'],
2021-10-11 16:10:47 +02:00
'artwork_data' => $row[0]['artwork_data'],
'starts' => $row[0]['starts'],
'ends' => $row[0]['ends'],
'media_item_played' => $row[0]['media_item_played'],
2022-07-07 20:01:15 +02:00
'record' => 0,
];
}
public static function GetNextItem($p_timeNow)
{
// get previous show and previous item in the schedule table.
// Compare the two and if the last show was recorded and started
// after the last item in the schedule table, then return the show's
// name. Else return the last item from the schedule.
$showInstance = Application_Model_ShowInstance::GetNextShowInstance($p_timeNow);
$row = Application_Model_Schedule::GetNextScheduleItem($p_timeNow);
if (is_null($showInstance)) {
if (count($row) == 0) {
return null;
}
2021-10-11 16:10:47 +02:00
2022-07-07 20:01:15 +02:00
return [
'name' => $row[0]['artist_name'] . ' - ' . $row[0]['track_title'],
2021-10-11 16:10:47 +02:00
'artwork_data' => $row[0]['artwork_data'],
'starts' => $row[0]['starts'],
2022-07-07 20:01:15 +02:00
'ends' => $row[0]['ends'],
];
2021-10-11 16:10:47 +02:00
}
if (count($row) == 0) {
if ($showInstance->isRecorded()) {
// last item is a show instance
2022-07-07 20:01:15 +02:00
return [
'name' => $showInstance->getName(),
2021-10-11 16:10:47 +02:00
'starts' => $showInstance->getShowInstanceStart(),
2022-07-07 20:01:15 +02:00
'ends' => $showInstance->getShowInstanceEnd(),
];
}
2021-10-11 16:10:47 +02:00
return null;
}
// return the one that starts sooner.
2021-10-11 16:10:47 +02:00
if ($row[0]['starts'] <= $showInstance->getShowInstanceStart()) {
2022-07-07 20:01:15 +02:00
return [
'name' => $row[0]['artist_name'] . ' - ' . $row[0]['track_title'],
2021-10-11 16:10:47 +02:00
'artwork_data' => $row[0]['artwork_data'],
'starts' => $row[0]['starts'],
2022-07-07 20:01:15 +02:00
'ends' => $row[0]['ends'],
];
2021-10-11 16:10:47 +02:00
}
2022-07-07 20:01:15 +02:00
return [
'name' => $showInstance->getName(),
2021-10-11 16:10:47 +02:00
'starts' => $showInstance->getShowInstanceStart(),
2022-07-07 20:01:15 +02:00
'ends' => $showInstance->getShowInstanceEnd(),
];
2021-10-11 16:10:47 +02:00
}
}