CC-1665: Scheduled stream rebroadcasting and recording

-code cleanup
This commit is contained in:
Martin Konecny 2012-07-26 17:51:47 -04:00
parent 7cde4ba2ba
commit ebed110429
3 changed files with 67 additions and 69 deletions

View File

@ -75,40 +75,39 @@ class Application_Model_Schedule
global $CC_CONFIG; global $CC_CONFIG;
$con = Propel::getConnection(); $con = Propel::getConnection();
$sql = 'Select ft.artist_name, ft.track_title, st.starts as starts, st.ends as ends, st.media_item_played as media_item_played, si.ends as show_ends $sql = "SELECT %%columns%% st.starts as starts, st.ends as ends, st.media_item_played as media_item_played, si.ends as show_ends
FROM cc_schedule st LEFT JOIN cc_files ft ON st.file_id = ft.id LEFT JOIN cc_show_instances si on st.instance_id = si.id FROM cc_schedule st JOIN %%tables%% LEFT JOIN cc_show_instances si ON st.instance_id = si.id
WHERE '; WHERE ";
/* Alternate SQL...merge conflict and I'm not sure which on is right.... -MK $fileColumns = "ft.artist_name, ft.track_title, ";
$sql = 'Select ft.artist_name, ft.track_title, st.starts as starts, st.ends as ends, st.media_item_played as media_item_played, si.ends as show_ends $streamColumns = "ws.login as artist_name, ws.name as track_title, ";
FROM cc_schedule st LEFT JOIN cc_files ft ON st.file_id = ft.id
WHERE '; $fileJoin = "cc_files ft ON st.file_id = ft.id";
*/ $streamJoin = "cc_webstream ws ON st.stream_id = ws.id";
if (isset($p_previousShowID)) { $predicateArr = array();
if (isset($p_nextShowID) || isset($p_currentShowID)) if (isset($p_previousShowID)) {
$sql .= '('; $predicateArr[] = 'st.instance_id = '.$p_previousShowID;
$sql .= 'st.instance_id = '.$p_previousShowID; }
if (isset($p_currentShowID)) {
$predicateArr[] = 'st.instance_id = '.$p_currentShowID;
}
if (isset($p_nextShowID)) {
$predicateArr[] = 'st.instance_id = '.$p_nextShowID;
} }
if ($p_currentShowID != null) {
if ($p_previousShowID != null) $sql .= " (".implode(" OR ", $predicateArr).") ";
$sql .= ' OR ';
else if($p_nextShowID != null)
$sql .= '(';
$sql .= 'st.instance_id = '.$p_currentShowID;
}
if ($p_nextShowID != null) {
if ($p_previousShowID != null || $p_currentShowID != null)
$sql .= ' OR ';
$sql .= 'st.instance_id = '.$p_nextShowID;
if($p_previousShowID != null || $p_currentShowID != null)
$sql .= ')';
} else if($p_previousShowID != null && $p_currentShowID != null)
$sql .= ')';
$sql .= ' AND st.playout_status > 0 ORDER BY st.starts'; $sql .= ' AND st.playout_status > 0 ORDER BY st.starts';
$filesSql = str_replace("%%columns%%", $fileColumns, $sql);
$filesSql = str_replace("%%tables%%", $fileJoin, $filesSql);
$streamSql = str_replace("%%columns%%", $streamColumns, $sql);
$streamSql = str_replace("%%tables%%", $streamJoin, $streamSql);
$sql = "SELECT * FROM (($filesSql) UNION ($streamSql)) AS unioned ORDER BY starts";
$rows = $con->query($sql)->fetchAll(); $rows = $con->query($sql)->fetchAll();
$numberOfRows = count($rows); $numberOfRows = count($rows);
@ -117,42 +116,44 @@ class Application_Model_Schedule
$results['next'] = null; $results['next'] = null;
$timeNowAsMillis = strtotime($p_timeNow); $timeNowAsMillis = strtotime($p_timeNow);
for ($i = 0; $i < $numberOfRows; ++$i) { for ($i = 0; $i < $numberOfRows; ++$i) {
// if the show is overbooked, then update the track end time to the end of the show time. // if the show is overbooked, then update the track end time to the end of the show time.
if ($rows[$i]['ends'] > $rows[$i]["show_ends"]) { if ($rows[$i]['ends'] > $rows[$i]["show_ends"]) {
$rows[$i]['ends'] = $rows[$i]["show_ends"]; $rows[$i]['ends'] = $rows[$i]["show_ends"];
} }
if ((strtotime($rows[$i]['starts']) <= $timeNowAsMillis) && (strtotime($rows[$i]['ends']) >= $timeNowAsMillis)) {
if ($i - 1 >= 0) {
$results['previous'] = array("name"=>$rows[$i-1]["artist_name"]." - ".$rows[$i-1]["track_title"], if ((strtotime($rows[$i]['starts']) <= $timeNowAsMillis) && (strtotime($rows[$i]['ends']) >= $timeNowAsMillis)) {
"starts"=>$rows[$i-1]["starts"], if ($i - 1 >= 0) {
"ends"=>$rows[$i-1]["ends"], $results['previous'] = array("name"=>$rows[$i-1]["artist_name"]." - ".$rows[$i-1]["track_title"],
"type"=>'track'); "starts"=>$rows[$i-1]["starts"],
} "ends"=>$rows[$i-1]["ends"],
$results['current'] = array("name"=>$rows[$i]["artist_name"]." - ".$rows[$i]["track_title"], "type"=>'track');
"starts"=>$rows[$i]["starts"], }
"ends"=> (($rows[$i]["ends"] > $rows[$i]["show_ends"]) ? $rows[$i]["show_ends"]: $rows[$i]["ends"]), $results['current'] = array("name"=>$rows[$i]["artist_name"]." - ".$rows[$i]["track_title"],
"media_item_played"=>$rows[$i]["media_item_played"], "starts"=>$rows[$i]["starts"],
"record"=>0, "ends"=> (($rows[$i]["ends"] > $rows[$i]["show_ends"]) ? $rows[$i]["show_ends"]: $rows[$i]["ends"]),
"type"=>'track'); "media_item_played"=>$rows[$i]["media_item_played"],
if ( isset($rows[$i+1])) { "record"=>0,
$results['next'] = array("name"=>$rows[$i+1]["artist_name"]." - ".$rows[$i+1]["track_title"], "type"=>'track');
"starts"=>$rows[$i+1]["starts"], if ( isset($rows[$i+1])) {
"ends"=>$rows[$i+1]["ends"], $results['next'] = array("name"=>$rows[$i+1]["artist_name"]." - ".$rows[$i+1]["track_title"],
"type"=>'track'); "starts"=>$rows[$i+1]["starts"],
} "ends"=>$rows[$i+1]["ends"],
break; "type"=>'track');
} }
if (strtotime($rows[$i]['ends']) < $timeNowAsMillis ) { break;
$previousIndex = $i; }
} if (strtotime($rows[$i]['ends']) < $timeNowAsMillis ) {
if (strtotime($rows[$i]['starts']) > $timeNowAsMillis) { $previousIndex = $i;
$results['next'] = array("name"=>$rows[$i]["artist_name"]." - ".$rows[$i]["track_title"], }
"starts"=>$rows[$i]["starts"], if (strtotime($rows[$i]['starts']) > $timeNowAsMillis) {
"ends"=>$rows[$i]["ends"], $results['next'] = array("name"=>$rows[$i]["artist_name"]." - ".$rows[$i]["track_title"],
"type"=>'track'); "starts"=>$rows[$i]["starts"],
break; "ends"=>$rows[$i]["ends"],
} "type"=>'track');
break;
}
} }
//If we didn't find a a current show because the time didn't fit we may still have //If we didn't find a a current show because the time didn't fit we may still have
//found a previous show so use it. //found a previous show so use it.

