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 @@