From e16dd6c486eb9f0baf16c66e296ec3076e73d230 Mon Sep 17 00:00:00 2001 From: martin Date: Sun, 6 Mar 2011 00:08:02 -0500 Subject: [PATCH] early implementation of CC-1962 --- .../controllers/ScheduleController.php | 6 +-- application/models/Schedule.php | 43 ++++++++++++++++--- application/models/Shows.php | 23 +++++++--- application/models/StoredFile.php | 2 +- .../schedule/schedule-show-dialog.phtml | 1 + public/js/airtime/schedule/schedule.js | 9 ++++ public/js/playlist/nowplayingdatagrid.js | 2 +- pypo/scripts/lib.liq | 12 ++++-- 8 files changed, 78 insertions(+), 20 deletions(-) diff --git a/application/controllers/ScheduleController.php b/application/controllers/ScheduleController.php index 2a071ec78..e589f7fe9 100644 --- a/application/controllers/ScheduleController.php +++ b/application/controllers/ScheduleController.php @@ -188,7 +188,7 @@ class ScheduleController extends Zend_Controller_Action $this->view->showContent = $show->getShowContent(); $this->view->timeFilled = $show->getTimeScheduled(); - $this->view->percentFilled = $show->getPercentScheduledInRange(); + $this->view->percentFilled = $show->getPercentScheduled(); $this->view->chosen = $this->view->render('schedule/scheduled-content.phtml'); unset($this->view->showContent); @@ -237,7 +237,7 @@ class ScheduleController extends Zend_Controller_Action $this->view->showContent = $show->getShowContent(); $this->view->timeFilled = $show->getTimeScheduled(); - $this->view->percentFilled = $show->getPercentScheduledInRange(); + $this->view->percentFilled = $show->getPercentScheduled(); $this->view->chosen = $this->view->render('schedule/scheduled-content.phtml'); unset($this->view->showContent); } @@ -268,7 +268,7 @@ class ScheduleController extends Zend_Controller_Action $this->view->timeFilled = $show->getTimeScheduled(); $this->view->showName = $show->getName(); $this->view->showLength = $show->getShowLength(); - $this->view->percentFilled = $show->getPercentScheduledInRange(); + $this->view->percentFilled = $show->getPercentScheduled(); $this->view->s_wday = $dateInfo_s['weekday']; $this->view->s_month = $dateInfo_s['month']; diff --git a/application/models/Schedule.php b/application/models/Schedule.php index f515327e1..ad8d24d3a 100644 --- a/application/models/Schedule.php +++ b/application/models/Schedule.php @@ -278,12 +278,11 @@ class Schedule { return ($count == '0'); } - public static function getTimeUnScheduledInRange($s_datetime, $e_datetime) { + public static function getTimeUnScheduledInRange($instance_id, $s_datetime, $e_datetime) { global $CC_CONFIG, $CC_DBC; - $sql = "SELECT SUM(clip_length) FROM ".$CC_CONFIG["scheduleTable"]." - WHERE (starts >= '{$s_datetime}') - AND (ends <= '{$e_datetime}')"; + $sql = "SELECT SUM(clip_length) FROM $CC_CONFIG[scheduleTable]" + ." WHERE instance_id = $instance_id"; $time = $CC_DBC->GetOne($sql); @@ -313,6 +312,20 @@ class Schedule { return $res; } + + public static function GetTotalShowTime($instance_id) { + global $CC_CONFIG, $CC_DBC; + + $sql = "SELECT SUM(clip_length) FROM $CC_CONFIG[scheduleTable]" + ." WHERE instance_id = $instance_id"; + + $res = $CC_DBC->GetOne($sql); + + if(is_null($res)) + return 0; + + return $res; + } public static function getPercentScheduledInRange($s_datetime, $e_datetime) { @@ -337,6 +350,25 @@ class Schedule { return $percent; } + public static function GetPercentScheduled($instance_id, $s_datetime, $e_datetime){ + $time = Schedule::GetTotalShowTime($instance_id); + + $s_epoch = strtotime($s_datetime); + $e_epoch = strtotime($e_datetime); + + $con = Propel::getConnection(CcSchedulePeer::DATABASE_NAME); + $sql = "SELECT EXTRACT(EPOCH FROM INTERVAL '{$time}')"; + $r = $con->query($sql); + $i_epoch = $r->fetchColumn(0); + + $percent = ceil(($i_epoch / ($e_epoch - $s_epoch)) * 100); + + if ($percent > 100) + $percent = 100; + + return $percent; + } + /** * Return TRUE if file is going to be played in the future. @@ -490,7 +522,8 @@ class Schedule { ." WHERE st.playlist_id = pt.id" ." AND st.file_id = ft.id" ." AND st.instance_id = si.id" - ." AND si.show_id = show.id"; + ." AND si.show_id = show.id" + ." AND st.starts < si.ends"; if ($timePeriod < 0){ $sql .= " AND st.ends < TIMESTAMP '$timeStamp'" diff --git a/application/models/Shows.php b/application/models/Shows.php index 12fa1411b..993c5e84f 100644 --- a/application/models/Shows.php +++ b/application/models/Shows.php @@ -456,6 +456,10 @@ class ShowInstance { return $showInstance->getDbShowId(); } + public function getShowInstanceId() { + return $this->_instanceId; + } + public function getName() { $show = CcShowQuery::create()->findPK($this->getShowId()); return $show->getDbName(); @@ -635,11 +639,8 @@ class ShowInstance { } public function getTimeScheduled() { - - $start_timestamp = $this->getShowStart(); - $end_timestamp = $this->getShowEnd(); - - $time = Schedule::getTimeScheduledInRange($start_timestamp, $end_timestamp); + $instance_id = $this->getShowInstanceId(); + $time = Schedule::GetTotalShowTime($instance_id); return $time; } @@ -648,8 +649,9 @@ class ShowInstance { $start_timestamp = $this->getShowStart(); $end_timestamp = $this->getShowEnd(); + $instance_id = $this->getShowInstanceId(); - $time = Schedule::getTimeUnScheduledInRange($start_timestamp, $end_timestamp); + $time = Schedule::getTimeUnScheduledInRange($instance_id, $start_timestamp, $end_timestamp); return $time; } @@ -662,6 +664,14 @@ class ShowInstance { return Schedule::getPercentScheduledInRange($start_timestamp, $end_timestamp); } + public function getPercentScheduled(){ + $start_timestamp = $this->getShowStart(); + $end_timestamp = $this->getShowEnd(); + $instance_id = $this->getShowInstanceId(); + + return Schedule::GetPercentScheduled($instance_id, $start_timestamp, $end_timestamp); + } + public function getShowLength(){ global $CC_DBC; @@ -794,6 +804,7 @@ class Show_DAL{ ." WHERE ((si.starts < TIMESTAMP '$timeNow' - INTERVAL '$start seconds' AND si.ends > TIMESTAMP '$timeNow' - INTERVAL '$start seconds')" ." OR (si.starts > TIMESTAMP '$timeNow' - INTERVAL '$start seconds' AND si.ends < TIMESTAMP '$timeNow' + INTERVAL '$end seconds')" ." OR (si.starts < TIMESTAMP '$timeNow' + INTERVAL '$end seconds' AND si.ends > TIMESTAMP '$timeNow' + INTERVAL '$end seconds'))" + ." AND (st.starts < si.ends)" ." ORDER BY st.starts"; return $CC_DBC->GetAll($sql); diff --git a/application/models/StoredFile.php b/application/models/StoredFile.php index 72e96dbea..95f7f51ae 100644 --- a/application/models/StoredFile.php +++ b/application/models/StoredFile.php @@ -1671,7 +1671,7 @@ class StoredFile { $fromTable = "cc_playlist AS pl LEFT JOIN cc_playlisttimes AS plt USING(id) LEFT JOIN cc_subjs AS sub ON pl.editedby = sub.id"; - $datatables["optWhere"][] = "plt.length <= INTERVAL '{$p_length}'"; + $datatables["optWhere"][] = "INTERVAL '{$p_length}' > INTERVAL '00:00:00'"; $datatables["optWhere"][] = "plt.length > INTERVAL '00:00:00'"; return StoredFile::searchFiles($fromTable, $datatables); diff --git a/application/views/scripts/schedule/schedule-show-dialog.phtml b/application/views/scripts/schedule/schedule-show-dialog.phtml index c10038bfd..c0a28a984 100644 --- a/application/views/scripts/schedule/schedule-show-dialog.phtml +++ b/application/views/scripts/schedule/schedule-show-dialog.phtml @@ -28,6 +28,7 @@
showLength; ?> +
diff --git a/public/js/airtime/schedule/schedule.js b/public/js/airtime/schedule/schedule.js index 99e5fadf1..5fb842593 100644 --- a/public/js/airtime/schedule/schedule.js +++ b/public/js/airtime/schedule/schedule.js @@ -22,6 +22,15 @@ function setScheduleDialogHtml(json) { $("#show_time_filled").empty().append(json.timeFilled); $("#show_progressbar").progressbar( "value" , json.percentFilled ); + + var showFilled = $("#show_time_filled").text().split('.')[0]; + var showLength = $("#show_length").text(); + + if (showFilled > showLength){ + $("#show_time_warning").text("Shows longer than their scheduled time will be cut off by a following show."); + } else { + $("#show_time_warning").empty(); + } } function setScheduleDialogEvents(dialog) { diff --git a/public/js/playlist/nowplayingdatagrid.js b/public/js/playlist/nowplayingdatagrid.js index 97313278c..b1ca520be 100644 --- a/public/js/playlist/nowplayingdatagrid.js +++ b/public/js/playlist/nowplayingdatagrid.js @@ -60,7 +60,7 @@ var columns = [{"sTitle": "type", "bVisible":false}, {"sTitle":"Album"}, {"sTitle":"Playlist"}, {"sTitle":"Show"}, - {"sTitle":"instance_id", "bVisible":true}]; + {"sTitle":"instance_id", "bVisible":false}]; function getDateString(){ var date0 = $("#datepicker").datepicker("getDate"); diff --git a/pypo/scripts/lib.liq b/pypo/scripts/lib.liq index 68fd55459..384287056 100644 --- a/pypo/scripts/lib.liq +++ b/pypo/scripts/lib.liq @@ -39,10 +39,14 @@ end # by default def add_skip_command(s) # A command to skip - def skip(_) - source.skip(s) - "Done!" - end + def skip(_) + l = list.hd(server.execute("queue.queue")) + l = string.split(separator=" ",l) + list.iter(fun (rid) -> ignore(server.execute(queue.ignore #{rid}")), l) + + source.skip(s) + "Done!" + end # Register the command: server.register(namespace="source", usage="skip",