From 4f5b5d85626c68696efd5370fd919c7f8fa15407 Mon Sep 17 00:00:00 2001 From: Naomi Aro Date: Mon, 13 Feb 2012 18:29:39 +0100 Subject: [PATCH] CC-3174 : Show Content Builder adding time filled/empty row data. --- airtime_mvc/application/models/Scheduler.php | 8 +-- .../application/models/ShowBuilder.php | 53 ++++++++++++++++--- .../public/js/airtime/schedule/schedule.js | 2 +- .../public/js/airtime/showbuilder/builder.js | 43 +++++++++------ 4 files changed, 78 insertions(+), 28 deletions(-) diff --git a/airtime_mvc/application/models/Scheduler.php b/airtime_mvc/application/models/Scheduler.php index b34897ae9..2657d2645 100644 --- a/airtime_mvc/application/models/Scheduler.php +++ b/airtime_mvc/application/models/Scheduler.php @@ -68,7 +68,7 @@ class Application_Model_Scheduler { * * @return DateTime endDT in UTC */ - private function findEndTime($p_startDT, $p_duration) { + public static function findEndTime($p_startDT, $p_duration) { $startEpoch = $p_startDT->format("U.u"); $durationSeconds = Application_Model_Playlist::playlistTimeToSeconds($p_duration); @@ -149,7 +149,7 @@ class Application_Model_Scheduler { Logging::log("adding file with id: ".$file["id"]); - $endTimeDT = $this->findEndTime($nextStartDT, $file['cliplength']); + $endTimeDT = self::findEndTime($nextStartDT, $file['cliplength']); //item existed previously and is being moved. //need to keep same id for resources if we want REST. @@ -184,7 +184,7 @@ class Application_Model_Scheduler { Logging::log("adjusting iterm {$item->getDbId()}"); - $endTimeDT = $this->findEndTime($nextStartDT, $item->getDbClipLength()); + $endTimeDT = self::findEndTime($nextStartDT, $item->getDbClipLength()); $item->setDbStarts($nextStartDT); $item->setDbEnds($endTimeDT); @@ -346,7 +346,7 @@ class Application_Model_Scheduler { Logging::log("adjusting item #".$item->getDbId()); - $itemEndDT = $this->findEndTime($itemStartDT, $item->getDbClipLength()); + $itemEndDT = self::findEndTime($itemStartDT, $item->getDbClipLength()); $item->setDbStarts($itemStartDT); $item->setDbEnds($itemEndDT); diff --git a/airtime_mvc/application/models/ShowBuilder.php b/airtime_mvc/application/models/ShowBuilder.php index 136ceea5c..0e398a94f 100644 --- a/airtime_mvc/application/models/ShowBuilder.php +++ b/airtime_mvc/application/models/ShowBuilder.php @@ -7,6 +7,8 @@ class Application_Model_ShowBuilder { private $endDT; private $user; + private $contentDT; + private $defaultRowArray = array( "header" => false, "footer" => false, @@ -15,9 +17,7 @@ class Application_Model_ShowBuilder { "id" => 0, "instance" => "", "starts" => "", - "startsUnix" => null, "ends" => "", - "endsUnix" => null, "runtime" => "", "title" => "", "creator" => "", @@ -56,11 +56,45 @@ class Application_Model_ShowBuilder { return $runtime; } - private function makeFooterRow() { + private function formatTimeFilled($p_sec) { + + $formatted = ""; + $sign = ($p_sec < 0) ? "-" : "+"; + + $time = Application_Model_Playlist::secondsToPlaylistTime(abs($p_sec)); + Logging::log("time is: ".$time); + $info = explode(":", $time); + + $formatted .= $sign; + + if ($info[0] > 0) { + $formatted .= " {$info[0]}h"; + } + + if ($info[1] > 0) { + $formatted .= " {$info[1]}m"; + } + + if ($info[2] > 0) { + $sec = round($info[2], 0); + $formatted .= " {$sec}s"; + } + + return $formatted; + } + + private function makeFooterRow($p_item) { $row = $this->defaultRowArray; $row["footer"] = true; + $showEndDT = new DateTime($p_item["si_ends"], new DateTimeZone("UTC")); + $contentDT = $this->contentDT; + + $runtime = bcsub($contentDT->format("U.u"), $showEndDT->format("U.u"), 6); + $row["runtime"] = $runtime; + $row["fRuntime"] = $this->formatTimeFilled($runtime); + return $row; } @@ -80,6 +114,8 @@ class Application_Model_ShowBuilder { $row["title"] = $p_item["show_name"]; $row["instance"] = intval($p_item["si_id"]); + $this->contentDT = $showStartDT; + return $row; } @@ -107,6 +143,8 @@ class Application_Model_ShowBuilder { $row["title"] = $p_item["file_track_title"]; $row["creator"] = $p_item["file_artist_name"]; $row["album"] = $p_item["file_album_title"]; + + $this->contentDT = $schedEndDT; } //show is empty else { @@ -125,14 +163,17 @@ class Application_Model_ShowBuilder { $scheduled_items = Application_Model_Schedule::GetScheduleDetailItems($this->startDT->format("Y-m-d H:i:s"), $this->endDT->format("Y-m-d H:i:s")); - foreach ($scheduled_items as $item) { + for ($i = 0, $rows = count($scheduled_items); $i < $rows; $i++) { + + $item = $scheduled_items[$i]; //make a header row. if ($current_id !== $item["si_id"]) { //make a footer row. if ($current_id !== -1) { - $display_items[] = $this->makeFooterRow(); + //pass in the previous row as it's the last row for the previous show. + $display_items[] = $this->makeFooterRow($scheduled_items[$i-1]); } $display_items[] = $this->makeHeaderRow($item); @@ -146,7 +187,7 @@ class Application_Model_ShowBuilder { //make the last footer if there were any scheduled items. if (count($scheduled_items) > 0) { - $display_items[] = $this->makeFooterRow(); + $display_items[] = $this->makeFooterRow($scheduled_items[count($scheduled_items)-1]); } return $display_items; diff --git a/airtime_mvc/public/js/airtime/schedule/schedule.js b/airtime_mvc/public/js/airtime/schedule/schedule.js index 88b5aae42..354fbf5bc 100644 --- a/airtime_mvc/public/js/airtime/schedule/schedule.js +++ b/airtime_mvc/public/js/airtime/schedule/schedule.js @@ -362,7 +362,7 @@ function alertShowErrorAndReload(){ window.location.reload(); } -$(window).load(function() { +$(document).ready(function() { $.ajax({ url: "/Api/calendar-init/format/json", dataType:"json", success:createFullCalendar , error:function(jqXHR, textStatus, errorThrown){}}); diff --git a/airtime_mvc/public/js/airtime/showbuilder/builder.js b/airtime_mvc/public/js/airtime/showbuilder/builder.js index fd10c2296..31d598bfd 100644 --- a/airtime_mvc/public/js/airtime/showbuilder/builder.js +++ b/airtime_mvc/public/js/airtime/showbuilder/builder.js @@ -129,12 +129,12 @@ $(document).ready(function() { //save some info for reordering purposes. $(nRow).data({"aData": aData}); - fnPrepareSeparatorRow = function(sRowContent, sClass) { + fnPrepareSeparatorRow = function(sRowContent, sClass, iNodeIndex) { - node = nRow.children[1]; + node = nRow.children[iNodeIndex]; node.innerHTML = sRowContent; node.setAttribute('colspan',100); - for (i = 2; i < nRow.children.length; i = i+1) { + for (i = iNodeIndex + 1; i < nRow.children.length; i = i+1) { node = nRow.children[i]; node.innerHTML = ""; node.setAttribute("style", "display : none"); @@ -144,19 +144,29 @@ $(document).ready(function() { }; if (aData.header === true) { - node = nRow.children[0]; - node.innerHTML = ''; + //node = nRow.children[0]; + //node.innerHTML = ''; + //node.innerHTML = ''; sSeparatorHTML = ''+aData.title+''+aData.starts+''+aData.ends+''; - fnPrepareSeparatorRow(sSeparatorHTML, "sb-header"); + fnPrepareSeparatorRow(sSeparatorHTML, "sb-header", 0); } else if (aData.footer === true) { - + var c, node = nRow.children[0]; - node.innerHTML = ''; + + //check the show's content status. + if (aData.runtime > 0) { + node.innerHTML = ''; + cl = 'ui-state-highlight'; + } + else { + node.innerHTML = ''; + cl = 'ui-state-error'; + } - sSeparatorHTML = 'Show Footer'; - fnPrepareSeparatorRow(sSeparatorHTML, "sb-footer"); + sSeparatorHTML = ''+aData.fRuntime+''; + fnPrepareSeparatorRow(sSeparatorHTML, cl, 1); } else if (aData.empty === true) { @@ -164,7 +174,7 @@ $(document).ready(function() { node.innerHTML = ''; sSeparatorHTML = 'Show Empty'; - fnPrepareSeparatorRow(sSeparatorHTML, "sb-empty odd"); + fnPrepareSeparatorRow(sSeparatorHTML, "sb-empty odd", 1); } else { $(nRow).attr("id", "sched_"+aData.id); @@ -272,7 +282,7 @@ $(document).ready(function() { }, // R = ColReorderResize, C = ColVis, T = TableTools - "sDom": 'Rr<"H"CT<"#show_builder_toolbar">>t<"F">', + "sDom": 'Rr<"H"CT>t<"F">', "sAjaxDataProp": "schedule", "sAjaxSource": "/showbuilder/builder-feed" @@ -383,15 +393,14 @@ $(document).ready(function() { update: fnUpdate, start: function(event, ui) { //ui.placeholder.html("PLACE HOLDER"); - }, + } }; }()); tableDiv.sortable(sortableConf); - $("#show_builder_toolbar") - .append('') - .find(".ui-icon-trash") - .click(fnRemoveSelectedItems); + $("#show_builder .fg-toolbar") + .append('
') + .click(fnRemoveSelectedItems); });