2010-12-07 20:19:27 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class Show {
|
|
|
|
|
2010-12-16 21:15:43 +01:00
|
|
|
private $_showId;
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2011-02-06 00:20:51 +01:00
|
|
|
public function __construct($showId=NULL)
|
2010-12-07 20:19:27 +01:00
|
|
|
{
|
2010-12-16 21:15:43 +01:00
|
|
|
$this->_showId = $showId;
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
2011-02-01 17:43:52 +01:00
|
|
|
public function getName() {
|
|
|
|
$show = CcShowQuery::create()->findPK($this->_showId);
|
|
|
|
|
|
|
|
return $show->getDbName();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setName($name) {
|
|
|
|
$show = CcShowQuery::create()->findPK($this->_showId);
|
|
|
|
|
|
|
|
$show->setDbName($name);
|
|
|
|
}
|
|
|
|
|
2010-12-09 20:54:12 +01:00
|
|
|
//end dates are non inclusive.
|
2011-02-06 00:20:51 +01:00
|
|
|
public static function addShow($data) {
|
2010-12-08 21:40:53 +01:00
|
|
|
|
2011-01-10 19:24:21 +01:00
|
|
|
$con = Propel::getConnection(CcShowPeer::DATABASE_NAME);
|
2010-12-08 06:47:51 +01:00
|
|
|
|
2011-01-21 19:25:12 +01:00
|
|
|
$sql = "SELECT time '{$data['add_show_start_time']}' + INTERVAL '{$data['add_show_duration']} hour' ";
|
2010-12-08 06:47:51 +01:00
|
|
|
$r = $con->query($sql);
|
|
|
|
$endTime = $r->fetchColumn(0);
|
|
|
|
|
2011-01-21 19:25:12 +01:00
|
|
|
$sql = "SELECT EXTRACT(DOW FROM TIMESTAMP '{$data['add_show_start_date']} {$data['add_show_start_time']}')";
|
2010-12-08 06:47:51 +01:00
|
|
|
$r = $con->query($sql);
|
2010-12-08 21:40:53 +01:00
|
|
|
$startDow = $r->fetchColumn(0);
|
|
|
|
|
2011-01-21 19:25:12 +01:00
|
|
|
if($data['add_show_no_end']) {
|
2010-12-08 21:40:53 +01:00
|
|
|
$endDate = NULL;
|
2011-01-21 19:25:12 +01:00
|
|
|
$data['add_show_repeats'] = 1;
|
2010-12-08 21:40:53 +01:00
|
|
|
}
|
2011-01-21 19:25:12 +01:00
|
|
|
else if($data['add_show_repeats']) {
|
|
|
|
$sql = "SELECT date '{$data['add_show_end_date']}' + INTERVAL '1 day' ";
|
2010-12-09 20:54:12 +01:00
|
|
|
$r = $con->query($sql);
|
|
|
|
$endDate = $r->fetchColumn(0);
|
2010-12-08 21:40:53 +01:00
|
|
|
}
|
|
|
|
else {
|
2011-01-21 19:25:12 +01:00
|
|
|
$sql = "SELECT date '{$data['add_show_start_date']}' + INTERVAL '1 day' ";
|
2010-12-09 20:54:12 +01:00
|
|
|
$r = $con->query($sql);
|
|
|
|
$endDate = $r->fetchColumn(0);
|
2010-12-08 21:40:53 +01:00
|
|
|
}
|
|
|
|
|
2011-02-06 05:42:57 +01:00
|
|
|
//only want the day of the week from the start date.
|
|
|
|
if(!$data['add_show_repeats']) {
|
2011-01-21 19:25:12 +01:00
|
|
|
$data['add_show_day_check'] = array($startDow);
|
2010-12-10 18:15:17 +01:00
|
|
|
}
|
2010-12-10 21:44:36 +01:00
|
|
|
|
2011-02-06 05:21:52 +01:00
|
|
|
//find repeat type or set to a non repeating show.
|
2011-02-05 22:00:05 +01:00
|
|
|
if($data['add_show_repeats']) {
|
2011-02-06 05:21:52 +01:00
|
|
|
$repeat_type = $data["add_show_repeat_type"];
|
2011-02-05 22:00:05 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
$repeat_type = -1;
|
|
|
|
}
|
2010-12-10 18:15:17 +01:00
|
|
|
|
|
|
|
$show = new CcShow();
|
2011-01-21 19:25:12 +01:00
|
|
|
$show->setDbName($data['add_show_name']);
|
|
|
|
$show->setDbDescription($data['add_show_description']);
|
2011-01-21 20:43:38 +01:00
|
|
|
$show->setDbColor($data['add_show_color']);
|
|
|
|
$show->setDbBackgroundColor($data['add_show_background_color']);
|
2010-12-16 00:53:47 +01:00
|
|
|
$show->save();
|
2010-12-10 18:15:17 +01:00
|
|
|
|
|
|
|
$showId = $show->getDbId();
|
2010-12-08 06:47:51 +01:00
|
|
|
|
2011-01-21 19:25:12 +01:00
|
|
|
foreach ($data['add_show_day_check'] as $day) {
|
2010-12-08 06:47:51 +01:00
|
|
|
|
|
|
|
if($startDow !== $day){
|
|
|
|
|
|
|
|
if($startDow > $day)
|
|
|
|
$daysAdd = 6 - $startDow + 1 + $day;
|
|
|
|
else
|
|
|
|
$daysAdd = $day - $startDow;
|
|
|
|
|
2011-01-21 19:25:12 +01:00
|
|
|
$sql = "SELECT date '{$data['add_show_start_date']}' + INTERVAL '{$daysAdd} day' ";
|
2010-12-08 06:47:51 +01:00
|
|
|
$r = $con->query($sql);
|
|
|
|
$start = $r->fetchColumn(0);
|
|
|
|
}
|
|
|
|
else {
|
2011-01-21 19:25:12 +01:00
|
|
|
$start = $data['add_show_start_date'];
|
2010-12-08 06:47:51 +01:00
|
|
|
}
|
|
|
|
|
2011-02-02 00:02:35 +01:00
|
|
|
if(strtotime($start) < strtotime($endDate) || is_null($endDate)) {
|
2011-01-31 02:11:18 +01:00
|
|
|
|
|
|
|
$showDay = new CcShowDays();
|
|
|
|
$showDay->setDbFirstShow($start);
|
|
|
|
$showDay->setDbLastShow($endDate);
|
|
|
|
$showDay->setDbStartTime($data['add_show_start_time']);
|
2011-02-05 22:00:05 +01:00
|
|
|
$showDay->setDbDuration($data['add_show_duration']);
|
2011-01-31 02:11:18 +01:00
|
|
|
$showDay->setDbDay($day);
|
2011-02-05 22:00:05 +01:00
|
|
|
$showDay->setDbRepeatType($repeat_type);
|
2011-01-31 02:11:18 +01:00
|
|
|
$showDay->setDbShowId($showId);
|
|
|
|
$showDay->save();
|
|
|
|
}
|
2010-12-08 06:47:51 +01:00
|
|
|
}
|
2010-12-10 21:44:36 +01:00
|
|
|
|
2011-01-21 19:25:12 +01:00
|
|
|
foreach ($data['add_show_hosts'] as $host) {
|
2010-12-10 21:44:36 +01:00
|
|
|
$showHost = new CcShowHosts();
|
|
|
|
$showHost->setDbShow($showId);
|
|
|
|
$showHost->setDbHost($host);
|
|
|
|
$showHost->save();
|
|
|
|
}
|
2011-02-05 22:00:05 +01:00
|
|
|
|
2011-02-06 01:42:03 +01:00
|
|
|
Show::populateShowUntilLastGeneratedDate($showId);
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
2011-02-06 00:20:51 +01:00
|
|
|
public static function getShows($start_timestamp, $end_timestamp, $excludeInstance=NULL) {
|
2011-02-05 22:00:05 +01:00
|
|
|
global $CC_DBC;
|
2010-12-09 23:02:37 +01:00
|
|
|
|
2011-02-05 22:00:05 +01:00
|
|
|
$sql = "SELECT starts, ends, show_id, name, description, color, background_color, cc_show_instances.id AS instance_id
|
|
|
|
FROM cc_show_instances
|
|
|
|
LEFT JOIN cc_show ON cc_show.id = cc_show_instances.show_id
|
2011-02-05 22:34:58 +01:00
|
|
|
WHERE ((starts >= '{$start_timestamp}' AND starts < '{$end_timestamp}')
|
2011-02-06 23:37:23 +01:00
|
|
|
OR (ends > '{$start_timestamp}' AND ends <= '{$end_timestamp}')
|
|
|
|
OR (starts <= '{$start_timestamp}' AND ends >= '{$end_timestamp}'))";
|
2011-02-05 22:34:58 +01:00
|
|
|
|
|
|
|
if(isset($excludeInstance)) {
|
|
|
|
foreach($excludeInstance as $instance) {
|
|
|
|
$sql_exclude[] = "cc_show_instances.id != {$instance}";
|
|
|
|
}
|
|
|
|
|
|
|
|
$exclude = join(" OR ", $sql_exclude);
|
|
|
|
|
|
|
|
$sql = $sql." AND ({$exclude})";
|
|
|
|
}
|
2010-12-09 20:33:34 +01:00
|
|
|
|
2011-02-06 05:50:43 +01:00
|
|
|
//echo $sql;
|
2010-12-09 20:33:34 +01:00
|
|
|
|
2011-02-05 22:00:05 +01:00
|
|
|
return $CC_DBC->GetAll($sql);
|
|
|
|
}
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2011-02-05 22:00:05 +01:00
|
|
|
//for a show with repeat_type == -1
|
2011-02-06 00:20:51 +01:00
|
|
|
private static function populateNonRepeatingShow($show_id, $first_show, $start_time, $duration, $day, $end_timestamp) {
|
2011-02-05 22:00:05 +01:00
|
|
|
global $CC_DBC;
|
|
|
|
|
|
|
|
$next_date = $first_show." ".$start_time;
|
|
|
|
|
|
|
|
if(strtotime($next_date) < strtotime($end_timestamp)) {
|
|
|
|
|
|
|
|
$start = $next_date;
|
|
|
|
|
|
|
|
$sql = "SELECT timestamp '{$start}' + interval '{$duration}'";
|
|
|
|
$end = $CC_DBC->GetOne($sql);
|
|
|
|
|
|
|
|
$newShow = new CcShowInstances();
|
|
|
|
$newShow->setDbShowId($show_id);
|
|
|
|
$newShow->setDbStarts($start);
|
|
|
|
$newShow->setDbEnds($end);
|
|
|
|
$newShow->save();
|
|
|
|
}
|
|
|
|
}
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2011-02-05 22:00:05 +01:00
|
|
|
//for a show with repeat_type == 0
|
2011-02-06 00:20:51 +01:00
|
|
|
private static function populateWeeklyShow($show_id, $next_pop_date, $first_show, $last_show, $start_time, $duration, $day, $end_timestamp) {
|
2011-02-05 22:00:05 +01:00
|
|
|
global $CC_DBC;
|
|
|
|
|
|
|
|
if(isset($next_pop_date)) {
|
|
|
|
$next_date = $next_pop_date." ".$start_time;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$next_date = $first_show." ".$start_time;
|
|
|
|
}
|
|
|
|
|
|
|
|
while(strtotime($next_date) < strtotime($end_timestamp) && (strtotime($last_show) > strtotime($next_date) || is_null($last_show))) {
|
|
|
|
|
|
|
|
$start = $next_date;
|
|
|
|
|
|
|
|
$sql = "SELECT timestamp '{$start}' + interval '{$duration}'";
|
|
|
|
$end = $CC_DBC->GetOne($sql);
|
|
|
|
|
|
|
|
$newShow = new CcShowInstances();
|
|
|
|
$newShow->setDbShowId($show_id);
|
|
|
|
$newShow->setDbStarts($start);
|
|
|
|
$newShow->setDbEnds($end);
|
|
|
|
$newShow->save();
|
|
|
|
|
|
|
|
$sql = "SELECT timestamp '{$start}' + interval '7 days'";
|
|
|
|
$next_date = $CC_DBC->GetOne($sql);
|
|
|
|
}
|
|
|
|
|
|
|
|
$nextInfo = explode(" ", $next_date);
|
|
|
|
|
|
|
|
$repeatInfo = CcShowDaysQuery::create()
|
|
|
|
->filterByDbShowId($show_id)
|
|
|
|
->filterByDbDay($day)
|
|
|
|
->findOne();
|
|
|
|
|
|
|
|
$repeatInfo->setDbNextPopDate($nextInfo[0])
|
|
|
|
->save();
|
|
|
|
}
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2011-02-06 05:21:52 +01:00
|
|
|
//for a show with repeat_type == 1
|
|
|
|
private static function populateBiWeeklyShow($show_id, $next_pop_date, $first_show, $last_show, $start_time, $duration, $day, $end_timestamp) {
|
|
|
|
global $CC_DBC;
|
|
|
|
|
|
|
|
if(isset($next_pop_date)) {
|
|
|
|
$next_date = $next_pop_date." ".$start_time;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$next_date = $first_show." ".$start_time;
|
|
|
|
}
|
|
|
|
|
|
|
|
while(strtotime($next_date) < strtotime($end_timestamp) && (strtotime($last_show) > strtotime($next_date) || is_null($last_show))) {
|
|
|
|
|
|
|
|
$start = $next_date;
|
|
|
|
|
|
|
|
$sql = "SELECT timestamp '{$start}' + interval '{$duration}'";
|
|
|
|
$end = $CC_DBC->GetOne($sql);
|
|
|
|
|
|
|
|
$newShow = new CcShowInstances();
|
|
|
|
$newShow->setDbShowId($show_id);
|
|
|
|
$newShow->setDbStarts($start);
|
|
|
|
$newShow->setDbEnds($end);
|
|
|
|
$newShow->save();
|
|
|
|
|
|
|
|
$sql = "SELECT timestamp '{$start}' + interval '14 days'";
|
|
|
|
$next_date = $CC_DBC->GetOne($sql);
|
|
|
|
}
|
|
|
|
|
|
|
|
$nextInfo = explode(" ", $next_date);
|
|
|
|
|
|
|
|
$repeatInfo = CcShowDaysQuery::create()
|
|
|
|
->filterByDbShowId($show_id)
|
|
|
|
->filterByDbDay($day)
|
|
|
|
->findOne();
|
|
|
|
|
|
|
|
$repeatInfo->setDbNextPopDate($nextInfo[0])
|
|
|
|
->save();
|
|
|
|
}
|
|
|
|
|
2011-02-06 00:20:51 +01:00
|
|
|
private static function populateShow($repeat_type, $show_id, $next_pop_date, $first_show, $last_show, $start_time, $duration, $day, $end_timestamp) {
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2011-02-05 22:00:05 +01:00
|
|
|
if($repeat_type == -1) {
|
2011-02-06 00:20:51 +01:00
|
|
|
Show::populateNonRepeatingShow($show_id, $first_show, $start_time, $duration, $day, $end_timestamp);
|
2011-02-05 22:00:05 +01:00
|
|
|
}
|
|
|
|
else if($repeat_type == 0) {
|
2011-02-06 00:20:51 +01:00
|
|
|
Show::populateWeeklyShow($show_id, $next_pop_date, $first_show, $last_show, $start_time, $duration, $day, $end_timestamp);
|
2011-02-05 22:00:05 +01:00
|
|
|
}
|
2011-02-06 05:21:52 +01:00
|
|
|
else if($repeat_type == 1) {
|
|
|
|
Show::populateBiWeeklyShow($show_id, $next_pop_date, $first_show, $last_show, $start_time, $duration, $day, $end_timestamp);
|
|
|
|
}
|
2011-02-05 22:00:05 +01:00
|
|
|
}
|
2010-12-16 21:15:43 +01:00
|
|
|
|
2011-02-05 22:00:05 +01:00
|
|
|
//used to catch up a newly added show
|
2011-02-06 00:20:51 +01:00
|
|
|
private static function populateShowUntilLastGeneratedDate($show_id) {
|
2011-02-05 22:00:05 +01:00
|
|
|
global $CC_DBC;
|
|
|
|
$showsPopUntil = Application_Model_Preference::GetShowsPopulatedUntil();
|
|
|
|
|
|
|
|
$sql = "SELECT * FROM cc_show_days WHERE show_id = {$show_id}";
|
|
|
|
$res = $CC_DBC->GetAll($sql);
|
|
|
|
|
|
|
|
foreach($res as $row) {
|
2011-02-06 00:20:51 +01:00
|
|
|
Show::populateShow($row["repeat_type"], $row["show_id"], $row["next_pop_date"], $row["first_show"],
|
2011-02-05 22:00:05 +01:00
|
|
|
$row["last_show"], $row["start_time"], $row["duration"], $row["day"], $showsPopUntil);
|
|
|
|
}
|
|
|
|
}
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2011-02-06 00:20:51 +01:00
|
|
|
public static function populateShowsUntil($pop_timestamp, $end_timestamp) {
|
2011-02-05 22:00:05 +01:00
|
|
|
global $CC_DBC;
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2011-02-05 22:00:05 +01:00
|
|
|
if($pop_timestamp != "") {
|
|
|
|
$sql = "SELECT * FROM cc_show_days
|
|
|
|
WHERE last_show IS NULL
|
|
|
|
OR first_show < '{$end_timestamp}' AND last_show > '{$pop_timestamp}'";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$today_timestamp = date("Y-m-d");
|
|
|
|
|
|
|
|
$sql = "SELECT * FROM cc_show_days
|
|
|
|
WHERE last_show IS NULL
|
|
|
|
OR first_show < '{$end_timestamp}' AND last_show > '{$today_timestamp}'";
|
|
|
|
}
|
|
|
|
|
|
|
|
$res = $CC_DBC->GetAll($sql);
|
|
|
|
|
|
|
|
foreach($res as $row) {
|
2011-02-06 00:20:51 +01:00
|
|
|
Show::populateShow($row["repeat_type"], $row["show_id"], $row["next_pop_date"], $row["first_show"],
|
2011-02-05 22:00:05 +01:00
|
|
|
$row["last_show"], $row["start_time"], $row["duration"], $row["day"], $end_timestamp);
|
|
|
|
}
|
|
|
|
}
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2011-02-06 00:20:51 +01:00
|
|
|
public static function getFullCalendarEvents($start, $end, $editable=false) {
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2011-02-05 22:00:05 +01:00
|
|
|
$events = array();
|
|
|
|
$showsPopUntil = Application_Model_Preference::GetShowsPopulatedUntil();
|
2011-01-19 22:50:30 +01:00
|
|
|
|
2011-02-05 22:00:05 +01:00
|
|
|
//if fullcalendar is requesting shows past our previous populated until date, generate shows up until this point.
|
|
|
|
if($showsPopUntil == "" || strtotime($showsPopUntil) < strtotime($end)) {
|
2011-01-19 22:50:30 +01:00
|
|
|
|
2011-02-06 00:20:51 +01:00
|
|
|
Show::populateShowsUntil($showsPopUntil, $end);
|
2011-02-05 22:00:05 +01:00
|
|
|
Application_Model_Preference::SetShowsPopulatedUntil($end);
|
|
|
|
}
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2011-02-06 00:20:51 +01:00
|
|
|
$shows = Show::getShows($start, $end);
|
2010-12-10 18:15:17 +01:00
|
|
|
|
2011-02-06 00:20:51 +01:00
|
|
|
$today_timestamp = date("Y-m-d H:i:s");
|
2011-02-05 22:00:05 +01:00
|
|
|
foreach ($shows as $show) {
|
2011-02-06 00:20:51 +01:00
|
|
|
if($editable && strtotime($today_timestamp) < strtotime($show["starts"]))
|
|
|
|
$events[] = Show::makeFullCalendarEvent($show, array("editable" => true));
|
|
|
|
else
|
|
|
|
$events[] = Show::makeFullCalendarEvent($show);
|
2011-02-05 22:00:05 +01:00
|
|
|
}
|
2010-12-17 05:45:11 +01:00
|
|
|
|
2011-02-05 22:00:05 +01:00
|
|
|
return $events;
|
|
|
|
}
|
2010-12-10 18:15:17 +01:00
|
|
|
|
2011-02-06 00:20:51 +01:00
|
|
|
private static function makeFullCalendarEvent($show, $options=array()) {
|
2011-02-05 22:00:05 +01:00
|
|
|
global $CC_DBC;
|
2010-12-10 18:15:17 +01:00
|
|
|
|
|
|
|
$event = array(
|
2011-02-05 22:00:05 +01:00
|
|
|
"id" => $show["instance_id"],
|
2010-12-10 18:15:17 +01:00
|
|
|
"title" => $show["name"],
|
2011-02-05 22:00:05 +01:00
|
|
|
"start" => $show["starts"],
|
|
|
|
"end" => $show["ends"],
|
2010-12-10 18:15:17 +01:00
|
|
|
"allDay" => false,
|
2011-01-21 20:43:38 +01:00
|
|
|
"description" => $show["description"],
|
|
|
|
"color" => $show["color"],
|
2011-02-05 22:00:05 +01:00
|
|
|
"backgroundColor" => $show["background_color"],
|
|
|
|
"showId" => $show["show_id"]
|
2010-12-10 18:15:17 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
foreach($options as $key=>$value) {
|
|
|
|
$event[$key] = $value;
|
|
|
|
}
|
|
|
|
|
2011-02-06 00:20:51 +01:00
|
|
|
$percent = Schedule::getPercentScheduledInRange($show["starts"], $show["ends"]);
|
|
|
|
$event["percent"] = $percent;
|
2011-02-05 23:19:54 +01:00
|
|
|
|
2011-02-06 00:20:51 +01:00
|
|
|
return $event;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class ShowInstance {
|
|
|
|
|
|
|
|
private $_instanceId;
|
|
|
|
|
|
|
|
public function __construct($instanceId)
|
|
|
|
{
|
|
|
|
$this->_instanceId = $instanceId;
|
|
|
|
}
|
|
|
|
|
2011-02-06 01:10:34 +01:00
|
|
|
public function getShowId() {
|
|
|
|
$showInstance = CcShowInstancesQuery::create()->findPK($this->_instanceId);
|
|
|
|
return $showInstance->getDbShowId();
|
|
|
|
}
|
|
|
|
|
2011-02-06 01:42:03 +01:00
|
|
|
public function getName() {
|
|
|
|
$show = CcShowQuery::create()->findPK($this->getShowId());
|
|
|
|
return $show->getDbName();
|
|
|
|
}
|
|
|
|
|
2011-02-06 01:10:34 +01:00
|
|
|
public function getShowStart() {
|
|
|
|
$showInstance = CcShowInstancesQuery::create()->findPK($this->_instanceId);
|
|
|
|
return $showInstance->getDbStarts();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getShowEnd() {
|
|
|
|
$showInstance = CcShowInstancesQuery::create()->findPK($this->_instanceId);
|
|
|
|
return $showInstance->getDbEnds();
|
|
|
|
}
|
|
|
|
|
2011-02-06 02:04:24 +01:00
|
|
|
public function setShowStart($start) {
|
|
|
|
$showInstance = CcShowInstancesQuery::create()->findPK($this->_instanceId);
|
|
|
|
$showInstance->setDbStarts($start)
|
|
|
|
->save();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setShowEnd($end) {
|
|
|
|
$showInstance = CcShowInstancesQuery::create()->findPK($this->_instanceId);
|
|
|
|
$showInstance->setDbEnds($end)
|
|
|
|
->save();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function moveScheduledShowContent($deltaDay, $deltaHours, $deltaMin) {
|
|
|
|
global $CC_DBC;
|
|
|
|
|
|
|
|
$sql = "UPDATE cc_schedule
|
|
|
|
SET starts = (starts + interval '{$deltaDay} days' + interval '{$deltaHours}:{$deltaMin}'),
|
|
|
|
ends = (ends + interval '{$deltaDay} days' + interval '{$deltaHours}:{$deltaMin}')
|
|
|
|
WHERE (starts >= '{$this->getShowStart()}')
|
|
|
|
AND (ends <= '{$this->getShowEnd()}')";
|
|
|
|
|
|
|
|
$CC_DBC->query($sql);
|
|
|
|
}
|
|
|
|
|
2011-02-06 00:20:51 +01:00
|
|
|
public function moveShow($deltaDay, $deltaMin){
|
|
|
|
global $CC_DBC;
|
|
|
|
|
|
|
|
$hours = $deltaMin/60;
|
|
|
|
if($hours > 0)
|
|
|
|
$hours = floor($hours);
|
|
|
|
else
|
|
|
|
$hours = ceil($hours);
|
|
|
|
|
|
|
|
$mins = abs($deltaMin%60);
|
|
|
|
|
2011-02-06 01:10:34 +01:00
|
|
|
$starts = $this->getShowStart();
|
|
|
|
$ends = $this->getShowEnd();
|
2011-02-06 00:20:51 +01:00
|
|
|
|
|
|
|
$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);
|
|
|
|
|
|
|
|
$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));
|
|
|
|
|
|
|
|
if(count($overlap) > 0) {
|
2011-02-06 04:02:45 +01:00
|
|
|
return "Should not overlap shows";
|
2010-12-10 18:15:17 +01:00
|
|
|
}
|
2011-02-06 02:04:24 +01:00
|
|
|
|
|
|
|
$this->moveScheduledShowContent($deltaDay, $hours, $mins);
|
|
|
|
$this->setShowStart($new_starts);
|
|
|
|
$this->setShowEnd($new_ends);
|
2011-02-06 00:20:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function resizeShow($deltaDay, $deltaMin){
|
|
|
|
global $CC_DBC;
|
|
|
|
|
|
|
|
$hours = $deltaMin/60;
|
|
|
|
if($hours > 0)
|
|
|
|
$hours = floor($hours);
|
|
|
|
else
|
|
|
|
$hours = ceil($hours);
|
|
|
|
|
|
|
|
$mins = abs($deltaMin%60);
|
|
|
|
|
2011-02-06 01:10:34 +01:00
|
|
|
$starts = $this->getShowStart();
|
|
|
|
$ends = $this->getShowEnd();
|
2011-02-06 00:20:51 +01:00
|
|
|
|
|
|
|
$sql = "SELECT timestamp '{$ends}' + 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);
|
|
|
|
|
|
|
|
if(count($overlap) > 0) {
|
2011-02-06 04:02:45 +01:00
|
|
|
return "Should not overlap shows";
|
2011-02-06 00:20:51 +01:00
|
|
|
}
|
|
|
|
}
|
2011-02-06 02:11:45 +01:00
|
|
|
//have to check if any scheduled content still fits.
|
|
|
|
else{
|
|
|
|
$scheduledTime = $this->getTimeScheduled();
|
2011-02-06 03:54:15 +01:00
|
|
|
$sql = "SELECT (timestamp '{$new_ends}' - timestamp '{$starts}') >= interval '{$scheduledTime}'";
|
|
|
|
$scheduledContentFits = $CC_DBC->GetOne($sql);
|
2011-02-06 02:11:45 +01:00
|
|
|
|
2011-02-06 03:54:15 +01:00
|
|
|
if($scheduledContentFits != "t") {
|
2011-02-06 02:11:45 +01:00
|
|
|
return "Must removed some scheduled content.";
|
|
|
|
}
|
|
|
|
}
|
2011-02-06 00:20:51 +01:00
|
|
|
|
2011-02-06 02:04:24 +01:00
|
|
|
$this->setShowEnd($new_ends);
|
2011-02-06 00:20:51 +01:00
|
|
|
}
|
|
|
|
|
2011-02-06 01:10:34 +01:00
|
|
|
private function getNextPos() {
|
2011-02-06 00:20:51 +01:00
|
|
|
global $CC_DBC;
|
|
|
|
|
2011-02-06 01:10:34 +01:00
|
|
|
$sql = "SELECT MAX(position)+1 from cc_show_schedule WHERE instance_id = '{$this->_instanceId}'";
|
2011-02-06 00:20:51 +01:00
|
|
|
$res = $CC_DBC->GetOne($sql);
|
|
|
|
|
|
|
|
if(is_null($res))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return $res;
|
|
|
|
}
|
|
|
|
|
2011-02-06 01:10:34 +01:00
|
|
|
private function getLastGroupId() {
|
2011-02-06 00:20:51 +01:00
|
|
|
global $CC_DBC;
|
|
|
|
|
2011-02-06 01:10:34 +01:00
|
|
|
$sql = "SELECT MAX(group_id) from cc_show_schedule WHERE instance_id = '{$this->_instanceId}'";
|
2011-02-06 00:20:51 +01:00
|
|
|
$res = $CC_DBC->GetOne($sql);
|
|
|
|
|
|
|
|
return $res;
|
|
|
|
}
|
|
|
|
|
2011-02-06 01:10:34 +01:00
|
|
|
public function addPlaylistToShow($plId) {
|
2011-02-06 00:20:51 +01:00
|
|
|
|
|
|
|
$sched = new ScheduleGroup();
|
2011-02-06 01:10:34 +01:00
|
|
|
$lastGroupId = $this->getLastGroupId();
|
2011-02-06 01:42:03 +01:00
|
|
|
$pos = $this->getNextPos();
|
2011-02-06 00:20:51 +01:00
|
|
|
|
|
|
|
if(is_null($lastGroupId)) {
|
|
|
|
|
2011-02-06 07:10:07 +01:00
|
|
|
$groupId = $sched->add($this->_instanceId, $this->getShowStart(), null, $plId);
|
2011-02-06 00:20:51 +01:00
|
|
|
}
|
|
|
|
else {
|
2011-02-06 07:10:07 +01:00
|
|
|
$groupId = $sched->addPlaylistAfter($this->_instanceId, $lastGroupId, $plId);
|
2010-12-13 17:49:45 +01:00
|
|
|
}
|
|
|
|
|
2011-02-06 00:20:51 +01:00
|
|
|
$groupsched = new CcShowSchedule();
|
2011-02-06 01:10:34 +01:00
|
|
|
$groupsched->setDbInstanceId($this->_instanceId);
|
2011-02-06 00:20:51 +01:00
|
|
|
$groupsched->setDbGroupId($groupId);
|
|
|
|
$groupsched->setDbPosition($pos);
|
|
|
|
$groupsched->save();
|
|
|
|
}
|
|
|
|
|
2011-02-06 01:10:34 +01:00
|
|
|
public function scheduleShow($plIds) {
|
2011-02-06 00:20:51 +01:00
|
|
|
|
|
|
|
foreach($plIds as $plId) {
|
2011-02-06 01:10:34 +01:00
|
|
|
$this->addPlaylistToShow($plId);
|
2011-02-06 00:20:51 +01:00
|
|
|
}
|
2010-12-10 18:15:17 +01:00
|
|
|
}
|
2011-01-10 19:24:21 +01:00
|
|
|
|
2011-02-06 01:10:34 +01:00
|
|
|
public function removeGroupFromShow($group_id){
|
|
|
|
global $CC_DBC;
|
2011-02-06 00:20:51 +01:00
|
|
|
|
|
|
|
$group = CcShowScheduleQuery::create()
|
2011-02-06 01:10:34 +01:00
|
|
|
->filterByDbInstanceId($this->_instanceId)
|
2011-02-06 00:20:51 +01:00
|
|
|
->filterByDbGroupId($group_id)
|
|
|
|
->findOne();
|
|
|
|
|
|
|
|
$position = $group->getDbPosition();
|
|
|
|
|
|
|
|
$sql = "SELECT group_id FROM cc_show_schedule
|
2011-02-06 01:10:34 +01:00
|
|
|
WHERE instance_id = '{$this->_instanceId}' AND position > '{$position}'";
|
2011-02-06 00:20:51 +01:00
|
|
|
$followingGroups = $CC_DBC->GetAll($sql);
|
|
|
|
|
2011-02-06 01:10:34 +01:00
|
|
|
$sql = "SELECT SUM(clip_length) FROM cc_schedule WHERE group_id='{$group_id}'";
|
2011-02-06 00:20:51 +01:00
|
|
|
$group_length = $CC_DBC->GetOne($sql);
|
|
|
|
|
2011-02-06 01:10:34 +01:00
|
|
|
$sql = "DELETE FROM cc_schedule WHERE group_id = '{$group_id}'";
|
2011-02-06 00:20:51 +01:00
|
|
|
$CC_DBC->query($sql);
|
|
|
|
|
|
|
|
if(!is_null($followingGroups)) {
|
|
|
|
$sql_opt = array();
|
|
|
|
foreach ($followingGroups as $row) {
|
|
|
|
$sql_opt[] = "group_id = {$row["group_id"]}";
|
|
|
|
}
|
|
|
|
$sql_group_ids = join(" OR ", $sql_opt);
|
|
|
|
|
2011-02-06 01:10:34 +01:00
|
|
|
$sql = "UPDATE cc_schedule
|
2011-02-06 00:20:51 +01:00
|
|
|
SET starts = (starts - INTERVAL '{$group_length}'), ends = (ends - INTERVAL '{$group_length}')
|
|
|
|
WHERE " . $sql_group_ids;
|
|
|
|
$CC_DBC->query($sql);
|
|
|
|
}
|
|
|
|
|
|
|
|
$group->delete();
|
|
|
|
}
|
|
|
|
|
2011-02-06 01:10:34 +01:00
|
|
|
public function clearShow() {
|
|
|
|
|
2011-02-06 00:20:51 +01:00
|
|
|
$groups = CcShowScheduleQuery::create()
|
2011-02-06 01:10:34 +01:00
|
|
|
->filterByDbInstanceId($this->_instanceId)
|
2011-02-06 00:20:51 +01:00
|
|
|
->find();
|
|
|
|
|
|
|
|
foreach($groups as $group) {
|
|
|
|
$groupId = $group->getDbGroupId();
|
|
|
|
CcScheduleQuery::create()
|
|
|
|
->filterByDbGroupId($groupId)
|
|
|
|
->delete();
|
|
|
|
|
|
|
|
$group->delete();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-06 02:39:35 +01:00
|
|
|
public function deleteShow() {
|
|
|
|
|
|
|
|
$this->clearShow();
|
|
|
|
|
|
|
|
$showInstance = CcShowInstancesQuery::create()
|
|
|
|
->findPK($this->_instanceId)
|
|
|
|
->delete();
|
|
|
|
}
|
|
|
|
|
2011-02-06 01:10:34 +01:00
|
|
|
public function getTimeScheduled() {
|
|
|
|
|
|
|
|
$start_timestamp = $this->getShowStart();
|
|
|
|
$end_timestamp = $this->getShowEnd();
|
2011-02-06 00:20:51 +01:00
|
|
|
|
|
|
|
$time = Schedule::getTimeScheduledInRange($start_timestamp, $end_timestamp);
|
|
|
|
|
|
|
|
return $time;
|
|
|
|
}
|
|
|
|
|
2011-02-06 01:10:34 +01:00
|
|
|
public function getTimeUnScheduled() {
|
|
|
|
|
|
|
|
$start_timestamp = $this->getShowStart();
|
|
|
|
$end_timestamp = $this->getShowEnd();
|
2011-02-06 00:20:51 +01:00
|
|
|
|
|
|
|
$time = Schedule::getTimeUnScheduledInRange($start_timestamp, $end_timestamp);
|
|
|
|
|
|
|
|
return $time;
|
|
|
|
}
|
|
|
|
|
2011-02-06 01:10:34 +01:00
|
|
|
public function getPercentScheduledInRange(){
|
2011-02-06 00:20:51 +01:00
|
|
|
|
2011-02-06 01:10:34 +01:00
|
|
|
$start_timestamp = $this->getShowStart();
|
|
|
|
$end_timestamp = $this->getShowEnd();
|
2011-02-06 00:20:51 +01:00
|
|
|
|
2011-02-06 01:42:03 +01:00
|
|
|
return Schedule::getPercentScheduledInRange($start_timestamp, $end_timestamp);
|
2011-02-06 01:10:34 +01:00
|
|
|
}
|
2011-02-06 00:20:51 +01:00
|
|
|
|
2011-02-06 01:10:34 +01:00
|
|
|
public function getShowLength(){
|
2011-01-16 00:23:15 +01:00
|
|
|
global $CC_DBC;
|
|
|
|
|
2011-02-06 01:10:34 +01:00
|
|
|
$start_timestamp = $this->getShowStart();
|
|
|
|
$end_timestamp = $this->getShowEnd();
|
|
|
|
|
2011-01-16 00:23:15 +01:00
|
|
|
$sql = "SELECT TIMESTAMP '{$end_timestamp}' - TIMESTAMP '{$start_timestamp}' ";
|
|
|
|
$length = $CC_DBC->GetOne($sql);
|
|
|
|
|
|
|
|
return $length;
|
|
|
|
}
|
|
|
|
|
2011-02-06 01:10:34 +01:00
|
|
|
public function searchPlaylistsForShow($datatables){
|
2011-01-10 19:24:21 +01:00
|
|
|
|
2011-02-06 01:10:34 +01:00
|
|
|
$length = $this->getTimeUnScheduled();
|
2011-01-10 19:24:21 +01:00
|
|
|
|
2011-01-28 00:38:02 +01:00
|
|
|
return StoredFile::searchPlaylistsForSchedule($length, $datatables);
|
2011-01-10 19:24:21 +01:00
|
|
|
}
|
2011-02-06 00:20:51 +01:00
|
|
|
|
|
|
|
public function getShowListContent() {
|
|
|
|
global $CC_DBC;
|
|
|
|
|
|
|
|
$sql = "SELECT *
|
|
|
|
FROM (cc_show_schedule AS ss LEFT JOIN cc_schedule AS s USING(group_id)
|
|
|
|
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 ss.instance_id = '{$this->_instanceId}' ORDER BY starts";
|
|
|
|
|
|
|
|
return $CC_DBC->GetAll($sql);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getShowContent() {
|
|
|
|
global $CC_DBC;
|
|
|
|
|
|
|
|
$res = $this->getShowListContent();
|
|
|
|
|
|
|
|
if(count($res) <= 0) {
|
|
|
|
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[$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);
|
|
|
|
|
|
|
|
$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"];
|
|
|
|
}
|
|
|
|
|
|
|
|
return $items;
|
|
|
|
}
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
2011-02-05 00:22:15 +01:00
|
|
|
|
|
|
|
/* Show Data Access Layer */
|
|
|
|
class Show_DAL{
|
|
|
|
|
|
|
|
/* Given a group_id, get all show data related to
|
|
|
|
* id. This is useful in the case where you have an item
|
|
|
|
* in the schedule table and you want to find out more about
|
|
|
|
* the show it is in without joining the schedule and show tables
|
|
|
|
* (which causes problems with duplicate items)
|
|
|
|
*/
|
|
|
|
public static function GetShowData($group_id){
|
|
|
|
global $CC_DBC;
|
|
|
|
|
|
|
|
$sql="SELECT * FROM cc_show_schedule as ss, cc_show as s"
|
|
|
|
." WHERE ss.show_id = s.id"
|
|
|
|
." AND ss.group_id = $group_id"
|
|
|
|
." LIMIT 1";
|
|
|
|
|
|
|
|
return $CC_DBC->GetOne($sql);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Given a show ID, this function returns what group IDs
|
|
|
|
* are present in this show. */
|
|
|
|
public static function GetShowGroupIDs($showID){
|
|
|
|
global $CC_CONFIG, $CC_DBC;
|
|
|
|
|
|
|
|
$sql = "SELECT group_id"
|
|
|
|
." FROM $CC_CONFIG[showSchedule]"
|
|
|
|
." WHERE show_id = $showID";
|
|
|
|
|
|
|
|
$rows = $CC_DBC->GetAll($sql);
|
|
|
|
return $rows;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|