View File

@ -1,5 +1,4 @@
<button id="spl_new" class="ui-button ui-widget ui-state-default" role="button" aria-disabled="false">New</button> <button id="spl_new" class="ui-button ui-widget ui-state-default" role="button" aria-disabled="false">New</button>
<button id="ws_new" class="ui-button ui-widget ui-state-default" role="button" aria-disabled="false">New Stream</button>
<?php if (isset($this->obj)) : ?> <?php if (isset($this->obj)) : ?>
<button id="spl_delete" class="ui-button ui-widget ui-state-default" role="button" aria-disabled="false">Delete</button> <button id="spl_delete" class="ui-button ui-widget ui-state-default" role="button" aria-disabled="false">Delete</button>
<a href="#" id="spl_crossfade" class="ui-button ui-button-icon-only ui-widget ui-state-default crossfade-main-button"> <a href="#" id="spl_crossfade" class="ui-button ui-button-icon-only ui-widget ui-state-default crossfade-main-button">

View File

@ -796,21 +796,19 @@ var AIRTIME = (function(AIRTIME){
mod.init = function() { mod.init = function() {
$.contextMenu({ $.contextMenu({
selector: '#spl_new', selector: '#spl_new, #ws_new',
trigger: "left", trigger: "left",
ignoreRightClick: true, ignoreRightClick: true,
items: { items: {
"sp": {name: "New Playlist", callback: AIRTIME.playlist.fnNew}, "sp": {name: "New Playlist", callback: AIRTIME.playlist.fnNew},
"sb": {name: "New Smart Playlist", callback: AIRTIME.playlist.fnNewBlock} "sb": {name: "New Smart Playlist", callback: AIRTIME.playlist.fnNewBlock},
"ws": {name: "New Webstream", callback: AIRTIME.playlist.fnWsNew}
} }
}); });
/* /*
$pl.delegate("#spl_new", $pl.delegate("#spl_new",
{"click": AIRTIME.playlist.fnNew});*/ {"click": AIRTIME.playlist.fnNew});*/
$pl.delegate("#ws_new",
{"click": AIRTIME.playlist.fnWsNew});
$pl.delegate("#spl_delete", {"click": function(ev){ $pl.delegate("#spl_delete", {"click": function(ev){
AIRTIME.playlist.fnDelete(); AIRTIME.playlist.fnDelete();
}}); }});