Commit so that I may access project from a different computer. Many things do not work/ are incomplete!!!
-Added unfinalized API for getting schedule and currently playing item.
This commit is contained in:
parent
afd9f80f59
commit
10218aeeb5
6 changed files with 190 additions and 10 deletions
|
@ -58,6 +58,12 @@ $pages = array(
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
|
array(
|
||||||
|
'label' => 'Test',
|
||||||
|
'module' => 'default',
|
||||||
|
'controller' => 'Schedule',
|
||||||
|
'action' => 'get-scheduler-time'
|
||||||
|
),
|
||||||
array(
|
array(
|
||||||
'label' => 'Schedule',
|
'label' => 'Schedule',
|
||||||
'module' => 'default',
|
'module' => 'default',
|
||||||
|
|
|
@ -18,7 +18,8 @@ class ScheduleController extends Zend_Controller_Action
|
||||||
->addActionContext('resize-show', 'json')
|
->addActionContext('resize-show', 'json')
|
||||||
->addActionContext('delete-show', 'json')
|
->addActionContext('delete-show', 'json')
|
||||||
->addActionContext('schedule-show', 'json')
|
->addActionContext('schedule-show', 'json')
|
||||||
->addActionContext('clear-show', 'json')
|
->addActionContext('clear-show', 'json')
|
||||||
|
->addActionContext('get-current-playlist', 'json')
|
||||||
->initContext();
|
->initContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -173,6 +174,15 @@ class ScheduleController extends Zend_Controller_Action
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getSchedulerTimeAction()
|
||||||
|
{
|
||||||
|
$this->view->headScript()->appendFile('/js/progressbar/jquery.progressbar.min.js','text/javascript');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCurrentPlaylistAction()
|
||||||
|
{
|
||||||
|
$this->view->entries = Schedule::GetPlayOrderRange();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -351,7 +351,7 @@ class Schedule {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns array indexed numberically of:
|
* Returns array indexed by:
|
||||||
* "playlistId"/"playlist_id" (aliases to the same thing)
|
* "playlistId"/"playlist_id" (aliases to the same thing)
|
||||||
* "start"/"starts" (aliases to the same thing) as YYYY-MM-DD HH:MM:SS.nnnnnn
|
* "start"/"starts" (aliases to the same thing) as YYYY-MM-DD HH:MM:SS.nnnnnn
|
||||||
* "end"/"ends" (aliases to the same thing) as YYYY-MM-DD HH:MM:SS.nnnnnn
|
* "end"/"ends" (aliases to the same thing) as YYYY-MM-DD HH:MM:SS.nnnnnn
|
||||||
|
@ -369,7 +369,7 @@ class Schedule {
|
||||||
* @param string $p_toDateTime
|
* @param string $p_toDateTime
|
||||||
* In the format YYYY-MM-DD HH:MM:SS.nnnnnn
|
* In the format YYYY-MM-DD HH:MM:SS.nnnnnn
|
||||||
* @param boolean $p_playlistsOnly
|
* @param boolean $p_playlistsOnly
|
||||||
* Retreive playlists as a single item.
|
* Retrieve playlists as a single item.
|
||||||
* @return array
|
* @return array
|
||||||
* Returns empty array if nothing found
|
* Returns empty array if nothing found
|
||||||
*/
|
*/
|
||||||
|
@ -412,19 +412,94 @@ class Schedule {
|
||||||
return $rows;
|
return $rows;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getSchedulerTime() {
|
|
||||||
|
/**
|
||||||
|
* Returns the date of the server in the format
|
||||||
|
* "YYYY-MM-DD HH:mm:SS".
|
||||||
|
*
|
||||||
|
* Note: currently assuming that Web Server and Scheduler are on the
|
||||||
|
* same host.
|
||||||
|
*
|
||||||
|
* @return date Current server time.
|
||||||
|
*/
|
||||||
|
public static function GetSchedulerTime() {
|
||||||
|
return date("Y-m-d H:i:s");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCurrentlyPlaying() {
|
/**
|
||||||
|
* Returns current playlist.
|
||||||
|
*
|
||||||
|
* Note: Total playlist length is prev + next + 1
|
||||||
|
*
|
||||||
|
* @param int $prev
|
||||||
|
* @param int $next
|
||||||
|
* @return date
|
||||||
|
*/
|
||||||
|
public static function GetPlayOrderRange($prev = 1, $next = 1) {
|
||||||
|
if (!is_int($prev) || !is_int($next)){
|
||||||
|
//must enter integers to specify ranges
|
||||||
|
return "{}";
|
||||||
|
}
|
||||||
|
|
||||||
|
$timeNow = Schedule::GetSchedulerTime();
|
||||||
|
$currentSong = Schedule::getCurrentlyPlaying();
|
||||||
|
return array("schedulerTime"=>$timeNow,"previous"=>Schedule::getPreviousItems($timeNow),
|
||||||
|
"current"=>Schedule::getCurrentlyPlaying($timeNow),
|
||||||
|
"next"=>Schedule::getNextItems($timeNow));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getNextItem($nextCount = 1) {
|
private static function GetPreviousItems($timeNow, $prevCount = 1){
|
||||||
|
global $CC_CONFIG, $CC_DBC;
|
||||||
|
$sql = "SELECT * FROM ".$CC_CONFIG["scheduleTable"]
|
||||||
|
." WHERE (starts < TIMESTAMP '$timeNow')"
|
||||||
|
." ORDER BY id"
|
||||||
|
." LIMIT $prevCount";
|
||||||
|
$rows = $CC_DBC->GetAll($sql);
|
||||||
|
foreach ($rows as &$row) {
|
||||||
|
$row["count"] = "1";
|
||||||
|
$row["playlistId"] = $row["playlist_id"];
|
||||||
|
$row["start"] = $row["starts"];
|
||||||
|
$row["end"] = $row["ends"];
|
||||||
|
$row["id"] = $row["group_id"];
|
||||||
|
}
|
||||||
|
return $rows;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getStatus() {
|
private static function GetCurrentlyPlaying($timeNow){
|
||||||
|
global $CC_CONFIG, $CC_DBC;
|
||||||
|
|
||||||
|
$sql = "SELECT * FROM ".$CC_CONFIG["scheduleTable"]
|
||||||
|
." WHERE (starts < TIMESTAMP '$timeNow') "
|
||||||
|
." AND (ends > TIMESTAMP '$timeNow')";
|
||||||
|
$rows = $CC_DBC->GetAll($sql);
|
||||||
|
foreach ($rows as &$row) {
|
||||||
|
$row["count"] = "1";
|
||||||
|
$row["playlistId"] = $row["playlist_id"];
|
||||||
|
$row["start"] = $row["starts"];
|
||||||
|
$row["end"] = $row["ends"];
|
||||||
|
$row["id"] = $row["group_id"];
|
||||||
|
}
|
||||||
|
return $rows;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function GetNextItems($timeNow, $nextCount = 1) {
|
||||||
|
global $CC_CONFIG, $CC_DBC;
|
||||||
|
$sql = "SELECT * FROM ".$CC_CONFIG["scheduleTable"]
|
||||||
|
." WHERE (starts > TIMESTAMP '$timeNow')"
|
||||||
|
." ORDER BY id"
|
||||||
|
." LIMIT $nextCount";
|
||||||
|
$rows = $CC_DBC->GetAll($sql);
|
||||||
|
foreach ($rows as &$row) {
|
||||||
|
$row["count"] = "1";
|
||||||
|
$row["playlistId"] = $row["playlist_id"];
|
||||||
|
$row["start"] = $row["starts"];
|
||||||
|
$row["end"] = $row["ends"];
|
||||||
|
$row["id"] = $row["group_id"];
|
||||||
|
}
|
||||||
|
return $rows;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function GetStatus() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
<?php
|
||||||
|
echo $this->entries;
|
||||||
|
?>
|
86
application/views/scripts/schedule/get-scheduler-time.phtml
Normal file
86
application/views/scripts/schedule/get-scheduler-time.phtml
Normal file
|
@ -0,0 +1,86 @@
|
||||||
|
<div>
|
||||||
|
<script>
|
||||||
|
function convertDateToPosixTime(s){
|
||||||
|
var year = s.substring(0, 4);
|
||||||
|
var month = s.substring(5, 7);
|
||||||
|
var day = s.substring(8, 10);
|
||||||
|
var hour = s.substring(11, 13);
|
||||||
|
var minute = s.substring(14, 16);
|
||||||
|
var sec = s.substring(17);
|
||||||
|
|
||||||
|
return Date.UTC(year, month, day, hour, minute, sec, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
var schedulePosixTime;
|
||||||
|
|
||||||
|
var currentSong;
|
||||||
|
var nextSong;
|
||||||
|
|
||||||
|
var updatedSchedule = false;
|
||||||
|
|
||||||
|
function secondsTimer(){
|
||||||
|
schedulePosixTime += 1000;
|
||||||
|
updateProgressBarValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateProgressBarValue(){
|
||||||
|
var percentDone = (schedulePosixTime - currentSong.songStartPosixTime)/currentSong.songLengthMs*100;
|
||||||
|
if (percentDone <= 100){
|
||||||
|
$('#spaceused1').progressBar(percentDone);
|
||||||
|
setTimeout(secondsTimer, 1000);
|
||||||
|
|
||||||
|
if (!updatedSchedule && (currentSong.songEndPosixTime - schedulePosixTime < 5000)){
|
||||||
|
updatedSchedule = true;
|
||||||
|
getScheduleFromServer();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
currentSong = nextSong;
|
||||||
|
updatedSchedule = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getCurrentPlayingItem(currentItem){
|
||||||
|
var clipLength = currentItem.clip_length;
|
||||||
|
var clHours = parseInt(clipLength.substring(0, 2));
|
||||||
|
var clMinutes = parseInt(clipLength.substring(3, 5));
|
||||||
|
var clSeconds = parseInt(clipLength.substring(6, 8));
|
||||||
|
var clMs = parseInt(clipLength.substring(9));
|
||||||
|
|
||||||
|
var songLengthMs = clMs + clSeconds*1000 + clMinutes*60*1000 + clHours*60*60*1000;
|
||||||
|
var songStartPosixTime = convertDateToPosixTime(currentItem.starts);
|
||||||
|
var songEndPosixTime = convertDateToPosixTime(currentItem.ends);
|
||||||
|
|
||||||
|
return {songLengthMs:songLengthMs, songStartPosixTime:songStartPosixTime, songEndPosixTime:songEndPosixTime};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function prepareNextPlayingItem(obj){
|
||||||
|
if (obj.next.length > 0){
|
||||||
|
var nextItem = obj.next[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseItems(obj){
|
||||||
|
schedulePosixTime = convertDateToPosixTime(obj.schedulerTime);
|
||||||
|
if (obj.current.length > 0){
|
||||||
|
currentSong = getCurrentPlayingItem(obj.current[0]);
|
||||||
|
}
|
||||||
|
if (obj.next.length > 0){
|
||||||
|
nextSong = getCurrentPlayingItem(obj.next[0]);
|
||||||
|
}
|
||||||
|
updateProgressBarValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
function getScheduleFromServer(){
|
||||||
|
$.ajax({ url: "/Schedule/get-current-playlist/format/json", dataType:"json", success:function(data){
|
||||||
|
parseItems(data.entries);
|
||||||
|
}});
|
||||||
|
}
|
||||||
|
|
||||||
|
$(document).ready(function() {
|
||||||
|
$("#spaceused1").progressBar();
|
||||||
|
getScheduleFromServer();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
<span class="progressBar" id="spaceused1">0%</span>
|
||||||
|
</div>
|
|
@ -106,7 +106,7 @@ class Global:
|
||||||
def selfcheck(self):
|
def selfcheck(self):
|
||||||
self.api_client = api_client.api_client_factory(config)
|
self.api_client = api_client.api_client_factory(config)
|
||||||
if (not self.api_client.is_server_compatible()):
|
if (not self.api_client.is_server_compatible()):
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue