From b5863d3d7a43982fea60ed465d775e6fe04510a4 Mon Sep 17 00:00:00 2001 From: Naomi Aro Date: Thu, 26 Apr 2012 12:14:41 +0200 Subject: [PATCH] CC-3522 : Now Playing Screen-> Periodical message pops up --- .../controllers/ShowbuilderController.php | 7 ++-- airtime_mvc/application/forms/ShowBuilder.php | 6 ---- .../application/models/ShowBuilder.php | 15 ++++++-- .../views/scripts/form/showbuilder.phtml | 1 - .../public/js/airtime/showbuilder/builder.js | 36 +++++++++++-------- .../js/airtime/showbuilder/main_builder.js | 1 + 6 files changed, 39 insertions(+), 27 deletions(-) diff --git a/airtime_mvc/application/controllers/ShowbuilderController.php b/airtime_mvc/application/controllers/ShowbuilderController.php index e61838ba6..9339ac087 100644 --- a/airtime_mvc/application/controllers/ShowbuilderController.php +++ b/airtime_mvc/application/controllers/ShowbuilderController.php @@ -238,6 +238,7 @@ class ShowbuilderController extends Zend_Controller_Action $show_filter = intval($request->getParam("showFilter", 0)); $my_shows = intval($request->getParam("myShows", 0)); $timestamp = intval($request->getParam("timestamp", -1)); + $instances = $request->getParam("instances", array()); $startsDT = DateTime::createFromFormat("U", $starts_epoch, new DateTimeZone("UTC")); $endsDT = DateTime::createFromFormat("U", $ends_epoch, new DateTimeZone("UTC")); @@ -247,7 +248,7 @@ class ShowbuilderController extends Zend_Controller_Action //only send the schedule back if updates have been made. // -1 default will always call the schedule to be sent back if no timestamp is defined. - if ($showBuilder->hasBeenUpdatedSince($timestamp)) { + if ($showBuilder->hasBeenUpdatedSince($timestamp, $instances)) { $this->view->update = true; } else { @@ -275,7 +276,9 @@ class ShowbuilderController extends Zend_Controller_Action $opts = array("myShows" => $my_shows, "showFilter" => $show_filter); $showBuilder = new Application_Model_ShowBuilder($startsDT, $endsDT, $opts); - $this->view->schedule = $showBuilder->GetItems(); + $data = $showBuilder->GetItems(); + $this->view->schedule = $data["schedule"]; + $this->view->instances = $data["showInstances"]; $this->view->timestamp = $current_time; $end = microtime(true); diff --git a/airtime_mvc/application/forms/ShowBuilder.php b/airtime_mvc/application/forms/ShowBuilder.php index a5198ec6f..f1e1ed3fa 100644 --- a/airtime_mvc/application/forms/ShowBuilder.php +++ b/airtime_mvc/application/forms/ShowBuilder.php @@ -11,12 +11,6 @@ class Application_Form_ShowBuilder extends Zend_Form_SubForm array('ViewScript', array('viewScript' => 'form/showbuilder.phtml')) )); - //set value to -1 originally to ensure we grab the schedule on first call. - $timestamp = new Zend_Form_Element_Hidden('sb_timestamp'); - $timestamp->setValue(-1) - ->setDecorators(array('ViewHelper')); - $this->addElement($timestamp); - // Add start date element $startDate = new Zend_Form_Element_Text('sb_date_start'); $startDate->class = 'input_text'; diff --git a/airtime_mvc/application/models/ShowBuilder.php b/airtime_mvc/application/models/ShowBuilder.php index f13849094..aab62d3f2 100644 --- a/airtime_mvc/application/models/ShowBuilder.php +++ b/airtime_mvc/application/models/ShowBuilder.php @@ -19,6 +19,8 @@ class Application_Model_ShowBuilder { private $contentDT; private $epoch_now; private $currentShow; + + private $showInstances = array(); private $defaultRowArray = array( "header" => false, @@ -311,11 +313,13 @@ class Application_Model_ShowBuilder { * @return boolean whether the schedule in the show builder's range has been updated. * */ - public function hasBeenUpdatedSince($timestamp) { + public function hasBeenUpdatedSince($timestamp, $instances) { $outdated = false; $shows = Application_Model_Show::getShows($this->startDT, $this->endDT); + $currentInstances = array(); foreach ($shows as $show) { + $currentInstances[] = $show["instance_id"]; if (isset($show["last_scheduled"])) { $dt = new DateTime($show["last_scheduled"], new DateTimeZone("UTC")); @@ -331,7 +335,8 @@ class Application_Model_ShowBuilder { } } - if (count($shows) == 0) { + //see if the displayed show instances have changed. (deleted, empty schedule etc) + if ($outdated === false && count($instances) !== count($currentInstances)) { $outdated = true; } @@ -392,6 +397,10 @@ class Application_Model_ShowBuilder { if (isset($row)) { $display_items[] = $row; } + + if ($current_id !== -1 && !in_array($current_id, $this->showInstances)) { + $this->showInstances[] = $current_id; + } } //make the last footer if there were any scheduled items. @@ -399,6 +408,6 @@ class Application_Model_ShowBuilder { $display_items[] = $this->makeFooterRow($scheduled_items[count($scheduled_items)-1]); } - return $display_items; + return array("schedule" => $display_items, "showInstances" => $this->showInstances); } } diff --git a/airtime_mvc/application/views/scripts/form/showbuilder.phtml b/airtime_mvc/application/views/scripts/form/showbuilder.phtml index 3d7ee8cbf..cb886f3b6 100644 --- a/airtime_mvc/application/views/scripts/form/showbuilder.phtml +++ b/airtime_mvc/application/views/scripts/form/showbuilder.phtml @@ -1,5 +1,4 @@
- element->getElement('sb_timestamp') ?> element->getElement('sb_date_start') ?> element->getElement('sb_time_start') ?> element->getElement('sb_date_end') ?> diff --git a/airtime_mvc/public/js/airtime/showbuilder/builder.js b/airtime_mvc/public/js/airtime/showbuilder/builder.js index 2aafaec03..3b211f9b6 100644 --- a/airtime_mvc/public/js/airtime/showbuilder/builder.js +++ b/airtime_mvc/public/js/airtime/showbuilder/builder.js @@ -19,31 +19,35 @@ var AIRTIME = (function(AIRTIME){ } mod.timeout = undefined; + mod.timestamp = -1; + mod.showInstances = []; mod.resetTimestamp = function() { - var timestamp = $("#sb_timestamp"); - //reset timestamp value since input values could have changed. - timestamp.val(-1); + + mod.timestamp = -1; }; mod.setTimestamp = function(timestamp) { - $("#sb_timestamp").val(timestamp); + + mod.timestamp = timestamp; }; mod.getTimestamp = function() { - var timestamp = $("#sb_timestamp"), - val; - //if the timestamp field is on the page return it, or give the default of -1 - //to ensure a page refresh. - if (timestamp.length === 1) { - val = timestamp.val(); + if (mod.timestamp !== undefined) { + return mod.timestamp; } else { - val = -1; + return -1; } - - return val; + }; + + mod.setShowInstances = function(showInstances) { + mod.showInstances = showInstances; + }; + + mod.getShowInstances = function() { + return mod.showInstances; }; mod.getSelectedData = function() { @@ -117,6 +121,7 @@ var AIRTIME = (function(AIRTIME){ mod.fnServerData = function ( sSource, aoData, fnCallback ) { aoData.push( { name: "timestamp", value: AIRTIME.showbuilder.getTimestamp()} ); + aoData.push( { name: "instances", value: AIRTIME.showbuilder.getShowInstances()} ); aoData.push( { name: "format", value: "json"} ); if (mod.fnServerData.hasOwnProperty("start")) { @@ -130,16 +135,17 @@ var AIRTIME = (function(AIRTIME){ aoData.push( { name: "showFilter", value: mod.fnServerData.ops.showFilter} ); } - $.ajax( { + $.ajax({ "dataType": "json", "type": "POST", "url": sSource, "data": aoData, "success": function(json) { AIRTIME.showbuilder.setTimestamp(json.timestamp); + AIRTIME.showbuilder.setShowInstances(json.instances); fnCallback(json); } - } ); + }); }; mod.builderDataTable = function() { diff --git a/airtime_mvc/public/js/airtime/showbuilder/main_builder.js b/airtime_mvc/public/js/airtime/showbuilder/main_builder.js index 6e46477bf..9301dd42a 100644 --- a/airtime_mvc/public/js/airtime/showbuilder/main_builder.js +++ b/airtime_mvc/public/js/airtime/showbuilder/main_builder.js @@ -218,6 +218,7 @@ AIRTIME = (function(AIRTIME) { data["start"] = start; data["end"] = end; data["timestamp"] = AIRTIME.showbuilder.getTimestamp(); + data["instances"] = AIRTIME.showbuilder.getShowInstances(); if (fn.hasOwnProperty("ops")) { data["myShows"] = fn.ops.myShows;