CC-1805: Ability to edit a show

-All cases for "When" tab should be covered for editing shows.
This commit is contained in:
martin 2011-04-12 11:54:24 -04:00
parent 64124175c5
commit ea11e0114a
1 changed files with 276 additions and 253 deletions

View File

@ -2,11 +2,11 @@
class Show {
private $_showId;
private $_showId;
public function __construct($showId=NULL)
public function __construct($showId=NULL)
{
$this->_showId = $showId;
$this->_showId = $showId;
}
public function getName()
@ -93,7 +93,7 @@ class Show {
$sql = "SELECT first_name, last_name
FROM cc_show_hosts LEFT JOIN cc_subjs ON cc_show_hosts.subjs_id = cc_subjs.id
WHERE show_id = {$this->_showId}";
WHERE show_id = {$this->_showId}";
$hosts = $CC_DBC->GetAll($sql);
@ -116,7 +116,7 @@ class Show {
->update(array('DbLastShow' => $timeinfo[0]));
$sql = "DELETE FROM cc_show_instances
WHERE starts >= '{$day_timestamp}' AND show_id = {$this->_showId}";
WHERE starts >= '{$day_timestamp}' AND show_id = {$this->_showId}";
$CC_DBC->query($sql);
RabbitMq::PushSchedule();
@ -138,6 +138,7 @@ class Show {
$showId = $this->getId();
$sql = "DELETE FROM cc_show_instances"
." WHERE EXTRACT(DOW FROM starts) IN ($uncheckedDaysImploded)"
." AND starts > current_timestamp "
." AND show_id = $showId";
$CC_DBC->query($sql);
@ -251,11 +252,24 @@ class Show {
$showId = $this->getId();
$sql = "DELETE FROM cc_show_instances "
."WHERE date(starts) > DATE '$p_date' "
."AND starts > current_timestamp "
."AND show_id = $showId";
$CC_DBC->query($sql);
}
public function removeAllInstancesBeforeDate($p_date){
global $CC_DBC;
$showId = $this->getId();
$sql = "DELETE FROM cc_show_instances "
."WHERE date(starts) < DATE '$p_date' "
."AND starts > current_timestamp "
."AND show_id = $showId";
$CC_DBC->query($sql);
}
public function getStartDate(){
global $CC_DBC;
@ -288,12 +302,13 @@ class Show {
}
}
public function getAllInstanceIds(){
public function getAllFutureInstanceIds(){
global $CC_DBC;
$showId = $this->getId();
$sql = "SELECT id from cc_show_instances "
." WHERE show_id = $showId";
." WHERE show_id = $showId"
." AND starts > current_timestamp";
$rows = $CC_DBC->GetAll($sql);
@ -316,7 +331,8 @@ class Show {
$sql = "UPDATE cc_show_instances "
."SET ends = starts + INTERVAL '$p_data[add_show_duration]' "
."WHERE show_id = $p_data[add_show_id]";
."WHERE show_id = $p_data[add_show_id] "
."AND starts > current_timestamp";
$CC_DBC->query($sql);
}
@ -344,10 +360,11 @@ class Show {
$sql = "UPDATE cc_show_instances "
."SET starts = starts + INTERVAL '$diff sec', "
."ends = ends + INTERVAL '$diff sec' "
."WHERE show_id = $p_data[add_show_id]";
."WHERE show_id = $p_data[add_show_id] "
."AND starts > current_timestamp";
$CC_DBC->query($sql);
$showInstanceIds = $this->getAllInstanceIds();
$showInstanceIds = $this->getAllFutureInstanceIds();
if (count($showInstanceIds) > 0 && $diff != 0){
$showIdsImploded = implode(",", $showInstanceIds);
$sql = "UPDATE cc_schedule "
@ -409,6 +426,12 @@ class Show {
if ($p_data['add_show_start_date'] != $p_show->getStartDate()
|| $p_data['add_show_start_time'] != $p_show->getStartTime()){
//start date/time has changed
$newDate = strtotime($p_data['add_show_start_date']);
$oldDate = strtotime($p_show->getStartDate());
if ($newDate > $oldDate){
$p_show->removeAllInstancesBeforeDate($p_data['add_show_start_date']);
}
$p_show->updateStartDateTime($p_data, $p_endDate);
}
@ -475,32 +498,32 @@ class Show {
* Show ID
*/
public static function create($data)
{
$con = Propel::getConnection(CcShowPeer::DATABASE_NAME);
{
$con = Propel::getConnection(CcShowPeer::DATABASE_NAME);
$sql = "SELECT EXTRACT(DOW FROM TIMESTAMP '{$data['add_show_start_date']} {$data['add_show_start_time']}')";
$r = $con->query($sql);
$sql = "SELECT EXTRACT(DOW FROM TIMESTAMP '{$data['add_show_start_date']} {$data['add_show_start_time']}')";
$r = $con->query($sql);
$startDow = $r->fetchColumn(0);
if ($data['add_show_no_end']) {
$endDate = NULL;
$data['add_show_repeats'] = 1;
}
else if ($data['add_show_repeats']) {
$sql = "SELECT date '{$data['add_show_end_date']}' + INTERVAL '1 day' ";
$r = $con->query($sql);
$endDate = $r->fetchColumn(0);
}
else {
$sql = "SELECT date '{$data['add_show_start_date']}' + INTERVAL '1 day' ";
$r = $con->query($sql);
$endDate = $r->fetchColumn(0);
}
if ($data['add_show_no_end']) {
$endDate = NULL;
$data['add_show_repeats'] = 1;
}
else if ($data['add_show_repeats']) {
$sql = "SELECT date '{$data['add_show_end_date']}' + INTERVAL '1 day' ";
$r = $con->query($sql);
$endDate = $r->fetchColumn(0);
}
else {
$sql = "SELECT date '{$data['add_show_start_date']}' + INTERVAL '1 day' ";
$r = $con->query($sql);
$endDate = $r->fetchColumn(0);
}
//only want the day of the week from the start date.
if (!$data['add_show_repeats']) {
$data['add_show_day_check'] = array($startDow);
}
if (!$data['add_show_repeats']) {
$data['add_show_day_check'] = array($startDow);
}
else if ($data['add_show_repeats'] && $data['add_show_day_check'] == "") {
$data['add_show_day_check'] = array($startDow);
}
@ -518,13 +541,13 @@ class Show {
} else {
$ccShow = CcShowQuery::create()->findPK($data['add_show_id']);
}
$ccShow->setDbName($data['add_show_name']);
$ccShow->setDbDescription($data['add_show_description']);
$ccShow->setDbName($data['add_show_name']);
$ccShow->setDbDescription($data['add_show_description']);
$ccShow->setDbUrl($data['add_show_url']);
$ccShow->setDbGenre($data['add_show_genre']);
$ccShow->setDbColor($data['add_show_color']);
$ccShow->setDbBackgroundColor($data['add_show_background_color']);
$ccShow->save();
$ccShow->setDbColor($data['add_show_color']);
$ccShow->setDbBackgroundColor($data['add_show_background_color']);
$ccShow->save();
$isRecorded = ($data['add_show_record']) ? 1 : 0;
@ -544,45 +567,45 @@ class Show {
//don't set day for monthly repeat type, it's invalid.
if ($data['add_show_repeats'] && $data['add_show_repeat_type'] == 2) {
$showDay = new CcShowDays();
$showDay->setDbFirstShow($data['add_show_start_date']);
$showDay->setDbLastShow($endDate);
$showDay->setDbStartTime($data['add_show_start_time']);
$showDay->setDbDuration($data['add_show_duration']);
$showDay->setDbFirstShow($data['add_show_start_date']);
$showDay->setDbLastShow($endDate);
$showDay->setDbStartTime($data['add_show_start_time']);
$showDay->setDbDuration($data['add_show_duration']);
$showDay->setDbRepeatType($repeat_type);
$showDay->setDbShowId($showId);
$showDay->setDbShowId($showId);
$showDay->setDbRecord($isRecorded);
$showDay->save();
$showDay->save();
}
else {
foreach ($data['add_show_day_check'] as $day) {
if ($startDow !== $day){
if ($startDow !== $day){
if ($startDow > $day)
$daysAdd = 6 - $startDow + 1 + $day;
else
$daysAdd = $day - $startDow;
if ($startDow > $day)
$daysAdd = 6 - $startDow + 1 + $day;
else
$daysAdd = $day - $startDow;
$sql = "SELECT date '{$data['add_show_start_date']}' + INTERVAL '{$daysAdd} day' ";
$r = $con->query($sql);
$start = $r->fetchColumn(0);
}
else {
$start = $data['add_show_start_date'];
}
$sql = "SELECT date '{$data['add_show_start_date']}' + INTERVAL '{$daysAdd} day' ";
$r = $con->query($sql);
$start = $r->fetchColumn(0);
}
else {
$start = $data['add_show_start_date'];
}
if (strtotime($start) < strtotime($endDate) || is_null($endDate)) {
$showDay = new CcShowDays();
$showDay->setDbFirstShow($start);
$showDay->setDbLastShow($endDate);
$showDay->setDbStartTime($data['add_show_start_time']);
$showDay->setDbDuration($data['add_show_duration']);
$showDay->setDbDay($day);
$showDay = new CcShowDays();
$showDay->setDbFirstShow($start);
$showDay->setDbLastShow($endDate);
$showDay->setDbStartTime($data['add_show_start_time']);
$showDay->setDbDuration($data['add_show_duration']);
$showDay->setDbDay($day);
$showDay->setDbRepeatType($repeat_type);
$showDay->setDbShowId($showId);
$showDay->setDbShowId($showId);
$showDay->setDbRecord($isRecorded);
$showDay->save();
$showDay->save();
}
}
}
}
//check if we are adding or updating a show, and if updating
@ -610,8 +633,8 @@ class Show {
if ($data['add_show_rebroadcast_absolute_date_'.$i]) {
$sql = "SELECT date '{$data['add_show_rebroadcast_absolute_date_'.$i]}' - date '{$data['add_show_start_date']}' ";
$r = $con->query($sql);
$offset_days = $r->fetchColumn(0);
$r = $con->query($sql);
$offset_days = $r->fetchColumn(0);
$showRebroad = new CcShowRebroadcast();
$showRebroad->setDbDayOffset($offset_days." days");
@ -629,18 +652,18 @@ class Show {
}
if (is_array($data['add_show_hosts'])) {
//add selected hosts to cc_show_hosts table.
foreach ($data['add_show_hosts'] as $host) {
$showHost = new CcShowHosts();
$showHost->setDbShow($showId);
$showHost->setDbHost($host);
$showHost->save();
}
foreach ($data['add_show_hosts'] as $host) {
$showHost = new CcShowHosts();
$showHost->setDbShow($showId);
$showHost->setDbHost($host);
$showHost->save();
}
}
Show::populateShowUntil($showId);
RabbitMq::PushSchedule();
return $showId;
}
}
/**
* Get all the show instances in the given time range.
@ -694,7 +717,7 @@ class Show {
$sql = $sql." AND ({$exclude})";
}
return $CC_DBC->GetAll($sql);
return $CC_DBC->GetAll($sql);
}
private static function setNextPop($next_date, $show_id, $day)
@ -722,7 +745,7 @@ class Show {
$start = $next_date;
$sql = "SELECT timestamp '{$start}' + interval '{$duration}'";
$end = $CC_DBC->GetOne($sql);
$end = $CC_DBC->GetOne($sql);
$show = new Show($show_id);
if ($show->hasInstance()){
@ -742,17 +765,17 @@ class Show {
$show_instance_id = $showInstance->getDbId();
$sql = "SELECT * FROM cc_show_rebroadcast WHERE show_id={$show_id}";
$rebroadcasts = $CC_DBC->GetAll($sql);
$rebroadcasts = $CC_DBC->GetAll($sql);
foreach($rebroadcasts as $rebroadcast) {
$timeinfo = explode(" ", $start);
$sql = "SELECT timestamp '{$timeinfo[0]}' + interval '{$rebroadcast["day_offset"]}' + interval '{$rebroadcast["start_time"]}'";
$rebroadcast_start_time = $CC_DBC->GetOne($sql);
$rebroadcast_start_time = $CC_DBC->GetOne($sql);
$sql = "SELECT timestamp '{$rebroadcast_start_time}' + interval '{$duration}'";
$rebroadcast_end_time = $CC_DBC->GetOne($sql);
$rebroadcast_end_time = $CC_DBC->GetOne($sql);
$newRebroadcastInstance = new CcShowInstances();
$newRebroadcastInstance->setDbShowId($show_id);
@ -761,7 +784,7 @@ class Show {
$newRebroadcastInstance->setDbRecord(0);
$newRebroadcastInstance->setDbRebroadcast(1);
$newRebroadcastInstance->setDbOriginalShow($show_instance_id);
$newRebroadcastInstance->save();
$newRebroadcastInstance->save();
}
}
RabbitMq::PushSchedule();
@ -781,7 +804,7 @@ class Show {
}
$sql = "SELECT * FROM cc_show_rebroadcast WHERE show_id={$show_id}";
$rebroadcasts = $CC_DBC->GetAll($sql);
$rebroadcasts = $CC_DBC->GetAll($sql);
$show = new Show($show_id);
while(strtotime($next_date) < strtotime($end_timestamp) && (strtotime($last_show) > strtotime($next_date) || is_null($last_show))) {
@ -789,7 +812,7 @@ class Show {
$start = $next_date;
$sql = "SELECT timestamp '{$start}' + interval '{$duration}'";
$end = $CC_DBC->GetOne($sql);
$end = $CC_DBC->GetOne($sql);
if ($show->hasInstanceOnDate($start)){
$showInstance = $show->getInstanceOnDate($start);
@ -811,10 +834,10 @@ class Show {
$timeinfo = explode(" ", $next_date);
$sql = "SELECT timestamp '{$timeinfo[0]}' + interval '{$rebroadcast["day_offset"]}' + interval '{$rebroadcast["start_time"]}'";
$rebroadcast_start_time = $CC_DBC->GetOne($sql);
$rebroadcast_start_time = $CC_DBC->GetOne($sql);
$sql = "SELECT timestamp '{$rebroadcast_start_time}' + interval '{$duration}'";
$rebroadcast_end_time = $CC_DBC->GetOne($sql);
$rebroadcast_end_time = $CC_DBC->GetOne($sql);
$newRebroadcastInstance = new CcShowInstances();
$newRebroadcastInstance->setDbShowId($show_id);
@ -823,11 +846,11 @@ class Show {
$newRebroadcastInstance->setDbRecord(0);
$newRebroadcastInstance->setDbRebroadcast(1);
$newRebroadcastInstance->setDbOriginalShow($show_instance_id);
$newRebroadcastInstance->save();
$newRebroadcastInstance->save();
}
$sql = "SELECT timestamp '{$start}' + interval '{$interval}'";
$next_date = $CC_DBC->GetOne($sql);
$next_date = $CC_DBC->GetOne($sql);
}
Show::setNextPop($next_date, $show_id, $day);
@ -863,7 +886,7 @@ class Show {
*
* @param int $p_showId
* @param string $p_date
* In the format "YYYY-MM-DD HH:mm:ss"
* In the format "YYYY-MM-DD HH:mm:ss"
*/
public static function populateShowUntil($p_showId, $p_date = NULL)
{
@ -878,7 +901,7 @@ class Show {
}
$sql = "SELECT * FROM cc_show_days WHERE show_id = $p_showId";
$res = $CC_DBC->GetAll($sql);
$res = $CC_DBC->GetAll($sql);
foreach ($res as $row) {
Show::populateShow($row["repeat_type"], $row["show_id"], $row["next_pop_date"], $row["first_show"],
@ -890,9 +913,9 @@ class Show {
* Generate all the repeating shows in the given range.
*
* @param string $p_startTimestamp
* In the format "YYYY-MM-DD HH:mm:ss"
* In the format "YYYY-MM-DD HH:mm:ss"
* @param string $p_endTimestamp
* In the format "YYYY-MM-DD HH:mm:ss"
* In the format "YYYY-MM-DD HH:mm:ss"
*/
public static function populateAllShowsInRange($p_startTimestamp, $p_endTimestamp)
{
@ -900,17 +923,17 @@ class Show {
if ($p_startTimestamp != "") {
$sql = "SELECT * FROM cc_show_days
WHERE last_show IS NULL
WHERE last_show IS NULL
OR first_show < '{$p_endTimestamp}' AND last_show > '{$p_startTimestamp}'";
}
else {
$today_timestamp = date("Y-m-d");
$sql = "SELECT * FROM cc_show_days
WHERE last_show IS NULL
WHERE last_show IS NULL
OR first_show < '{$p_endTimestamp}' AND last_show > '{$today_timestamp}'";
}
$res = $CC_DBC->GetAll($sql);
$res = $CC_DBC->GetAll($sql);
foreach ($res as $row) {
Show::populateShow($row["repeat_type"], $row["show_id"], $row["next_pop_date"], $row["first_show"],
@ -923,7 +946,7 @@ class Show {
* @param string $start
* In the format "YYYY-MM-DD HH:mm:ss"
* @param string $end
* In the format "YYYY-MM-DD HH:mm:ss"
* In the format "YYYY-MM-DD HH:mm:ss"
* @param boolean $editable
*/
public static function getFullCalendarEvents($start, $end, $editable=false)
@ -948,7 +971,7 @@ class Show {
if ($editable && strtotime($today_timestamp) < strtotime($show["starts"])) {
$options["editable"] = true;
$events[] = Show::makeFullCalendarEvent($show, $options);
$events[] = Show::makeFullCalendarEvent($show, $options);
}
else {
$events[] = Show::makeFullCalendarEvent($show, $options);
@ -958,7 +981,7 @@ class Show {
return $events;
}
private static function makeFullCalendarEvent($show, $options=array())
private static function makeFullCalendarEvent($show, $options=array())
{
$event = array();
@ -966,12 +989,12 @@ class Show {
$event["disableResizing"] = true;
}
$event["id"] = $show["instance_id"];
$event["title"] = $show["name"];
$event["start"] = $show["starts"];
$event["end"] = $show["ends"];
$event["allDay"] = false;
$event["description"] = $show["description"];
$event["id"] = $show["instance_id"];
$event["title"] = $show["name"];
$event["start"] = $show["starts"];
$event["end"] = $show["ends"];
$event["allDay"] = false;
$event["description"] = $show["description"];
$event["showId"] = $show["show_id"];
$event["record"] = intval($show["record"]);
$event["rebroadcast"] = intval($show["rebroadcast"]);
@ -983,14 +1006,14 @@ class Show {
}
if($show["background_color"] != "") {
$event["color"] = "#".$show["background_color"];
}
}
foreach($options as $key=>$value) {
$event[$key] = $value;
}
foreach($options as $key=>$value) {
$event[$key] = $value;
}
return $event;
}
return $event;
}
public static function getDateFromTimestamp($p_timestamp){
$explode = explode(" ", $p_timestamp);
@ -1030,11 +1053,11 @@ class Show {
class ShowInstance {
private $_instanceId;
private $_instanceId;
public function __construct($instanceId)
public function __construct($instanceId)
{
$this->_instanceId = $instanceId;
$this->_instanceId = $instanceId;
}
public function getShowId()
@ -1170,40 +1193,40 @@ class ShowInstance {
public function moveShow($deltaDay, $deltaMin)
{
global $CC_DBC;
global $CC_DBC;
$hours = $deltaMin/60;
if($hours > 0)
$hours = floor($hours);
else
$hours = ceil($hours);
$hours = $deltaMin/60;
if($hours > 0)
$hours = floor($hours);
else
$hours = ceil($hours);
$mins = abs($deltaMin%60);
$mins = abs($deltaMin%60);
$starts = $this->getShowStart();
$ends = $this->getShowEnd();
$sql = "SELECT timestamp '{$starts}' + interval '{$deltaDay} days' + interval '{$hours}:{$mins}'";
$new_starts = $CC_DBC->GetOne($sql);
$sql = "SELECT timestamp '{$starts}' + interval '{$deltaDay} days' + interval '{$hours}:{$mins}'";
$new_starts = $CC_DBC->GetOne($sql);
$sql = "SELECT timestamp '{$ends}' + interval '{$deltaDay} days' + interval '{$hours}:{$mins}'";
$new_ends = $CC_DBC->GetOne($sql);
$sql = "SELECT timestamp '{$ends}' + interval '{$deltaDay} days' + interval '{$hours}:{$mins}'";
$new_ends = $CC_DBC->GetOne($sql);
$today_timestamp = date("Y-m-d H:i:s");
if(strtotime($today_timestamp) > strtotime($new_starts)) {
return "can't move show into past";
}
$overlap = Show::getShows($new_starts, $new_ends, array($this->_instanceId));
$overlap = Show::getShows($new_starts, $new_ends, array($this->_instanceId));
if(count($overlap) > 0) {
return "Should not overlap shows";
}
if(count($overlap) > 0) {
return "Should not overlap shows";
}
$rebroadcast = $this->isRebroadcast();
if($rebroadcast) {
$sql = "SELECT timestamp '{$new_starts}' < (SELECT starts FROM cc_show_instances WHERE id = {$rebroadcast})";
$isBeforeRecordedOriginal = $CC_DBC->GetOne($sql);
$isBeforeRecordedOriginal = $CC_DBC->GetOne($sql);
if($isBeforeRecordedOriginal === 't'){
return "Cannot move a rebroadcast show before its original";
@ -1214,33 +1237,33 @@ class ShowInstance {
$this->setShowStart($new_starts);
$this->setShowEnd($new_ends);
RabbitMq::PushSchedule();
}
}
public function resizeShow($deltaDay, $deltaMin)
{
global $CC_DBC;
public function resizeShow($deltaDay, $deltaMin)
{
global $CC_DBC;
$hours = $deltaMin/60;
if($hours > 0)
$hours = floor($hours);
else
$hours = ceil($hours);
$hours = $deltaMin/60;
if($hours > 0)
$hours = floor($hours);
else
$hours = ceil($hours);
$mins = abs($deltaMin%60);
$mins = abs($deltaMin%60);
$starts = $this->getShowStart();
$ends = $this->getShowEnd();
$sql = "SELECT timestamp '{$ends}' + interval '{$deltaDay} days' + interval '{$hours}:{$mins}'";
$new_ends = $CC_DBC->GetOne($sql);
$sql = "SELECT timestamp '{$ends}' + interval '{$deltaDay} days' + interval '{$hours}:{$mins}'";
$new_ends = $CC_DBC->GetOne($sql);
//only need to check overlap if show increased in size.
if(strtotime($new_ends) > strtotime($ends)) {
$overlap = Show::getShows($ends, $new_ends);
$overlap = Show::getShows($ends, $new_ends);
if(count($overlap) > 0) {
return "Should not overlap shows";
}
return "Should not overlap shows";
}
}
//with overbooking no longer need to check already scheduled content still fits.
@ -1248,45 +1271,45 @@ class ShowInstance {
if($this->isRecorded()) {
$sql = "UPDATE cc_show_instances SET ends = (ends + interval '{$deltaDay} days' + interval '{$hours}:{$mins}')
WHERE rebroadcast = 1 AND instance_id = {$this->_instanceId}";
$CC_DBC->query($sql);
$CC_DBC->query($sql);
}
$this->setShowEnd($new_ends);
RabbitMq::PushSchedule();
}
}
/**
* Get the group ID for this show.
*
*/
private function getLastGroupId()
{
global $CC_DBC;
$sql = "SELECT group_id FROM cc_schedule WHERE instance_id = '{$this->_instanceId}' ORDER BY ends DESC LIMIT 1";
$res = $CC_DBC->GetOne($sql);
return $res;
}
/**
* Add a playlist as the last item of the current show.
*
* @param int $plId
* Playlist ID.
*/
public function addPlaylistToShow($plId)
/**
* Get the group ID for this show.
*
*/
private function getLastGroupId()
{
$sched = new ScheduleGroup();
$lastGroupId = $this->getLastGroupId();
global $CC_DBC;
$sql = "SELECT group_id FROM cc_schedule WHERE instance_id = '{$this->_instanceId}' ORDER BY ends DESC LIMIT 1";
$res = $CC_DBC->GetOne($sql);
return $res;
}
if (is_null($lastGroupId)) {
$groupId = $sched->add($this->_instanceId, $this->getShowStart(), null, $plId);
}
else {
$groupId = $sched->addPlaylistAfter($this->_instanceId, $lastGroupId, $plId);
}
RabbitMq::PushSchedule();
/**
* Add a playlist as the last item of the current show.
*
* @param int $plId
* Playlist ID.
*/
public function addPlaylistToShow($plId)
{
$sched = new ScheduleGroup();
$lastGroupId = $this->getLastGroupId();
if (is_null($lastGroupId)) {
$groupId = $sched->add($this->_instanceId, $this->getShowStart(), null, $plId);
}
else {
$groupId = $sched->addPlaylistAfter($this->_instanceId, $lastGroupId, $plId);
}
RabbitMq::PushSchedule();
$this->updateScheduledTime();
}
}
/**
* Add a media file as the last item in the show.
@ -1296,14 +1319,14 @@ class ShowInstance {
public function addFileToShow($file_id)
{
$sched = new ScheduleGroup();
$lastGroupId = $this->getLastGroupId();
$lastGroupId = $this->getLastGroupId();
if (is_null($lastGroupId)) {
$groupId = $sched->add($this->_instanceId, $this->getShowStart(), $file_id);
}
else {
$groupId = $sched->addFileAfter($this->_instanceId, $lastGroupId, $file_id);
}
if (is_null($lastGroupId)) {
$groupId = $sched->add($this->_instanceId, $this->getShowStart(), $file_id);
}
else {
$groupId = $sched->addFileAfter($this->_instanceId, $lastGroupId, $file_id);
}
RabbitMq::PushSchedule();
$this->updateScheduledTime();
}
@ -1312,7 +1335,7 @@ class ShowInstance {
* Add the given playlists to the show.
*
* @param array $plIds
* An array of playlist IDs.
* An array of playlist IDs.
*/
public function scheduleShow($plIds)
{
@ -1321,37 +1344,37 @@ class ShowInstance {
}
}
public function removeGroupFromShow($group_id)
{
global $CC_DBC;
public function removeGroupFromShow($group_id)
{
global $CC_DBC;
$sql = "SELECT MAX(ends) as end_timestamp, (MAX(ends) - MIN(starts)) as length
FROM cc_schedule
WHERE group_id = '{$group_id}'";
WHERE group_id = '{$group_id}'";
$groupBoundry = $CC_DBC->GetRow($sql);
$groupBoundry = $CC_DBC->GetRow($sql);
$group = CcScheduleQuery::create()
->filterByDbGroupId($group_id)
->delete();
$group = CcScheduleQuery::create()
->filterByDbGroupId($group_id)
->delete();
$sql = "UPDATE cc_schedule
SET starts = (starts - INTERVAL '{$groupBoundry["length"]}'), ends = (ends - INTERVAL '{$groupBoundry["length"]}')
WHERE starts >= '{$groupBoundry["end_timestamp"]}' AND instance_id = {$this->_instanceId}";
$sql = "UPDATE cc_schedule
SET starts = (starts - INTERVAL '{$groupBoundry["length"]}'), ends = (ends - INTERVAL '{$groupBoundry["length"]}')
WHERE starts >= '{$groupBoundry["end_timestamp"]}' AND instance_id = {$this->_instanceId}";
$CC_DBC->query($sql);
RabbitMq::PushSchedule();
$CC_DBC->query($sql);
RabbitMq::PushSchedule();
$this->updateScheduledTime();
}
}
public function clearShow()
{
CcScheduleQuery::create()
->filterByDbInstanceId($this->_instanceId)
->delete();
RabbitMq::PushSchedule();
CcScheduleQuery::create()
->filterByDbInstanceId($this->_instanceId)
->delete();
RabbitMq::PushSchedule();
$this->updateScheduledTime();
}
}
public function deleteShow()
{
@ -1359,7 +1382,7 @@ class ShowInstance {
->findPK($this->_instanceId)
->delete();
RabbitMq::PushSchedule();
}
}
public function setRecordedFile($file_id)
{
@ -1388,7 +1411,7 @@ class ShowInstance {
$time = "00:00:00";
}
return $time;
}
}
public function getPercentScheduled()
{
@ -1410,74 +1433,74 @@ class ShowInstance {
public function getShowLength()
{
global $CC_DBC;
global $CC_DBC;
$start_timestamp = $this->getShowStart();
$end_timestamp = $this->getShowEnd();
$sql = "SELECT TIMESTAMP '{$end_timestamp}' - TIMESTAMP '{$start_timestamp}' ";
$length = $CC_DBC->GetOne($sql);
$sql = "SELECT TIMESTAMP '{$end_timestamp}' - TIMESTAMP '{$start_timestamp}' ";
$length = $CC_DBC->GetOne($sql);
return $length;
}
return $length;
}
public function searchPlaylistsForShow($datatables)
{
return StoredFile::searchPlaylistsForSchedule($datatables);
}
public function searchPlaylistsForShow($datatables)
{
return StoredFile::searchPlaylistsForSchedule($datatables);
}
public function getShowListContent()
{
global $CC_DBC;
$sql = "SELECT *
FROM (cc_schedule AS s LEFT JOIN cc_files AS f ON f.id = s.file_id
LEFT JOIN cc_playlist AS p ON p.id = s.playlist_id )
$sql = "SELECT *
FROM (cc_schedule AS s LEFT JOIN cc_files AS f ON f.id = s.file_id
LEFT JOIN cc_playlist AS p ON p.id = s.playlist_id )
WHERE s.instance_id = '{$this->_instanceId}' ORDER BY starts";
WHERE s.instance_id = '{$this->_instanceId}' ORDER BY starts";
return $CC_DBC->GetAll($sql);
return $CC_DBC->GetAll($sql);
}
public function getShowContent()
{
global $CC_DBC;
public function getShowContent()
{
global $CC_DBC;
$res = $this->getShowListContent();
if(count($res) <= 0) {
return $res;
}
return $res;
}
$items = array();
$currGroupId = -1;
$pl_counter = -1;
$f_counter = -1;
foreach ($res as $row) {
if($currGroupId != $row["group_id"]){
$currGroupId = $row["group_id"];
$pl_counter = $pl_counter + 1;
$f_counter = -1;
$items = array();
$currGroupId = -1;
$pl_counter = -1;
$f_counter = -1;
foreach ($res as $row) {
if($currGroupId != $row["group_id"]){
$currGroupId = $row["group_id"];
$pl_counter = $pl_counter + 1;
$f_counter = -1;
$items[$pl_counter]["pl_name"] = $row["name"];
$items[$pl_counter]["pl_creator"] = $row["creator"];
$items[$pl_counter]["pl_description"] = $row["description"];
$items[$pl_counter]["pl_group"] = $row["group_id"];
$items[$pl_counter]["pl_name"] = $row["name"];
$items[$pl_counter]["pl_creator"] = $row["creator"];
$items[$pl_counter]["pl_description"] = $row["description"];
$items[$pl_counter]["pl_group"] = $row["group_id"];
$sql = "SELECT SUM(clip_length) FROM cc_schedule WHERE group_id = '{$currGroupId}'";
$length = $CC_DBC->GetOne($sql);
$sql = "SELECT SUM(clip_length) FROM cc_schedule WHERE group_id = '{$currGroupId}'";
$length = $CC_DBC->GetOne($sql);
$items[$pl_counter]["pl_length"] = $length;
}
$f_counter = $f_counter + 1;
$items[$pl_counter]["pl_length"] = $length;
}
$f_counter = $f_counter + 1;
$items[$pl_counter]["pl_content"][$f_counter]["f_name"] = $row["track_title"];
$items[$pl_counter]["pl_content"][$f_counter]["f_artist"] = $row["artist_name"];
$items[$pl_counter]["pl_content"][$f_counter]["f_length"] = $row["length"];
}
$items[$pl_counter]["pl_content"][$f_counter]["f_name"] = $row["track_title"];
$items[$pl_counter]["pl_content"][$f_counter]["f_artist"] = $row["artist_name"];
$items[$pl_counter]["pl_content"][$f_counter]["f_length"] = $row["length"];
}
return $items;
}
return $items;
}
}
/* Show Data Access Layer */
@ -1501,11 +1524,11 @@ class Show_DAL {
{
global $CC_CONFIG, $CC_DBC;
$sql = "SELECT *, si.starts as start_timestamp, si.ends as end_timestamp FROM "
." $CC_CONFIG[showInstances] si, $CC_CONFIG[showTable] s"
." WHERE si.show_id = s.id"
." AND si.starts >= TIMESTAMP '$timeNow'"
." AND si.starts < TIMESTAMP '$timeNow' + INTERVAL '48 hours'"
$sql = "SELECT *, si.starts as start_timestamp, si.ends as end_timestamp FROM "
." $CC_CONFIG[showInstances] si, $CC_CONFIG[showTable] s"
." WHERE si.show_id = s.id"
." AND si.starts >= TIMESTAMP '$timeNow'"
." AND si.starts < TIMESTAMP '$timeNow' + INTERVAL '48 hours'"
." ORDER BY si.starts"
." LIMIT $limit";
@ -1516,7 +1539,7 @@ class Show_DAL {
public static function GetShowsInRange($timeNow, $start, $end)
{
global $CC_CONFIG, $CC_DBC;
$sql = "SELECT"
$sql = "SELECT"
." si.starts as show_starts,"
." si.ends as show_ends,"
." si.rebroadcast as rebroadcast,"
@ -1537,8 +1560,8 @@ class Show_DAL {
." LEFT JOIN $CC_CONFIG[filesTable] ft"
." ON st.file_id = ft.id"
." LEFT JOIN $CC_CONFIG[showTable] s"
." ON si.show_id = s.id"
." WHERE ((si.starts < TIMESTAMP '$timeNow' - INTERVAL '$start seconds' AND si.ends > TIMESTAMP '$timeNow' - INTERVAL '$start seconds')"
." ON si.show_id = s.id"
." WHERE ((si.starts < TIMESTAMP '$timeNow' - INTERVAL '$start seconds' AND si.ends > TIMESTAMP '$timeNow' - INTERVAL '$start seconds')"
." OR (si.starts > TIMESTAMP '$timeNow' - INTERVAL '$start seconds' AND si.ends < TIMESTAMP '$timeNow' + INTERVAL '$end seconds')"
." OR (si.starts < TIMESTAMP '$timeNow' + INTERVAL '$end seconds' AND si.ends > TIMESTAMP '$timeNow' + INTERVAL '$end seconds'))"
//checking for st.starts IS NULL so that the query also returns shows that do not have any items scheduled.
@ -1556,14 +1579,14 @@ class Show_DAL {
//Result: 5
global $CC_CONFIG, $CC_DBC;
$sql = "SELECT"
$sql = "SELECT"
." si.starts as show_starts,"
." si.ends as show_ends,"
." s.name as show_name,"
." s.url as url"
." FROM $CC_CONFIG[showInstances] si"
." LEFT JOIN $CC_CONFIG[showTable] s"
." ON si.show_id = s.id"
." ON si.show_id = s.id"
." WHERE EXTRACT(DOW FROM si.starts) = $day"
." AND EXTRACT(WEEK FROM si.starts) = EXTRACT(WEEK FROM localtimestamp)"
." ORDER BY si.starts";