CC-3174 : showbuilder

only updating the timeline view if it is needed.
This commit is contained in:
Naomi Aro 2012-03-07 12:20:30 +01:00
parent a4d07b3060
commit e9627bca07
7 changed files with 160 additions and 12 deletions

View file

@ -1448,7 +1448,8 @@ class Application_Model_Show {
}
$sql = "SELECT starts, ends, record, rebroadcast, instance_id, show_id, name,
color, background_color, file_id, cc_show_instances.id AS instance_id
color, background_color, file_id, cc_show_instances.id AS instance_id,
last_scheduled
FROM cc_show_instances
LEFT JOIN cc_show ON cc_show.id = cc_show_instances.show_id
WHERE cc_show_instances.modified_instance = FALSE";
@ -1479,6 +1480,9 @@ class Application_Model_Show {
$sql = $sql." AND ({$exclude})";
}
Logging::log("getShows");
Logging::log($sql);
return $CC_DBC->GetAll($sql);
}

View file

@ -6,8 +6,12 @@ require_once 'formatters/TimeFilledFormatter.php';
class Application_Model_ShowBuilder {
private $timezone;
//in UTC timezone
private $startDT;
//in UTC timezone
private $endDT;
private $user;
private $opts;
@ -59,12 +63,12 @@ class Application_Model_ShowBuilder {
$showStartDT = new DateTime($p_item["si_starts"], new DateTimeZone("UTC"));
$schedStartDT = new DateTime($p_item["sched_starts"], new DateTimeZone("UTC"));
$showStartEpoch = intval($showStartDT->format('U'));
$schedStartEpoch = intval($schedStartDT->format('U'));
//can only schedule the show if item hasn't started and you are allowed.
if ($this->epoch_now < max($showStartEpoch, $schedStartEpoch)
if ($this->epoch_now < max($showStartEpoch, $schedStartEpoch)
&& $this->user->canSchedule($p_item["show_id"]) == true) {
$row["allowed"] = true;
}
@ -89,7 +93,7 @@ class Application_Model_ShowBuilder {
}
private function isCurrent($p_epochItemStart, $p_epochItemEnd, &$row) {
if ($this->epoch_now >= $p_epochItemStart && $this->epoch_now < $p_epochItemEnd) {
$row["current"] = true;
//how many seconds the view should wait to redraw itself.
@ -194,6 +198,39 @@ class Application_Model_ShowBuilder {
return $row;
}
/*
* @param int $timestamp Unix timestamp in seconds.
*
* @return boolean whether the schedule in the show builder's range has been updated.
*
*/
public function hasBeenUpdatedSince($timestamp) {
$outdated = false;
Logging::log("checking if show builder has been updated since {$timestamp}");
$shows = Application_Model_Show::getShows($this->startDT, $this->endDT);
foreach ($shows as $show) {
if (isset($show["last_scheduled"])) {
$dt = new DateTime($show["last_scheduled"], new DateTimeZone("UTC"));
//check if any of the shows have a more recent timestamp.
if ($timestamp < intval($dt->format("U"))) {
$outdated = true;
break;
}
}
}
if (count($shows) == 0) {
$outdated = true;
}
return $outdated;
}
public function GetItems() {
$current_id = -1;