diff --git a/application/configs/navigation.php b/application/configs/navigation.php index e40c92b0f..9af489d6c 100644 --- a/application/configs/navigation.php +++ b/application/configs/navigation.php @@ -70,6 +70,12 @@ $pages = array( ) ) ), + array( + 'label' => 'Test', + 'module' => 'default', + 'controller' => 'Schedule', + 'action' => 'get-scheduler-time' + ), array( 'label' => 'Schedule', 'module' => 'default', diff --git a/application/controllers/ScheduleController.php b/application/controllers/ScheduleController.php index f25fa8403..a1ee638b4 100644 --- a/application/controllers/ScheduleController.php +++ b/application/controllers/ScheduleController.php @@ -18,7 +18,8 @@ class ScheduleController extends Zend_Controller_Action ->addActionContext('resize-show', 'json') ->addActionContext('delete-show', 'json') ->addActionContext('schedule-show', 'json') - ->addActionContext('clear-show', 'json') + ->addActionContext('clear-show', 'json') + ->addActionContext('get-current-playlist', 'json') ->initContext(); } @@ -174,6 +175,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(); + } } diff --git a/application/models/Schedule.php b/application/models/Schedule.php index b5398809b..f54844024 100644 --- a/application/models/Schedule.php +++ b/application/models/Schedule.php @@ -351,7 +351,7 @@ class Schedule { /** - * Returns array indexed numberically of: + * Returns array indexed by: * "playlistId"/"playlist_id" (aliases to the same thing) * "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 @@ -369,7 +369,7 @@ class Schedule { * @param string $p_toDateTime * In the format YYYY-MM-DD HH:MM:SS.nnnnnn * @param boolean $p_playlistsOnly - * Retreive playlists as a single item. + * Retrieve playlists as a single item. * @return array * Returns empty array if nothing found */ @@ -412,19 +412,94 @@ class Schedule { 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() { } diff --git a/application/views/scripts/schedule/get-current-playlist.phtml b/application/views/scripts/schedule/get-current-playlist.phtml new file mode 100644 index 000000000..789c0e6d5 --- /dev/null +++ b/application/views/scripts/schedule/get-current-playlist.phtml @@ -0,0 +1,3 @@ +entries; +?> diff --git a/application/views/scripts/schedule/get-scheduler-time.phtml b/application/views/scripts/schedule/get-scheduler-time.phtml new file mode 100644 index 000000000..8cff686e4 --- /dev/null +++ b/application/views/scripts/schedule/get-scheduler-time.phtml @@ -0,0 +1,86 @@ +
+ +0% +
diff --git a/public/js/progressbar/images/progressbar.gif b/public/js/progressbar/images/progressbar.gif new file mode 100644 index 000000000..abe588c15 Binary files /dev/null and b/public/js/progressbar/images/progressbar.gif differ diff --git a/public/js/progressbar/images/progressbg_black.gif b/public/js/progressbar/images/progressbg_black.gif new file mode 100644 index 000000000..74fd1f9b3 Binary files /dev/null and b/public/js/progressbar/images/progressbg_black.gif differ diff --git a/public/js/progressbar/images/progressbg_green.gif b/public/js/progressbar/images/progressbg_green.gif new file mode 100644 index 000000000..f3f3bf681 Binary files /dev/null and b/public/js/progressbar/images/progressbg_green.gif differ diff --git a/public/js/progressbar/images/progressbg_orange.gif b/public/js/progressbar/images/progressbg_orange.gif new file mode 100644 index 000000000..808cac7cf Binary files /dev/null and b/public/js/progressbar/images/progressbg_orange.gif differ diff --git a/public/js/progressbar/images/progressbg_red.gif b/public/js/progressbar/images/progressbg_red.gif new file mode 100644 index 000000000..54dfa135f Binary files /dev/null and b/public/js/progressbar/images/progressbg_red.gif differ diff --git a/public/js/progressbar/images/progressbg_yellow.gif b/public/js/progressbar/images/progressbg_yellow.gif new file mode 100644 index 000000000..fdb0dfc98 Binary files /dev/null and b/public/js/progressbar/images/progressbg_yellow.gif differ diff --git a/public/js/progressbar/jquery.progressbar.min.js b/public/js/progressbar/jquery.progressbar.min.js new file mode 100644 index 000000000..4689bc4d2 --- /dev/null +++ b/public/js/progressbar/jquery.progressbar.min.js @@ -0,0 +1,9 @@ + +(function($){$.extend({progressBar:new function(){this.defaults={increment:2,speed:15,showText:true,width:120,boxImage:'/js/progressbar/images/progressbar.gif',barImage:'/js/progressbar/images/progressbg_green.gif',height:12};this.construct=function(arg1,arg2){var argpercentage=null;var argconfig=null;if(arg1!=null){if(!isNaN(arg1)){argpercentage=arg1;if(arg2!=null){argconfig=arg2;}}else{argconfig=arg1;}} +return this.each(function(child){var pb=this;if(argpercentage!=null&&this.bar!=null&&this.config!=null){this.config.tpercentage=argpercentage;if(argconfig!=null) +pb.config=$.extend(this.config,argconfig);}else{var $this=$(this);var config=$.extend({},$.progressBar.defaults,argconfig);var percentage=argpercentage;if(argpercentage==null) +var percentage=$this.html().replace("%","");$this.html("");var bar=document.createElement('img');var text=document.createElement('span');bar.id=this.id+"_percentImage";text.id=this.id+"_percentText";bar.src=config.boxImage;bar.width=config.width;var $bar=$(bar);var $text=$(text);this.bar=$bar;this.ntext=$text;this.config=config;this.config.cpercentage=0;this.config.tpercentage=percentage;$bar.css("width",config.width+"px");$bar.css("height",config.height+"px");$bar.css("background-image","url("+config.barImage+")");$bar.css("padding","0");$bar.css("margin","0");$this.append($bar);$this.append($text);bar.alt=this.tpercentage;bar.title=this.tpercentage;} +var t=setInterval(function(){var config=pb.config;var cpercentage=parseInt(config.cpercentage);var tpercentage=parseInt(config.tpercentage);var increment=parseInt(config.increment);var bar=pb.bar;var text=pb.ntext;var pixels=config.width/100;bar.css("background-position",(((config.width*-1))+(cpercentage*pixels))+'px 50%');if(config.showText) +text.html(" "+Math.round(cpercentage)+"%");if(cpercentage>tpercentage){if(cpercentage-incrementtpercentage){pb.config.cpercentage=tpercentage}else{pb.config.cpercentage+=increment;}} +else{clearInterval(t);}},pb.config.speed);});};}});$.fn.extend({progressBar:$.progressBar.construct});})(jQuery); diff --git a/pypo/pypo-cli.py b/pypo/pypo-cli.py index 3ef5fd095..f57a35a42 100755 --- a/pypo/pypo-cli.py +++ b/pypo/pypo-cli.py @@ -106,7 +106,7 @@ class Global: def selfcheck(self): self.api_client = api_client.api_client_factory(config) if (not self.api_client.is_server_compatible()): - sys.exit() + sys.exit() """