-further fixes for naomis new layout
This commit is contained in:
parent
8396e12df1
commit
fae1401568
|
@ -2,108 +2,88 @@
|
|||
|
||||
class Application_Model_Nowplaying
|
||||
{
|
||||
|
||||
public static function InsertBlankRow($i, $rows){
|
||||
$startDate = explode(".", $rows[$i-1][3]);
|
||||
$endDate = explode(".", $rows[$i][2]);
|
||||
|
||||
$epochStartMS = strtotime($startDate[0])*1000;
|
||||
$epochEndMS = strtotime($endDate[0])*1000;
|
||||
|
||||
if (count($startDate) > 1)
|
||||
$epochStartMS += $startDate[1];
|
||||
if (count($endDate) > 1)
|
||||
$epochEndMS += $endDate[1];
|
||||
|
||||
$blankRow = array(array("b", "-", "-", "-", Application_Model_DateHelper::ConvertMSToHHMMSSmm($epochEndMS - $epochStartMS), "-", "-", "-", "-" , "-", "", ""));
|
||||
array_splice($rows, $i, 0, $blankRow);
|
||||
return $rows;
|
||||
}
|
||||
|
||||
public static function FindGaps($rows){
|
||||
$n = count($rows);
|
||||
|
||||
$blankRowIndices = array();
|
||||
$arrayIndexOffset = 0;
|
||||
|
||||
if ($n < 2)
|
||||
return $rows;
|
||||
|
||||
for ($i=1; $i<$n; $i++){
|
||||
if ($rows[$i-1][3] != $rows[$i][2])
|
||||
array_push($blankRowIndices, $i);
|
||||
}
|
||||
|
||||
for ($i=0, $n=count($blankRowIndices); $i<$n; $i++){
|
||||
$rows = Application_Model_Nowplaying::InsertBlankRow($blankRowIndices[$i]+$arrayIndexOffset, $rows);
|
||||
$arrayIndexOffset++;
|
||||
}
|
||||
|
||||
return $rows;
|
||||
}
|
||||
|
||||
public static function GetDataGridData($viewType){
|
||||
|
||||
$columnHeaders = array(array("sTitle"=>"type", "bVisible"=>false),
|
||||
array("sTitle"=>"Date"),
|
||||
array("sTitle"=>"Start"),
|
||||
array("sTitle"=>"End"),
|
||||
array("sTitle"=>"Duration"),
|
||||
array("sTitle"=>"Song"),
|
||||
array("sTitle"=>"Artist"),
|
||||
array("sTitle"=>"Album"),
|
||||
array("sTitle"=>"Playlist"),
|
||||
array("sTitle"=>"Show"),
|
||||
array("sTitle"=>"bgcolor", "bVisible"=>false),
|
||||
array("sTitle"=>"group_id", "bVisible"=>false));
|
||||
|
||||
$date = Schedule::GetSchedulerTime();
|
||||
$timeNow = $date->getDate();
|
||||
$currentShow = Schedule::GetCurrentShow($timeNow);
|
||||
$groupIDs = array();
|
||||
|
||||
public static function InsertBlankRow($i, $rows){
|
||||
$startDate = explode(".", $rows[$i-1][3]);
|
||||
$endDate = explode(".", $rows[$i][2]);
|
||||
|
||||
if (count($currentShow) > 0){
|
||||
$dbRows = Show_DAL::GetShowGroupIDs($currentShow[0]["id"]);
|
||||
|
||||
foreach ($dbRows as $row){
|
||||
array_push($groupIDs, $row["group_id"]);
|
||||
}
|
||||
}
|
||||
|
||||
if ($viewType == "now"){
|
||||
$previous = Schedule::Get_Scheduled_Item_Data($timeNow, -1, 1, "60 seconds");
|
||||
$current = Schedule::Get_Scheduled_Item_Data($timeNow, 0);
|
||||
$next = Schedule::Get_Scheduled_Item_Data($timeNow, 1, 10, "24 hours");
|
||||
} else {
|
||||
$epochStartMS = strtotime($startDate[0])*1000;
|
||||
$epochEndMS = strtotime($endDate[0])*1000;
|
||||
|
||||
if (count($startDate) > 1)
|
||||
$epochStartMS += $startDate[1];
|
||||
if (count($endDate) > 1)
|
||||
$epochEndMS += $endDate[1];
|
||||
|
||||
$blankRow = array(array("b", "-", "-", "-", Application_Model_DateHelper::ConvertMSToHHMMSSmm($epochEndMS - $epochStartMS), "-", "-", "-", "-" , "-", "", ""));
|
||||
array_splice($rows, $i, 0, $blankRow);
|
||||
return $rows;
|
||||
}
|
||||
|
||||
public static function FindGaps($rows){
|
||||
$n = count($rows);
|
||||
|
||||
$blankRowIndices = array();
|
||||
$arrayIndexOffset = 0;
|
||||
|
||||
if ($n < 2)
|
||||
return $rows;
|
||||
|
||||
for ($i=1; $i<$n; $i++){
|
||||
if ($rows[$i-1][3] != $rows[$i][2])
|
||||
array_push($blankRowIndices, $i);
|
||||
}
|
||||
|
||||
for ($i=0, $n=count($blankRowIndices); $i<$n; $i++){
|
||||
$rows = Application_Model_Nowplaying::InsertBlankRow($blankRowIndices[$i]+$arrayIndexOffset, $rows);
|
||||
$arrayIndexOffset++;
|
||||
}
|
||||
|
||||
return $rows;
|
||||
}
|
||||
|
||||
public static function GetDataGridData($viewType){
|
||||
|
||||
$date = Schedule::GetSchedulerTime();
|
||||
$timeNow = $date->getDate();
|
||||
|
||||
if ($viewType == "now"){
|
||||
|
||||
$previous = Schedule::Get_Scheduled_Item_Data($timeNow, -1, "ALL", $date->getNowDayStartDiff()." seconds");
|
||||
$current = Schedule::Get_Scheduled_Item_Data($timeNow, 0);
|
||||
$next = Schedule::Get_Scheduled_Item_Data($timeNow, 1, "ALL", $date->getNowDayEndDiff()." seconds");
|
||||
}
|
||||
|
||||
$rows = array();
|
||||
|
||||
foreach ($previous as $item){
|
||||
$color = (count($currentShow) > 0) && in_array($item["group_id"], $groupIDs) ? "x" : "";
|
||||
array_push($rows, array("p", $item["starts"], $item["starts"], $item["ends"], $item["clip_length"], $item["track_title"], $item["artist_name"],
|
||||
$item["album_title"], $item["name"], $item["show_name"], $color, $item["group_id"]));
|
||||
}
|
||||
|
||||
foreach ($current as $item){
|
||||
array_push($rows, array("c", $item["starts"], $item["starts"], $item["ends"], $item["clip_length"], $item["track_title"], $item["artist_name"],
|
||||
$item["album_title"], $item["name"], $item["show_name"], "", $item["group_id"]));
|
||||
}
|
||||
|
||||
foreach ($next as $item){
|
||||
$color = (count($currentShow) > 0) && in_array($item["group_id"], $groupIDs) ? "x" : "";
|
||||
array_push($rows, array("n", $item["starts"], $item["starts"], $item["ends"], $item["clip_length"], $item["track_title"], $item["artist_name"],
|
||||
$item["album_title"], $item["name"], $item["show_name"], $color, $item["group_id"]));
|
||||
}
|
||||
|
||||
$rows = Application_Model_Nowplaying::FindGaps($rows);
|
||||
$data = array("columnHeaders"=>$columnHeaders, "rows"=>$rows);
|
||||
|
||||
return $data;
|
||||
}
|
||||
/* When do "ORDER BY x DESC LIMIT 5" to ensure that we get the last 5 previously scheduled items.
|
||||
* However using DESC, puts our scheduled items in reverse order, so we need to reverse it again
|
||||
* with array_reverse.
|
||||
*/
|
||||
$previous = array_reverse(Schedule::Get_Scheduled_Item_Data($timeNow, -1, 1, "60 seconds"));
|
||||
$current = Schedule::Get_Scheduled_Item_Data($timeNow, 0);
|
||||
$next = Schedule::Get_Scheduled_Item_Data($timeNow, 1, 10, "24 hours");
|
||||
} else {
|
||||
|
||||
$previous = array_reverse(Schedule::Get_Scheduled_Item_Data($timeNow, -1, "ALL", $date->getNowDayStartDiff()." seconds"));
|
||||
$current = Schedule::Get_Scheduled_Item_Data($timeNow, 0);
|
||||
$next = Schedule::Get_Scheduled_Item_Data($timeNow, 1, "ALL", $date->getNowDayEndDiff()." seconds");
|
||||
}
|
||||
|
||||
$rows = array();
|
||||
|
||||
foreach ($previous as $item){
|
||||
array_push($rows, array("p", $item["starts"], $item["starts"], $item["ends"], $item["clip_length"], $item["track_title"], $item["artist_name"],
|
||||
$item["album_title"], $item["name"], $item["show_name"], $item["current_show"], $item["group_id"]));
|
||||
}
|
||||
|
||||
foreach ($current as $item){
|
||||
array_push($rows, array("c", $item["starts"], $item["starts"], $item["ends"], $item["clip_length"], $item["track_title"], $item["artist_name"],
|
||||
$item["album_title"], $item["name"], $item["show_name"], $item["current_show"], $item["group_id"]));
|
||||
}
|
||||
|
||||
foreach ($next as $item){
|
||||
array_push($rows, array("n", $item["starts"], $item["starts"], $item["ends"], $item["clip_length"], $item["track_title"], $item["artist_name"],
|
||||
$item["album_title"], $item["name"], $item["show_name"], $item["current_show"], $item["group_id"]));
|
||||
}
|
||||
|
||||
$rows = Application_Model_Nowplaying::FindGaps($rows);
|
||||
$data = array("rows"=>$rows);
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -453,8 +453,8 @@ class Schedule {
|
|||
"previous"=>Schedule::Get_Scheduled_Item_Data($timeNow, -1, $prev, "24 hours"),
|
||||
"current"=>Schedule::Get_Scheduled_Item_Data($timeNow, 0),
|
||||
"next"=>Schedule::Get_Scheduled_Item_Data($timeNow, 1, $next, "48 hours"),
|
||||
"currentShow"=>Schedule::GetCurrentShow($timeNow),
|
||||
"nextShow"=>Schedule::GetNextShow($timeNow),
|
||||
"currentShow"=>Show_DAL::GetCurrentShow($timeNow),
|
||||
"nextShow"=>Show_DAL::GetNextShow($timeNow),
|
||||
"timezone"=> date("T"),
|
||||
"timezoneOffset"=> date("Z"));
|
||||
}
|
||||
|
@ -483,7 +483,7 @@ class Schedule {
|
|||
*/
|
||||
public static function Get_Scheduled_Item_Data($timeNow, $timePeriod=0, $count = 0, $interval="0 hours"){
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
$sql = "SELECT DISTINCT pt.name, ft.track_title, ft.artist_name, ft.album_title, st.starts, st.ends, st.clip_length, st.group_id, show.name as show_name"
|
||||
$sql = "SELECT DISTINCT pt.name, ft.track_title, ft.artist_name, ft.album_title, st.starts, st.ends, st.clip_length, st.group_id, show.name as show_name, (si.starts <= TIMESTAMP '$timeNow' AND si.ends > TIMESTAMP '$timeNow') as current_show"
|
||||
." FROM $CC_CONFIG[scheduleTable] st, $CC_CONFIG[filesTable] ft, $CC_CONFIG[playListTable] pt, $CC_CONFIG[showInstances] si, $CC_CONFIG[showTable] show"
|
||||
." WHERE st.playlist_id = pt.id"
|
||||
." AND st.file_id = ft.id"
|
||||
|
@ -493,7 +493,7 @@ class Schedule {
|
|||
if ($timePeriod < 0){
|
||||
$sql .= " AND st.ends < TIMESTAMP '$timeNow'"
|
||||
." AND st.ends > (TIMESTAMP '$timeNow' - INTERVAL '$interval')"
|
||||
." ORDER BY st.starts"
|
||||
." ORDER BY st.starts DESC"
|
||||
." LIMIT $count";
|
||||
} else if ($timePeriod == 0){
|
||||
$sql .= " AND st.starts < TIMESTAMP '$timeNow'"
|
||||
|
@ -508,39 +508,7 @@ class Schedule {
|
|||
$rows = $CC_DBC->GetAll($sql);
|
||||
return $rows;
|
||||
}
|
||||
|
||||
public static function GetCurrentShow($timeNow) {
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
|
||||
$timestamp = explode(" ", $timeNow);
|
||||
$date = $timestamp[0];
|
||||
$time = $timestamp[1];
|
||||
|
||||
$sql = "SELECT si.starts as start_timestamp, si.ends as end_timestamp, s.name, s.id"
|
||||
." FROM $CC_CONFIG[showInstances] si, $CC_CONFIG[showTable] s"
|
||||
." WHERE si.show_id = s.id"
|
||||
." AND si.starts <= TIMESTAMP '$timeNow'"
|
||||
." AND si.ends > TIMESTAMP '$timeNow'";
|
||||
|
||||
$rows = $CC_DBC->GetAll($sql);
|
||||
return $rows;
|
||||
}
|
||||
|
||||
public static function GetNextShow($timeNow) {
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
|
||||
$sql = "SELECT *, si.starts as start_timestamp, si.ends as end_timestamp FROM "
|
||||
." $CC_CONFIG[showInstances] si, $CC_CONFIG[showTable] s"
|
||||
." WHERE si.show_id = s.id"
|
||||
." AND si.starts > TIMESTAMP '$timeNow'"
|
||||
." AND si.starts < TIMESTAMP '$timeNow' + INTERVAL '48 hours'"
|
||||
." ORDER BY si.starts"
|
||||
." LIMIT 1";
|
||||
|
||||
$rows = $CC_DBC->GetAll($sql);
|
||||
return $rows;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Convert a time string in the format "YYYY-MM-DD HH:mm:SS"
|
||||
|
|
|
@ -678,35 +678,37 @@ class ShowInstance {
|
|||
|
||||
/* Show Data Access Layer */
|
||||
class Show_DAL{
|
||||
|
||||
/* Given a group_id, get all show data related to
|
||||
* id. This is useful in the case where you have an item
|
||||
* in the schedule table and you want to find out more about
|
||||
* the show it is in without joining the schedule and show tables
|
||||
* (which causes problems with duplicate items)
|
||||
*/
|
||||
public static function GetShowData($group_id){
|
||||
global $CC_DBC;
|
||||
|
||||
$sql="SELECT * FROM cc_show_schedule as ss, cc_show as s"
|
||||
." WHERE ss.show_id = s.id"
|
||||
." AND ss.group_id = $group_id"
|
||||
." LIMIT 1";
|
||||
|
||||
return $CC_DBC->GetOne($sql);
|
||||
}
|
||||
|
||||
/* Given a show ID, this function returns what group IDs
|
||||
* are present in this show. */
|
||||
public static function GetShowGroupIDs($showID){
|
||||
public static function GetCurrentShow($timeNow) {
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
|
||||
$sql = "SELECT group_id"
|
||||
." FROM $CC_CONFIG[showSchedule]"
|
||||
." WHERE show_id = $showID";
|
||||
|
||||
$timestamp = explode(" ", $timeNow);
|
||||
$date = $timestamp[0];
|
||||
$time = $timestamp[1];
|
||||
|
||||
$sql = "SELECT si.starts as start_timestamp, si.ends as end_timestamp, s.name, s.id"
|
||||
." FROM $CC_CONFIG[showInstances] si, $CC_CONFIG[showTable] s"
|
||||
." WHERE si.show_id = s.id"
|
||||
." AND si.starts <= TIMESTAMP '$timeNow'"
|
||||
." AND si.ends > TIMESTAMP '$timeNow'";
|
||||
|
||||
$rows = $CC_DBC->GetAll($sql);
|
||||
return $rows;
|
||||
}
|
||||
}
|
||||
|
||||
public static function GetNextShow($timeNow) {
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
|
||||
$sql = "SELECT *, si.starts as start_timestamp, si.ends as end_timestamp FROM "
|
||||
." $CC_CONFIG[showInstances] si, $CC_CONFIG[showTable] s"
|
||||
." WHERE si.show_id = s.id"
|
||||
." AND si.starts > TIMESTAMP '$timeNow'"
|
||||
." AND si.starts < TIMESTAMP '$timeNow' + INTERVAL '48 hours'"
|
||||
." ORDER BY si.starts"
|
||||
." LIMIT 1";
|
||||
|
||||
$rows = $CC_DBC->GetAll($sql);
|
||||
return $rows;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -86,7 +86,7 @@ function createDataGrid(){
|
|||
"aaData": datagridData.rows,
|
||||
"aoColumns": columns,
|
||||
"fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
|
||||
if (aData[aData.length-2] != "")
|
||||
if (aData[aData.length-2] == "t")
|
||||
$(nRow).attr("style", "background-color:#166622");
|
||||
if (aData[0] == "c")
|
||||
$(nRow).attr("style", "background-color:#61B329");
|
||||
|
|
Loading…
Reference in New Issue