2012-01-26 15:21:04 +01:00
|
|
|
<?php
|
|
|
|
|
2012-02-24 16:05:01 +01:00
|
|
|
require_once 'formatters/LengthFormatter.php';
|
2012-03-01 17:25:37 +01:00
|
|
|
require_once 'formatters/TimeFilledFormatter.php';
|
2012-02-24 16:05:01 +01:00
|
|
|
|
2012-07-16 03:17:13 +02:00
|
|
|
class Application_Model_ShowBuilder
|
|
|
|
{
|
2012-01-26 15:21:04 +01:00
|
|
|
private $timezone;
|
2012-03-07 12:20:30 +01:00
|
|
|
|
|
|
|
//in UTC timezone
|
2012-01-26 15:21:04 +01:00
|
|
|
private $startDT;
|
2012-03-07 12:20:30 +01:00
|
|
|
//in UTC timezone
|
2012-01-26 15:21:04 +01:00
|
|
|
private $endDT;
|
2012-03-07 12:20:30 +01:00
|
|
|
|
2012-01-31 18:59:27 +01:00
|
|
|
private $user;
|
2012-02-15 00:39:27 +01:00
|
|
|
private $opts;
|
2012-07-11 00:51:32 +02:00
|
|
|
|
2012-03-27 16:27:43 +02:00
|
|
|
private $pos;
|
2012-02-13 18:29:39 +01:00
|
|
|
private $contentDT;
|
2012-02-23 17:46:07 +01:00
|
|
|
private $epoch_now;
|
2012-04-02 15:20:13 +02:00
|
|
|
private $currentShow;
|
2012-07-11 00:51:32 +02:00
|
|
|
|
2012-04-26 12:14:41 +02:00
|
|
|
private $showInstances = array();
|
2012-07-11 00:51:32 +02:00
|
|
|
|
2012-01-26 15:21:04 +01:00
|
|
|
private $defaultRowArray = array(
|
2012-09-17 23:49:16 +02:00
|
|
|
"header" => false,
|
|
|
|
"footer" => false,
|
|
|
|
"empty" => false,
|
|
|
|
"allowed" => false,
|
|
|
|
"id" => 0,
|
|
|
|
"instance" => "",
|
|
|
|
"starts" => "",
|
|
|
|
"ends" => "",
|
|
|
|
"runtime" => "",
|
|
|
|
"title" => "",
|
|
|
|
"creator" => "",
|
|
|
|
"album" => "",
|
|
|
|
"timestamp" => null,
|
|
|
|
"cuein" => "",
|
|
|
|
"cueout" => "",
|
|
|
|
"fadein" => "",
|
|
|
|
"fadeout" => "",
|
|
|
|
"image" => false,
|
|
|
|
"color" => "", //in hex without the '#' sign.
|
|
|
|
"backgroundColor" => "", //in hex without the '#' sign.
|
2012-01-26 15:21:04 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @param DateTime $p_startsDT
|
|
|
|
* @param DateTime $p_endsDT
|
|
|
|
*/
|
2012-07-16 03:17:13 +02:00
|
|
|
public function __construct($p_startDT, $p_endDT, $p_opts)
|
|
|
|
{
|
2012-09-17 23:49:25 +02:00
|
|
|
$this->startDT = $p_startDT;
|
|
|
|
$this->endDT = $p_endDT;
|
|
|
|
$this->timezone = date_default_timezone_get();
|
|
|
|
$this->user = Application_Model_User::getCurrentUser();
|
|
|
|
$this->opts = $p_opts;
|
|
|
|
$this->epoch_now = floatval(microtime(true));
|
2012-04-02 15:20:13 +02:00
|
|
|
$this->currentShow = false;
|
2012-01-26 15:21:04 +01:00
|
|
|
}
|
2012-07-11 00:51:32 +02:00
|
|
|
|
2012-07-16 03:17:13 +02:00
|
|
|
private function getUsersShows()
|
|
|
|
{
|
2012-05-24 17:33:15 +02:00
|
|
|
$shows = array();
|
2012-07-11 00:51:32 +02:00
|
|
|
|
2012-07-16 03:17:13 +02:00
|
|
|
$host_shows = CcShowHostsQuery::create()
|
|
|
|
->setFormatter(ModelCriteria::FORMAT_ON_DEMAND)
|
|
|
|
->filterByDbHost($this->user->getId())
|
|
|
|
->find();
|
|
|
|
|
|
|
|
foreach ($host_shows as $host_show) {
|
|
|
|
$shows[] = $host_show->getDbShow();
|
2012-05-24 17:33:15 +02:00
|
|
|
}
|
2012-07-11 00:51:32 +02:00
|
|
|
|
2012-05-24 17:33:15 +02:00
|
|
|
return $shows;
|
|
|
|
}
|
2012-01-26 15:21:04 +01:00
|
|
|
|
2012-03-26 19:08:52 +02:00
|
|
|
//check to see if this row should be editable by the user.
|
2012-07-16 03:17:13 +02:00
|
|
|
private function isAllowed($p_item, &$row)
|
|
|
|
{
|
2012-03-01 17:49:11 +01:00
|
|
|
//cannot schedule in a recorded show.
|
|
|
|
if (intval($p_item["si_record"]) === 1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-07-11 00:51:32 +02:00
|
|
|
if ($this->user->canSchedule($p_item["show_id"]) == true) {
|
2012-02-23 17:46:07 +01:00
|
|
|
$row["allowed"] = true;
|
2012-07-11 00:51:32 +02:00
|
|
|
}
|
2012-02-23 17:46:07 +01:00
|
|
|
}
|
2012-07-11 00:51:32 +02:00
|
|
|
|
2012-07-16 03:17:13 +02:00
|
|
|
private function getItemColor($p_item, &$row)
|
|
|
|
{
|
2012-03-22 18:04:22 +01:00
|
|
|
$defaultColor = "ffffff";
|
|
|
|
$defaultBackground = "3366cc";
|
2012-07-11 00:51:32 +02:00
|
|
|
|
2012-03-22 18:04:22 +01:00
|
|
|
$color = $p_item["show_color"];
|
|
|
|
if ($color === '') {
|
|
|
|
$color = $defaultColor;
|
|
|
|
}
|
|
|
|
$backgroundColor = $p_item["show_background_color"];
|
|
|
|
if ($backgroundColor === '') {
|
|
|
|
$backgroundColor = $defaultBackground;
|
|
|
|
}
|
2012-07-11 00:51:32 +02:00
|
|
|
|
2012-03-22 18:04:22 +01:00
|
|
|
$row["color"] = $color;
|
|
|
|
$row["backgroundColor"] = $backgroundColor;
|
|
|
|
}
|
2012-02-23 17:46:07 +01:00
|
|
|
|
2012-03-01 15:09:13 +01:00
|
|
|
//information about whether a track is inside|boundary|outside a show.
|
2012-07-16 03:17:13 +02:00
|
|
|
private function getItemStatus($p_item, &$row)
|
|
|
|
{
|
2012-03-02 12:22:08 +01:00
|
|
|
$row["status"] = intval($p_item["playout_status"]);
|
2012-02-23 22:23:21 +01:00
|
|
|
}
|
|
|
|
|
2012-07-16 03:17:13 +02:00
|
|
|
private function getRowTimestamp($p_item, &$row)
|
|
|
|
{
|
2012-02-16 16:29:11 +01:00
|
|
|
if (is_null($p_item["si_last_scheduled"])) {
|
|
|
|
$ts = 0;
|
2012-07-16 03:17:13 +02:00
|
|
|
} else {
|
2012-02-16 16:29:11 +01:00
|
|
|
$dt = new DateTime($p_item["si_last_scheduled"], new DateTimeZone("UTC"));
|
|
|
|
$ts = intval($dt->format("U"));
|
|
|
|
}
|
|
|
|
$row["timestamp"] = $ts;
|
|
|
|
}
|
2012-07-11 00:51:32 +02:00
|
|
|
|
2012-03-22 18:04:22 +01:00
|
|
|
/*
|
|
|
|
* marks a row's status.
|
|
|
|
* 0 = past
|
|
|
|
* 1 = current
|
|
|
|
* 2 = future
|
|
|
|
*/
|
2012-07-16 03:17:13 +02:00
|
|
|
private function getScheduledStatus($p_epochItemStart, $p_epochItemEnd, &$row)
|
|
|
|
{
|
2012-03-22 18:04:22 +01:00
|
|
|
if ($row["footer"] === true && $this->epoch_now > $p_epochItemStart && $this->epoch_now > $p_epochItemEnd) {
|
|
|
|
$row["scheduled"] = 0;
|
2012-07-16 03:17:13 +02:00
|
|
|
} elseif ($row["footer"] === true && $this->epoch_now < $p_epochItemEnd) {
|
|
|
|
$row["scheduled"] = 2;
|
|
|
|
} elseif ($row["header"] === true && $this->epoch_now >= $p_epochItemStart) {
|
2012-03-22 18:04:22 +01:00
|
|
|
$row["scheduled"] = 0;
|
2012-07-16 03:17:13 +02:00
|
|
|
} elseif ($row["header"] === true && $this->epoch_now < $p_epochItemEnd) {
|
|
|
|
$row["scheduled"] = 2;
|
2012-03-22 18:04:22 +01:00
|
|
|
}
|
2012-07-11 00:51:32 +02:00
|
|
|
|
2012-03-22 18:04:22 +01:00
|
|
|
//item is in the past.
|
2012-07-16 03:17:13 +02:00
|
|
|
else if ($this->epoch_now > $p_epochItemEnd) {
|
|
|
|
$row["scheduled"] = 0;
|
2012-03-22 18:04:22 +01:00
|
|
|
}
|
2012-07-16 03:17:13 +02:00
|
|
|
|
|
|
|
//item is the currently scheduled item.
|
|
|
|
else if ($this->epoch_now >= $p_epochItemStart && $this->epoch_now < $p_epochItemEnd) {
|
|
|
|
$row["scheduled"] = 1;
|
|
|
|
//how many seconds the view should wait to redraw itself.
|
|
|
|
$row["refresh"] = $p_epochItemEnd - $this->epoch_now;
|
2012-03-01 17:05:50 +01:00
|
|
|
}
|
2012-07-11 00:51:32 +02:00
|
|
|
|
2012-07-16 03:17:13 +02:00
|
|
|
//item is in the future.
|
|
|
|
else if ($this->epoch_now < $p_epochItemStart) {
|
|
|
|
$row["scheduled"] = 2;
|
|
|
|
}
|
2012-03-01 17:05:50 +01:00
|
|
|
}
|
|
|
|
|
2012-07-16 03:17:13 +02:00
|
|
|
private function makeHeaderRow($p_item)
|
|
|
|
{
|
2012-01-26 15:21:04 +01:00
|
|
|
$row = $this->defaultRowArray;
|
2012-02-23 17:46:07 +01:00
|
|
|
$this->isAllowed($p_item, $row);
|
2012-02-22 22:25:14 +01:00
|
|
|
$this->getRowTimestamp($p_item, $row);
|
2012-03-26 19:08:52 +02:00
|
|
|
$this->getItemColor($p_item, $row);
|
2012-01-26 15:21:04 +01:00
|
|
|
|
|
|
|
$showStartDT = new DateTime($p_item["si_starts"], new DateTimeZone("UTC"));
|
|
|
|
$showStartDT->setTimezone(new DateTimeZone($this->timezone));
|
2012-03-27 14:11:36 +02:00
|
|
|
$startsEpoch = floatval($showStartDT->format("U.u"));
|
2012-01-26 15:21:04 +01:00
|
|
|
$showEndDT = new DateTime($p_item["si_ends"], new DateTimeZone("UTC"));
|
|
|
|
$showEndDT->setTimezone(new DateTimeZone($this->timezone));
|
2012-03-27 14:11:36 +02:00
|
|
|
$endsEpoch = floatval($showEndDT->format("U.u"));
|
2012-07-11 00:51:32 +02:00
|
|
|
|
2012-07-16 03:17:13 +02:00
|
|
|
//is a rebroadcast show
|
|
|
|
if (intval($p_item["si_rebroadcast"]) === 1) {
|
2012-04-20 13:03:50 +02:00
|
|
|
$row["rebroadcast"] = true;
|
2012-07-11 00:51:32 +02:00
|
|
|
|
2012-04-20 13:03:50 +02:00
|
|
|
$parentInstance = CcShowInstancesQuery::create()->findPk($p_item["parent_show"]);
|
|
|
|
$name = $parentInstance->getCcShow()->getDbName();
|
|
|
|
$dt = $parentInstance->getDbStarts(null);
|
|
|
|
$dt->setTimezone(new DateTimeZone($this->timezone));
|
|
|
|
$time = $dt->format("Y-m-d H:i");
|
2012-07-11 00:51:32 +02:00
|
|
|
|
2012-07-16 03:17:13 +02:00
|
|
|
$row["rebroadcast_title"] = "Rebroadcast of {$name} from {$time}";
|
|
|
|
} elseif (intval($p_item["si_record"]) === 1) {
|
2012-04-20 13:03:50 +02:00
|
|
|
$row["record"] = true;
|
2012-07-11 00:51:32 +02:00
|
|
|
|
2012-05-14 15:06:56 +02:00
|
|
|
if (Application_Model_Preference::GetUploadToSoundcloudOption()) {
|
2012-09-17 23:39:41 +02:00
|
|
|
Logging::info('$p_item contains:');
|
|
|
|
Logging::info($p_item);
|
|
|
|
$file = Application_Model_StoredFile::Recall(
|
|
|
|
$p_item['si_file_id']);
|
2012-05-14 15:08:56 +02:00
|
|
|
if (isset($file)) {
|
2012-07-16 03:17:13 +02:00
|
|
|
$sid = $file->getSoundCloudId();
|
2012-09-17 23:39:41 +02:00
|
|
|
$row['soundcloud_id'] = $sid;
|
2012-07-11 00:51:32 +02:00
|
|
|
}
|
2012-05-14 15:06:56 +02:00
|
|
|
}
|
2012-04-20 13:03:50 +02:00
|
|
|
}
|
2012-07-11 00:51:32 +02:00
|
|
|
|
2012-04-02 15:20:13 +02:00
|
|
|
if ($startsEpoch < $this->epoch_now && $endsEpoch > $this->epoch_now) {
|
|
|
|
$row["currentShow"] = true;
|
|
|
|
$this->currentShow = true;
|
2012-07-16 03:17:13 +02:00
|
|
|
} else {
|
2012-04-02 15:20:13 +02:00
|
|
|
$this->currentShow = false;
|
|
|
|
}
|
2012-01-26 15:21:04 +01:00
|
|
|
|
2012-09-17 23:39:41 +02:00
|
|
|
$row["header"] = true;
|
|
|
|
$row["starts"] = $showStartDT->format("Y-m-d H:i");
|
2012-04-03 16:11:53 +02:00
|
|
|
$row["startDate"] = $showStartDT->format("Y-m-d");
|
|
|
|
$row["startTime"] = $showStartDT->format("H:i");
|
2012-09-17 23:39:41 +02:00
|
|
|
$row["refresh"] = floatval($showStartDT->format("U.u")) - $this->epoch_now;
|
|
|
|
$row["ends"] = $showEndDT->format("Y-m-d H:i");
|
|
|
|
$row["endDate"] = $showEndDT->format("Y-m-d");
|
|
|
|
$row["endTime"] = $showEndDT->format("H:i");
|
|
|
|
$row["duration"] = floatval($showEndDT->format("U.u")) - floatval($showStartDT->format("U.u"));
|
|
|
|
$row["title"] = $p_item["show_name"];
|
|
|
|
$row["instance"] = intval($p_item["si_id"]);
|
|
|
|
$row["image"] = '';
|
2012-07-11 00:51:32 +02:00
|
|
|
|
2012-03-22 18:04:22 +01:00
|
|
|
$this->getScheduledStatus($startsEpoch, $endsEpoch, $row);
|
2012-01-26 15:21:04 +01:00
|
|
|
|
2012-02-13 18:29:39 +01:00
|
|
|
$this->contentDT = $showStartDT;
|
|
|
|
|
2012-01-26 15:21:04 +01:00
|
|
|
return $row;
|
|
|
|
}
|
|
|
|
|
2012-07-16 03:17:13 +02:00
|
|
|
private function makeScheduledItemRow($p_item)
|
|
|
|
{
|
2012-01-26 15:21:04 +01:00
|
|
|
$row = $this->defaultRowArray;
|
|
|
|
|
|
|
|
if (isset($p_item["sched_starts"])) {
|
|
|
|
|
|
|
|
$schedStartDT = new DateTime($p_item["sched_starts"], new DateTimeZone("UTC"));
|
|
|
|
$schedStartDT->setTimezone(new DateTimeZone($this->timezone));
|
|
|
|
$schedEndDT = new DateTime($p_item["sched_ends"], new DateTimeZone("UTC"));
|
|
|
|
$schedEndDT->setTimezone(new DateTimeZone($this->timezone));
|
2012-03-01 17:05:50 +01:00
|
|
|
$showEndDT = new DateTime($p_item["si_ends"], new DateTimeZone("UTC"));
|
2012-01-26 15:21:04 +01:00
|
|
|
|
2012-02-23 22:23:21 +01:00
|
|
|
$this->getItemStatus($p_item, $row);
|
|
|
|
|
2012-03-27 14:11:36 +02:00
|
|
|
$startsEpoch = floatval($schedStartDT->format("U.u"));
|
|
|
|
$endsEpoch = floatval($schedEndDT->format("U.u"));
|
|
|
|
$showEndEpoch = floatval($showEndDT->format("U.u"));
|
2012-03-01 17:05:50 +01:00
|
|
|
|
|
|
|
//don't want an overbooked item to stay marked as current.
|
2012-03-22 18:04:22 +01:00
|
|
|
$this->getScheduledStatus($startsEpoch, min($endsEpoch, $showEndEpoch), $row);
|
2012-03-01 17:05:50 +01:00
|
|
|
|
2012-01-31 18:59:27 +01:00
|
|
|
$row["id"] = intval($p_item["sched_id"]);
|
2012-04-24 22:46:51 +02:00
|
|
|
$row["image"] = $p_item["file_exists"];
|
2012-01-31 18:59:27 +01:00
|
|
|
$row["instance"] = intval($p_item["si_id"]);
|
2012-01-26 19:10:37 +01:00
|
|
|
$row["starts"] = $schedStartDT->format("H:i:s");
|
|
|
|
$row["ends"] = $schedEndDT->format("H:i:s");
|
2012-07-11 00:51:32 +02:00
|
|
|
|
2012-02-24 16:05:01 +01:00
|
|
|
$formatter = new LengthFormatter($p_item['file_length']);
|
|
|
|
$row['runtime'] = $formatter->format();
|
|
|
|
|
2012-01-26 15:21:04 +01:00
|
|
|
$row["title"] = $p_item["file_track_title"];
|
2012-01-26 19:10:37 +01:00
|
|
|
$row["creator"] = $p_item["file_artist_name"];
|
|
|
|
$row["album"] = $p_item["file_album_title"];
|
2012-02-13 18:29:39 +01:00
|
|
|
|
2012-02-27 21:29:02 +01:00
|
|
|
$row["cuein"] = $p_item["cue_in"];
|
|
|
|
$row["cueout"] = $p_item["cue_out"];
|
2012-02-27 21:40:04 +01:00
|
|
|
$row["fadein"] = round(substr($p_item["fade_in"], 6), 6);
|
|
|
|
$row["fadeout"] = round(substr($p_item["fade_out"], 6), 6);
|
2012-07-11 00:51:32 +02:00
|
|
|
|
2012-03-27 16:27:43 +02:00
|
|
|
$row["pos"] = $this->pos++;
|
2012-02-27 21:29:02 +01:00
|
|
|
|
2012-02-13 18:29:39 +01:00
|
|
|
$this->contentDT = $schedEndDT;
|
2012-01-26 15:21:04 +01:00
|
|
|
}
|
2012-03-01 17:49:11 +01:00
|
|
|
//show is empty or is a special kind of show (recording etc)
|
|
|
|
else if (intval($p_item["si_record"]) === 1) {
|
|
|
|
$row["record"] = true;
|
2012-05-07 14:28:21 +02:00
|
|
|
$row["instance"] = intval($p_item["si_id"]);
|
2012-07-11 00:51:32 +02:00
|
|
|
|
2012-05-07 15:24:06 +02:00
|
|
|
$showStartDT = new DateTime($p_item["si_starts"], new DateTimeZone("UTC"));
|
|
|
|
$showEndDT = new DateTime($p_item["si_ends"], new DateTimeZone("UTC"));
|
2012-07-11 00:51:32 +02:00
|
|
|
|
2012-07-16 03:17:13 +02:00
|
|
|
$startsEpoch = floatval($showStartDT->format("U.u"));
|
2012-05-07 15:24:06 +02:00
|
|
|
$endsEpoch = floatval($showEndDT->format("U.u"));
|
2012-07-16 03:17:13 +02:00
|
|
|
|
2012-05-07 15:24:06 +02:00
|
|
|
$this->getScheduledStatus($startsEpoch, $endsEpoch, $row);
|
2012-07-16 03:17:13 +02:00
|
|
|
} else {
|
2012-01-26 15:21:04 +01:00
|
|
|
$row["empty"] = true;
|
2012-02-01 18:47:08 +01:00
|
|
|
$row["id"] = 0 ;
|
|
|
|
$row["instance"] = intval($p_item["si_id"]);
|
2012-01-26 15:21:04 +01:00
|
|
|
}
|
2012-07-11 00:51:32 +02:00
|
|
|
|
2012-07-16 03:17:13 +02:00
|
|
|
if (intval($p_item["si_rebroadcast"]) === 1) {
|
|
|
|
$row["rebroadcast"] = true;
|
2012-04-20 13:03:50 +02:00
|
|
|
}
|
2012-07-16 03:17:13 +02:00
|
|
|
|
2012-05-07 14:28:21 +02:00
|
|
|
if ($this->currentShow === true) {
|
2012-04-02 15:20:13 +02:00
|
|
|
$row["currentShow"] = true;
|
|
|
|
}
|
2012-07-16 03:17:13 +02:00
|
|
|
|
|
|
|
$this->getItemColor($p_item, $row);
|
|
|
|
$this->getRowTimestamp($p_item, $row);
|
2012-03-26 19:08:52 +02:00
|
|
|
$this->isAllowed($p_item, $row);
|
2012-01-26 15:21:04 +01:00
|
|
|
|
|
|
|
return $row;
|
|
|
|
}
|
|
|
|
|
2012-07-16 03:17:13 +02:00
|
|
|
private function makeFooterRow($p_item)
|
|
|
|
{
|
2012-02-28 16:57:53 +01:00
|
|
|
$row = $this->defaultRowArray;
|
|
|
|
$row["footer"] = true;
|
2012-03-19 14:48:11 +01:00
|
|
|
$row["instance"] = intval($p_item["si_id"]);
|
|
|
|
$this->getRowTimestamp($p_item, $row);
|
2012-02-28 16:57:53 +01:00
|
|
|
|
|
|
|
$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;
|
2012-03-01 17:25:37 +01:00
|
|
|
|
|
|
|
$timeFilled = new TimeFilledFormatter($runtime);
|
|
|
|
$row["fRuntime"] = $timeFilled->format();
|
2012-07-11 00:51:32 +02:00
|
|
|
|
2012-07-16 03:17:13 +02:00
|
|
|
$showStartDT = new DateTime($p_item["si_starts"], new DateTimeZone("UTC"));
|
|
|
|
$showStartDT->setTimezone(new DateTimeZone($this->timezone));
|
|
|
|
$startsEpoch = floatval($showStartDT->format("U.u"));
|
|
|
|
$showEndDT = new DateTime($p_item["si_ends"], new DateTimeZone("UTC"));
|
|
|
|
$showEndDT->setTimezone(new DateTimeZone($this->timezone));
|
2012-03-30 14:45:30 +02:00
|
|
|
$endsEpoch = floatval($showEndDT->format("U.u"));
|
2012-07-11 00:51:32 +02:00
|
|
|
|
2012-07-16 03:17:13 +02:00
|
|
|
$row["refresh"] = floatval($showEndDT->format("U.u")) - $this->epoch_now;
|
2012-07-11 00:51:32 +02:00
|
|
|
|
2012-07-16 03:17:13 +02:00
|
|
|
if ($this->currentShow === true) {
|
|
|
|
$row["currentShow"] = true;
|
2012-04-02 15:20:13 +02:00
|
|
|
}
|
2012-07-16 03:17:13 +02:00
|
|
|
|
2012-03-26 19:08:52 +02:00
|
|
|
$this->getScheduledStatus($startsEpoch, $endsEpoch, $row);
|
2012-07-16 03:17:13 +02:00
|
|
|
$this->isAllowed($p_item, $row);
|
2012-07-11 00:51:32 +02:00
|
|
|
|
2012-02-28 16:57:53 +01:00
|
|
|
return $row;
|
|
|
|
}
|
|
|
|
|
2012-03-07 12:20:30 +01:00
|
|
|
/*
|
|
|
|
* @param int $timestamp Unix timestamp in seconds.
|
|
|
|
*
|
|
|
|
* @return boolean whether the schedule in the show builder's range has been updated.
|
|
|
|
*
|
|
|
|
*/
|
2012-07-16 03:17:13 +02:00
|
|
|
public function hasBeenUpdatedSince($timestamp, $instances)
|
|
|
|
{
|
2012-03-07 12:20:30 +01:00
|
|
|
$outdated = false;
|
|
|
|
$shows = Application_Model_Show::getShows($this->startDT, $this->endDT);
|
2012-07-11 00:51:32 +02:00
|
|
|
|
2012-05-24 17:33:15 +02:00
|
|
|
if ($this->opts["showFilter"] !== 0) {
|
|
|
|
$include[] = $this->opts["showFilter"];
|
2012-07-16 03:17:13 +02:00
|
|
|
} elseif ($this->opts["myShows"] === 1) {
|
2012-05-24 17:33:15 +02:00
|
|
|
|
|
|
|
$include = $this->getUsersShows();
|
|
|
|
}
|
2012-07-11 00:51:32 +02:00
|
|
|
|
|
|
|
|
2012-04-26 12:14:41 +02:00
|
|
|
$currentInstances = array();
|
2012-03-07 12:20:30 +01:00
|
|
|
|
|
|
|
foreach ($shows as $show) {
|
2012-07-11 00:51:32 +02:00
|
|
|
|
2012-05-24 17:33:15 +02:00
|
|
|
if (empty($include) || in_array($show["show_id"], $include)) {
|
|
|
|
$currentInstances[] = $show["instance_id"];
|
2012-07-11 00:51:32 +02:00
|
|
|
|
2012-05-24 17:33:15 +02:00
|
|
|
if (isset($show["last_scheduled"])) {
|
|
|
|
$dt = new DateTime($show["last_scheduled"], new DateTimeZone("UTC"));
|
2012-07-16 03:17:13 +02:00
|
|
|
} else {
|
2012-05-24 17:33:15 +02:00
|
|
|
$dt = new DateTime($show["created"], new DateTimeZone("UTC"));
|
|
|
|
}
|
2012-07-11 00:51:32 +02:00
|
|
|
|
2012-05-24 17:33:15 +02:00
|
|
|
//check if any of the shows have a more recent timestamp.
|
2012-07-16 03:17:13 +02:00
|
|
|
$showTimeStamp = intval($dt->format("U"));
|
2012-05-24 17:33:15 +02:00
|
|
|
if ($timestamp < $showTimeStamp) {
|
2012-07-16 03:17:13 +02:00
|
|
|
Logging::debug("timestamp is {$timestamp} show timestamp is {$showTimeStamp}");
|
|
|
|
$outdated = true;
|
|
|
|
break;
|
2012-05-24 17:33:15 +02:00
|
|
|
}
|
2012-03-07 12:20:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-26 12:14:41 +02:00
|
|
|
//see if the displayed show instances have changed. (deleted, empty schedule etc)
|
|
|
|
if ($outdated === false && count($instances) !== count($currentInstances)) {
|
2012-05-24 17:33:15 +02:00
|
|
|
Logging::debug("show instances have changed.");
|
2012-03-07 12:20:30 +01:00
|
|
|
$outdated = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $outdated;
|
|
|
|
}
|
|
|
|
|
2012-09-07 22:50:33 +02:00
|
|
|
public function getItems()
|
2012-07-16 03:17:13 +02:00
|
|
|
{
|
2012-01-26 15:21:04 +01:00
|
|
|
$current_id = -1;
|
|
|
|
$display_items = array();
|
|
|
|
|
2012-02-15 00:39:27 +01:00
|
|
|
$shows = array();
|
|
|
|
if ($this->opts["myShows"] === 1) {
|
|
|
|
|
2012-05-24 17:33:15 +02:00
|
|
|
$shows = $this->getUsersShows();
|
2012-07-16 03:17:13 +02:00
|
|
|
} elseif ($this->opts["showFilter"] !== 0) {
|
2012-02-15 00:39:27 +01:00
|
|
|
$shows[] = $this->opts["showFilter"];
|
|
|
|
}
|
|
|
|
|
|
|
|
$scheduled_items = Application_Model_Schedule::GetScheduleDetailItems($this->startDT->format("Y-m-d H:i:s"), $this->endDT->format("Y-m-d H:i:s"), $shows);
|
2012-01-26 15:21:04 +01:00
|
|
|
|
2012-02-13 18:29:39 +01:00
|
|
|
for ($i = 0, $rows = count($scheduled_items); $i < $rows; $i++) {
|
|
|
|
|
|
|
|
$item = $scheduled_items[$i];
|
2012-07-11 00:51:32 +02:00
|
|
|
|
2012-03-26 19:08:52 +02:00
|
|
|
//don't send back data for filler rows.
|
|
|
|
if (isset($item["playout_status"]) && $item["playout_status"] < 0) {
|
|
|
|
continue;
|
|
|
|
}
|
2012-01-26 15:21:04 +01:00
|
|
|
|
|
|
|
//make a header row.
|
|
|
|
if ($current_id !== $item["si_id"]) {
|
|
|
|
|
|
|
|
//make a footer row.
|
|
|
|
if ($current_id !== -1) {
|
2012-02-13 18:29:39 +01:00
|
|
|
//pass in the previous row as it's the last row for the previous show.
|
|
|
|
$display_items[] = $this->makeFooterRow($scheduled_items[$i-1]);
|
2012-01-26 15:21:04 +01:00
|
|
|
}
|
2012-07-11 00:51:32 +02:00
|
|
|
|
2012-01-26 15:21:04 +01:00
|
|
|
$display_items[] = $this->makeHeaderRow($item);
|
|
|
|
|
|
|
|
$current_id = $item["si_id"];
|
2012-07-11 00:51:32 +02:00
|
|
|
|
2012-03-27 16:27:43 +02:00
|
|
|
$this->pos = 1;
|
2012-01-26 15:21:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//make a normal data row.
|
2012-02-23 17:46:07 +01:00
|
|
|
$row = $this->makeScheduledItemRow($item);
|
|
|
|
//don't display the empty rows.
|
|
|
|
if (isset($row)) {
|
|
|
|
$display_items[] = $row;
|
|
|
|
}
|
2012-07-16 03:17:13 +02:00
|
|
|
|
|
|
|
if ($current_id !== -1 && !in_array($current_id, $this->showInstances)) {
|
|
|
|
$this->showInstances[] = $current_id;
|
2012-04-26 12:14:41 +02:00
|
|
|
}
|
2012-01-26 15:21:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//make the last footer if there were any scheduled items.
|
|
|
|
if (count($scheduled_items) > 0) {
|
2012-09-17 23:04:49 +02:00
|
|
|
$display_items[] = $this->makeFooterRow($scheduled_items[
|
|
|
|
count($scheduled_items)-1]);
|
2012-01-26 15:21:04 +01:00
|
|
|
}
|
2012-07-11 00:51:32 +02:00
|
|
|
|
2012-09-17 23:04:49 +02:00
|
|
|
return array(
|
|
|
|
"schedule" => $display_items,
|
|
|
|
"showInstances" => $this->showInstances);
|
2012-01-26 15:21:04 +01:00
|
|
|
}
|
2012-03-25 18:57:20 +02:00
|
|
|
}
|