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-01-26 15:21:04 +01:00
|
|
|
class Application_Model_ShowBuilder {
|
|
|
|
|
|
|
|
private $timezone;
|
|
|
|
private $startDT;
|
|
|
|
private $endDT;
|
2012-01-31 18:59:27 +01:00
|
|
|
private $user;
|
2012-02-15 00:39:27 +01:00
|
|
|
private $opts;
|
2012-01-26 15:21:04 +01:00
|
|
|
|
2012-02-13 18:29:39 +01:00
|
|
|
private $contentDT;
|
2012-02-23 17:46:07 +01:00
|
|
|
private $epoch_now;
|
2012-02-13 18:29:39 +01:00
|
|
|
|
2012-01-26 15:21:04 +01:00
|
|
|
private $defaultRowArray = array(
|
|
|
|
"header" => false,
|
|
|
|
"footer" => false,
|
|
|
|
"empty" => false,
|
2012-02-23 17:46:07 +01:00
|
|
|
"allowed" => false,
|
2012-02-06 01:51:22 +01:00
|
|
|
"id" => 0,
|
2012-01-26 15:21:04 +01:00
|
|
|
"instance" => "",
|
|
|
|
"starts" => "",
|
|
|
|
"ends" => "",
|
2012-01-26 19:10:37 +01:00
|
|
|
"runtime" => "",
|
|
|
|
"title" => "",
|
|
|
|
"creator" => "",
|
2012-02-16 16:29:11 +01:00
|
|
|
"album" => "",
|
2012-02-27 21:29:02 +01:00
|
|
|
"timestamp" => null,
|
|
|
|
"cuein" => "",
|
|
|
|
"cueout" => "",
|
|
|
|
"fadein" => "",
|
2012-03-01 17:05:50 +01:00
|
|
|
"fadeout" => "",
|
|
|
|
"current" => false,
|
2012-01-26 15:21:04 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @param DateTime $p_startsDT
|
|
|
|
* @param DateTime $p_endsDT
|
|
|
|
*/
|
2012-02-15 00:39:27 +01:00
|
|
|
public function __construct($p_startDT, $p_endDT, $p_opts) {
|
2012-01-26 15:21:04 +01:00
|
|
|
|
|
|
|
$this->startDT = $p_startDT;
|
|
|
|
$this->endDT = $p_endDT;
|
|
|
|
$this->timezone = date_default_timezone_get();
|
2012-01-31 18:59:27 +01:00
|
|
|
$this->user = Application_Model_User::GetCurrentUser();
|
2012-02-15 00:39:27 +01:00
|
|
|
$this->opts = $p_opts;
|
2012-02-23 17:46:07 +01:00
|
|
|
$this->epoch_now = time();
|
2012-01-26 15:21:04 +01:00
|
|
|
}
|
|
|
|
|
2012-03-01 17:05:50 +01:00
|
|
|
//check to see if this row should be editable.
|
2012-02-23 17:46:07 +01:00
|
|
|
private function isAllowed($p_item, &$row) {
|
|
|
|
|
|
|
|
$showStartDT = new DateTime($p_item["si_starts"], new DateTimeZone("UTC"));
|
|
|
|
|
|
|
|
//can only schedule the show if it hasn't started and you are allowed.
|
|
|
|
if ($this->epoch_now < $showStartDT->format('U') && $this->user->canSchedule($p_item["show_id"]) == true) {
|
|
|
|
$row["allowed"] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-01 15:09:13 +01:00
|
|
|
//information about whether a track is inside|boundary|outside a show.
|
2012-02-23 22:23:21 +01:00
|
|
|
private function getItemStatus($p_item, &$row) {
|
|
|
|
|
2012-03-01 15:09:13 +01:00
|
|
|
$row["status"] = intval($p_item["sched_status"]);
|
2012-02-23 22:23:21 +01:00
|
|
|
}
|
|
|
|
|
2012-02-16 16:29:11 +01:00
|
|
|
private function getRowTimestamp($p_item, &$row) {
|
|
|
|
|
|
|
|
if (is_null($p_item["si_last_scheduled"])) {
|
|
|
|
$ts = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$dt = new DateTime($p_item["si_last_scheduled"], new DateTimeZone("UTC"));
|
|
|
|
$ts = intval($dt->format("U"));
|
|
|
|
}
|
|
|
|
$row["timestamp"] = $ts;
|
|
|
|
}
|
|
|
|
|
2012-03-01 17:05:50 +01:00
|
|
|
private function isCurrent($p_epochItemStart, $p_epochItemEnd) {
|
|
|
|
$current = false;
|
|
|
|
|
|
|
|
if ($this->epoch_now >= $p_epochItemStart && $this->epoch_now < $p_epochItemEnd) {
|
|
|
|
$current = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $current;
|
|
|
|
}
|
|
|
|
|
2012-01-26 15:21:04 +01:00
|
|
|
private function makeHeaderRow($p_item) {
|
|
|
|
|
|
|
|
$row = $this->defaultRowArray;
|
2012-02-23 17:46:07 +01:00
|
|
|
$this->isAllowed($p_item, $row);
|
|
|
|
Logging::log("making header for show id ".$p_item["show_id"]);
|
2012-02-22 22:25:14 +01:00
|
|
|
$this->getRowTimestamp($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));
|
|
|
|
$showEndDT = new DateTime($p_item["si_ends"], new DateTimeZone("UTC"));
|
|
|
|
$showEndDT->setTimezone(new DateTimeZone($this->timezone));
|
|
|
|
|
|
|
|
$row["header"] = true;
|
|
|
|
$row["starts"] = $showStartDT->format("Y-m-d H:i");
|
|
|
|
$row["ends"] = $showEndDT->format("Y-m-d H:i");
|
2012-01-27 21:06:04 +01:00
|
|
|
$row["duration"] = $showEndDT->format("U") - $showStartDT->format("U");
|
2012-01-26 15:21:04 +01:00
|
|
|
$row["title"] = $p_item["show_name"];
|
2012-02-06 01:51:22 +01:00
|
|
|
$row["instance"] = intval($p_item["si_id"]);
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function makeScheduledItemRow($p_item) {
|
|
|
|
$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-02-14 14:44:46 +01:00
|
|
|
|
2012-01-26 15:21:04 +01:00
|
|
|
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-01 17:05:50 +01:00
|
|
|
$startsEpoch = intval($schedStartDT->format("U"));
|
|
|
|
$endsEpoch = intval($schedEndDT->format("U"));
|
|
|
|
$showEndEpoch = intval($showEndDT->format("U"));
|
|
|
|
|
|
|
|
//don't want an overbooked item to stay marked as current.
|
|
|
|
if ($this->isCurrent($startsEpoch, min($endsEpoch, $showEndEpoch))) {
|
|
|
|
$row["current"] = true;
|
|
|
|
}
|
|
|
|
|
2012-01-31 18:59:27 +01:00
|
|
|
$row["id"] = intval($p_item["sched_id"]);
|
|
|
|
$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-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-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
|
|
|
}
|
|
|
|
//show is empty
|
|
|
|
else {
|
2012-02-28 16:57:53 +01:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
return $row;
|
|
|
|
}
|
|
|
|
|
2012-02-28 16:57:53 +01:00
|
|
|
private function makeFooterRow($p_item) {
|
|
|
|
|
|
|
|
$row = $this->defaultRowArray;
|
2012-02-28 20:58:06 +01:00
|
|
|
//$this->isAllowed($p_item, $row);
|
2012-02-28 16:57:53 +01:00
|
|
|
$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;
|
2012-03-01 17:25:37 +01:00
|
|
|
|
|
|
|
$timeFilled = new TimeFilledFormatter($runtime);
|
|
|
|
$row["fRuntime"] = $timeFilled->format();
|
2012-02-28 16:57:53 +01:00
|
|
|
|
|
|
|
return $row;
|
|
|
|
}
|
|
|
|
|
2012-01-26 15:21:04 +01:00
|
|
|
public function GetItems() {
|
|
|
|
|
|
|
|
$current_id = -1;
|
|
|
|
$display_items = array();
|
|
|
|
|
2012-02-15 00:39:27 +01:00
|
|
|
$shows = array();
|
|
|
|
if ($this->opts["myShows"] === 1) {
|
|
|
|
|
|
|
|
$host_shows = CcShowHostsQuery::create()
|
|
|
|
->setFormatter(ModelCriteria::FORMAT_ON_DEMAND)
|
|
|
|
->filterByDbHost($this->user->getId())
|
|
|
|
->find();
|
|
|
|
|
|
|
|
foreach ($host_shows as $host_show) {
|
|
|
|
$shows[] = $host_show->getDbShow();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ($this->opts["showFilter"] !== 0) {
|
|
|
|
$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-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
|
|
|
}
|
|
|
|
|
|
|
|
$display_items[] = $this->makeHeaderRow($item);
|
|
|
|
|
|
|
|
$current_id = $item["si_id"];
|
|
|
|
}
|
|
|
|
|
|
|
|
//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-01-26 15:21:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//make the last footer if there were any scheduled items.
|
|
|
|
if (count($scheduled_items) > 0) {
|
2012-02-13 18:29:39 +01:00
|
|
|
$display_items[] = $this->makeFooterRow($scheduled_items[count($scheduled_items)-1]);
|
2012-01-26 15:21:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return $display_items;
|
|
|
|
}
|
|
|
|
}
|