CC-3030: Repeating shows is broken in devel branch.
-working towards using only DateTime objects
This commit is contained in:
parent
74d3c3aebc
commit
42cde33648
7 changed files with 95 additions and 52 deletions
|
@ -352,7 +352,10 @@ class ApiController extends Zend_Controller_Action
|
|||
$now = new DateTime($today_timestamp);
|
||||
$end_timestamp = $now->add(new DateInterval("PT2H"));
|
||||
$end_timestamp = $end_timestamp->format("Y-m-d H:i:s");
|
||||
$this->view->shows = Application_Model_Show::getShows($today_timestamp, $end_timestamp, $excludeInstance=NULL, $onlyRecord=TRUE);
|
||||
|
||||
$this->view->shows = Application_Model_Show::getShows(Application_Model_DateHelper::ConvertToUtcDateTime($today_timestamp, date_default_timezone_get()),
|
||||
Application_Model_DateHelper::ConvertToUtcDateTime($end_timestamp, date_default_timezone_get()),
|
||||
$excludeInstance=NULL, $onlyRecord=TRUE);
|
||||
|
||||
|
||||
$this->view->is_recording = false;
|
||||
|
|
|
@ -68,8 +68,8 @@ class ScheduleController extends Zend_Controller_Action
|
|||
|
||||
public function eventFeedAction()
|
||||
{
|
||||
$start = $this->_getParam('start', null);
|
||||
$end = $this->_getParam('end', null);
|
||||
$start = new DateTime($this->_getParam('start', null));
|
||||
$end = new DateTime($this->_getParam('end', null));
|
||||
|
||||
$userInfo = Zend_Auth::getInstance()->getStorage()->read();
|
||||
$user = new Application_Model_User($userInfo->id);
|
||||
|
@ -355,11 +355,14 @@ class ScheduleController extends Zend_Controller_Action
|
|||
$this->view->show_error = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
$start_timestamp = $show->getShowStart();
|
||||
$end_timestamp = $show->getShowEnd();
|
||||
|
||||
//check to make sure show doesn't overlap.
|
||||
if(Application_Model_Show::getShows($start_timestamp, $end_timestamp, array($showInstanceId))) {
|
||||
if(Application_Model_Show::getShows(new DateTime($start_timestamp, new DateTimeZone("UTC")),
|
||||
new DateTime($end_timestamp, new DateTimeZone("UTC")),
|
||||
array($showInstanceId))) {
|
||||
$this->view->error = "cannot schedule an overlapping show.";
|
||||
return;
|
||||
}
|
||||
|
@ -563,7 +566,7 @@ class ScheduleController extends Zend_Controller_Action
|
|||
foreach($js as $j){
|
||||
$data[$j["name"]] = $j["value"];
|
||||
}
|
||||
Logging::log("id:".$data['add_show_id']);
|
||||
|
||||
$show = new Application_Model_Show($data['add_show_id']);
|
||||
|
||||
$startDateModified = true;
|
||||
|
|
|
@ -119,12 +119,34 @@ class Application_Model_Preference
|
|||
$view->headTitle(self::GetHeadTitle());
|
||||
}
|
||||
|
||||
public static function SetShowsPopulatedUntil($timestamp) {
|
||||
self::SetValue("shows_populated_until", $timestamp);
|
||||
/**
|
||||
* Set the furthest date that a never-ending show
|
||||
* should be populated until.
|
||||
*
|
||||
* @param DateTime $dateTime
|
||||
* A row from cc_show_days table
|
||||
*/
|
||||
public static function SetShowsPopulatedUntil($dateTime) {
|
||||
self::SetValue("shows_populated_until", $dateTime->format("Y-m-d"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the furthest date that a never-ending show
|
||||
* should be populated until.
|
||||
*
|
||||
* Returns null if the value hasn't been set, otherwise returns
|
||||
* a DateTime object representing the date.
|
||||
*
|
||||
* @return DateTime (in UTC Timezone)
|
||||
*/
|
||||
public static function GetShowsPopulatedUntil() {
|
||||
return self::GetValue("shows_populated_until");
|
||||
$date = self::GetValue("shows_populated_until");
|
||||
|
||||
if ($date == ""){
|
||||
return null;
|
||||
} else {
|
||||
return new DateTime($date, new DateTimeZone("UTC"));
|
||||
}
|
||||
}
|
||||
|
||||
public static function SetDefaultFade($fade) {
|
||||
|
|
|
@ -74,13 +74,13 @@ class Application_Model_RabbitMq
|
|||
$EXCHANGE = 'airtime-show-recorder';
|
||||
$channel->exchange_declare($EXCHANGE, 'direct', false, true);
|
||||
|
||||
$now = new DateTime("@".time());
|
||||
$end_timestamp = new DateTime("@".(time() + 3600*2));
|
||||
$now = new DateTime("@".time()); //in UTC timezone
|
||||
$end_timestamp = new DateTime("@".(time() + 3600*2)); //in UTC timezone
|
||||
|
||||
$temp['event_type'] = $event_type;
|
||||
$temp['server_timezone'] = Application_Model_Preference::GetTimezone();
|
||||
if($event_type = "update_schedule"){
|
||||
$temp['shows'] = Application_Model_Show::getShows($now->format("Y-m-d H:i:s"), $end_timestamp->format("Y-m-d H:i:s"), $excludeInstance=NULL, $onlyRecord=TRUE);
|
||||
$temp['shows'] = Application_Model_Show::getShows($now, $end_timestamp, $excludeInstance=NULL, $onlyRecord=TRUE);
|
||||
}
|
||||
$data = json_encode($temp);
|
||||
$msg = new AMQPMessage($data, array('content_type' => 'text/plain'));
|
||||
|
|
|
@ -736,7 +736,6 @@ class Application_Model_Show {
|
|||
*/
|
||||
public static function create($data)
|
||||
{
|
||||
|
||||
$startDateTime = new DateTime($data['add_show_start_date']." ".$data['add_show_start_time']);
|
||||
$utcStartDateTime = clone $startDateTime;
|
||||
$utcStartDateTime->setTimezone(new DateTimeZone('UTC'));
|
||||
|
@ -888,7 +887,7 @@ class Application_Model_Show {
|
|||
$showHost->save();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Application_Model_Show::populateShowUntil($showId);
|
||||
Application_Model_RabbitMq::PushSchedule();
|
||||
return $showId;
|
||||
|
@ -910,14 +909,14 @@ class Application_Model_Show {
|
|||
if (is_null($p_dateTime)) {
|
||||
$date = Application_Model_Preference::GetShowsPopulatedUntil();
|
||||
|
||||
if ($date == "") {
|
||||
if (is_null($date)) {
|
||||
$p_dateTime = new DateTime("now", new DateTimeZone('UTC'));
|
||||
Application_Model_Preference::SetShowsPopulatedUntil($p_dateTime->format("Y-m-d"));
|
||||
Application_Model_Preference::SetShowsPopulatedUntil($p_dateTime);
|
||||
} else {
|
||||
$p_dateTime = new DateTime($date, new DateTimeZone('UTC'));
|
||||
$p_dateTime = $date;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$sql = "SELECT * FROM cc_show_days WHERE show_id = $p_showId";
|
||||
$res = $CC_DBC->GetAll($sql);
|
||||
|
||||
|
@ -937,8 +936,7 @@ class Application_Model_Show {
|
|||
* @param DateTime $p_dateTime
|
||||
* DateTime object in UTC time.
|
||||
*/
|
||||
private static function populateShow($p_showRow, $p_dateTime) {
|
||||
|
||||
private static function populateShow($p_showRow, $p_dateTime) {
|
||||
if($p_showRow["repeat_type"] == -1) {
|
||||
Application_Model_Show::populateNonRepeatingShow($p_showRow, $p_dateTime);
|
||||
}
|
||||
|
@ -1033,7 +1031,7 @@ class Application_Model_Show {
|
|||
private static function populateRepeatingShow($p_showRow, $p_dateTime, $p_interval)
|
||||
{
|
||||
global $CC_DBC;
|
||||
|
||||
|
||||
$show_id = $p_showRow["show_id"];
|
||||
$next_pop_date = $p_showRow["next_pop_date"];
|
||||
$first_show = $p_showRow["first_show"]; //non-UTC
|
||||
|
@ -1059,10 +1057,11 @@ class Application_Model_Show {
|
|||
|
||||
$date = new Application_Model_DateHelper();
|
||||
$currentUtcTimestamp = $date->getUtcTimestamp();
|
||||
|
||||
while($utcStartDateTime->getTimestamp() <= $p_dateTime->getTimestamp() &&
|
||||
|
||||
while($utcStartDateTime->getTimestamp()
|
||||
<= $p_dateTime->getTimestamp() &&
|
||||
($utcStartDateTime->getTimestamp() < strtotime($last_show) || is_null($last_show))) {
|
||||
|
||||
|
||||
$utcStart = $utcStartDateTime->format("Y-m-d H:i:s");
|
||||
$sql = "SELECT timestamp '{$utcStart}' + interval '{$duration}'";
|
||||
$utcEndDateTime = new DateTime($CC_DBC->GetOne($sql), new DateTimeZone("UTC"));
|
||||
|
@ -1136,12 +1135,12 @@ class Application_Model_Show {
|
|||
}
|
||||
|
||||
/**
|
||||
* Get all the show instances in the given time range.
|
||||
* Get all the show instances in the given time range (inclusive).
|
||||
*
|
||||
* @param string $start_timestamp
|
||||
* In the format "YYYY-MM-DD HH:mm:ss". This time is inclusive.
|
||||
* @param string $end_timestamp
|
||||
* In the format "YYYY-MM-DD HH:mm:ss". This time is inclusive.
|
||||
* @param DateTime $start_timestamp
|
||||
* In UTC time.
|
||||
* @param DateTime $end_timestamp
|
||||
* In UTC time.
|
||||
* @param unknown_type $excludeInstance
|
||||
* @param boolean $onlyRecord
|
||||
* @return array
|
||||
|
@ -1153,7 +1152,7 @@ class Application_Model_Show {
|
|||
$showsPopUntil = Application_Model_Preference::GetShowsPopulatedUntil();
|
||||
|
||||
//if application is requesting shows past our previous populated until date, generate shows up until this point.
|
||||
if ($showsPopUntil == "" || strtotime($showsPopUntil) < strtotime($end_timestamp)) {
|
||||
if (is_null($showsPopUntil) || $showsPopUntil->getTimestamp() < $end_timestamp->getTimestamp()) {
|
||||
Application_Model_Show::populateAllShowsInRange($showsPopUntil, $end_timestamp);
|
||||
Application_Model_Preference::SetShowsPopulatedUntil($end_timestamp);
|
||||
}
|
||||
|
@ -1164,16 +1163,18 @@ class Application_Model_Show {
|
|||
LEFT JOIN cc_show ON cc_show.id = cc_show_instances.show_id";
|
||||
|
||||
//only want shows that are starting at the time or later.
|
||||
$start_string = $start_timestamp->format("Y-m-d H:i:s");
|
||||
$end_string = $end_timestamp->format("Y-m-d H:i:s");
|
||||
if ($onlyRecord) {
|
||||
|
||||
$sql = $sql." WHERE (starts >= '{$start_timestamp}' AND starts < timestamp '{$end_timestamp}')";
|
||||
$sql = $sql." WHERE (starts >= '{$start_string}' AND starts < timestamp '{$end_string}')";
|
||||
$sql = $sql." AND (record = 1)";
|
||||
}
|
||||
else {
|
||||
|
||||
$sql = $sql." WHERE ((starts >= '{$start_timestamp}' AND starts < '{$end_timestamp}')
|
||||
OR (ends > '{$start_timestamp}' AND ends <= '{$end_timestamp}')
|
||||
OR (starts <= '{$start_timestamp}' AND ends >= '{$end_timestamp}'))";
|
||||
$sql = $sql." WHERE ((starts >= '{$start_string}' AND starts < '{$end_string}')
|
||||
OR (ends > '{$start_string}' AND ends <= '{$end_string}')
|
||||
OR (starts <= '{$start_string}' AND ends >= '{$end_string}'))";
|
||||
}
|
||||
|
||||
|
||||
|
@ -1206,25 +1207,28 @@ class Application_Model_Show {
|
|||
/**
|
||||
* Generate all the repeating shows in the given range.
|
||||
*
|
||||
* @param string $p_startTimestamp
|
||||
* In the format "YYYY-MM-DD HH:mm:ss"
|
||||
* @param string $p_endTimestamp
|
||||
* In the format "YYYY-MM-DD HH:mm:ss"
|
||||
* @param DateTime $p_startTimestamp
|
||||
* In UTC format.
|
||||
* @param DateTime $p_endTimestamp
|
||||
* In UTC format.
|
||||
*/
|
||||
public static function populateAllShowsInRange($p_startTimestamp, $p_endTimestamp)
|
||||
{
|
||||
global $CC_DBC;
|
||||
|
||||
if ($p_startTimestamp != "") {
|
||||
|
||||
$endTimeString = $p_endTimestamp->format("Y-m-d H:i:s");
|
||||
if (!is_null($p_startTimestamp)) {
|
||||
$startTimeString = $p_startTimestamp->format("Y-m-d H:i:s");
|
||||
$sql = "SELECT * FROM cc_show_days
|
||||
WHERE last_show IS NULL
|
||||
OR first_show < '{$p_endTimestamp}' AND last_show > '{$p_startTimestamp}'";
|
||||
OR first_show < '{$endTimeString}' AND last_show > '{$startTimeString}'";
|
||||
}
|
||||
else {
|
||||
$today_timestamp = date("Y-m-d");
|
||||
$today_timestamp = new DateTime("now", new DateTimeZone("UTC"));
|
||||
$today_timestamp_string = $today_timestamp->format("Y-m-d H:i:s");
|
||||
$sql = "SELECT * FROM cc_show_days
|
||||
WHERE last_show IS NULL
|
||||
OR first_show < '{$p_endTimestamp}' AND last_show > '{$today_timestamp}'";
|
||||
OR first_show < '{$endTimeString}' AND last_show > '{$today_timestamp_string}'";
|
||||
}
|
||||
|
||||
$res = $CC_DBC->GetAll($sql);
|
||||
|
@ -1236,19 +1240,17 @@ class Application_Model_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"
|
||||
* @param DateTime $start
|
||||
* -in UTC time
|
||||
* @param DateTime $end
|
||||
* -in UTC time
|
||||
* @param boolean $editable
|
||||
*/
|
||||
public static function getFullCalendarEvents($start, $end, $editable=false)
|
||||
{
|
||||
$events = array();
|
||||
|
||||
$start_range = new DateTime($start);
|
||||
$end_range = new DateTime($end);
|
||||
$interval = $start_range->diff($end_range);
|
||||
$interval = $start->diff($end);
|
||||
$days = $interval->format('%a');
|
||||
|
||||
$shows = Application_Model_Show::getShows($start, $end);
|
||||
|
|
|
@ -51,11 +51,21 @@ class Application_Model_ShowInstance {
|
|||
return $show->getDbGenre();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the start time of the Show (UTC time)
|
||||
* @return string in format "Y-m-d H:i:s" (PHP time notation)
|
||||
* TODO: make this function return a DateTime object instead.
|
||||
*/
|
||||
public function getShowStart()
|
||||
{
|
||||
return $this->_showInstance->getDbStarts();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the end time of the Show (UTC time)
|
||||
* @return string in format "Y-m-d H:i:s" (PHP time notation)
|
||||
* TODO: make this function return a DateTime object instead.
|
||||
*/
|
||||
public function getShowEnd()
|
||||
{
|
||||
return $this->_showInstance->getDbEnds();
|
||||
|
@ -184,16 +194,18 @@ class Application_Model_ShowInstance {
|
|||
|
||||
$sql = "SELECT timestamp '{$starts}' + interval '{$deltaDay} days' + interval '{$hours}:{$mins}'";
|
||||
$new_starts = $CC_DBC->GetOne($sql);
|
||||
$newStartsDateTime = new DateTime($new_starts, new DateTimeZone("UTC"));
|
||||
|
||||
$sql = "SELECT timestamp '{$ends}' + interval '{$deltaDay} days' + interval '{$hours}:{$mins}'";
|
||||
$new_ends = $CC_DBC->GetOne($sql);
|
||||
$newEndsDateTime = new DateTime($new_ends, new DateTimeZone("UTC"));
|
||||
|
||||
$newStartsDateTime = new DateTime($new_starts, new DateTimeZone("UTC"));
|
||||
|
||||
if($today_timestamp > $newStartsDateTime->getTimestamp()) {
|
||||
return "Can't move show into past";
|
||||
}
|
||||
|
||||
$overlap = Application_Model_Show::getShows($new_starts, $new_ends, array($this->_instanceId));
|
||||
$overlap = Application_Model_Show::getShows($newStartsDateTime, $newEndsDateTime, array($this->_instanceId));
|
||||
|
||||
if(count($overlap) > 0) {
|
||||
return "Should not overlap shows";
|
||||
|
@ -247,6 +259,7 @@ class Application_Model_ShowInstance {
|
|||
|
||||
//only need to check overlap if show increased in size.
|
||||
if(strtotime($new_ends) > strtotime($ends)) {
|
||||
//TODO --martin
|
||||
$overlap = Application_Model_Show::getShows($ends, $new_ends);
|
||||
|
||||
if(count($overlap) > 0) {
|
||||
|
|
|
@ -66,7 +66,7 @@ function createTestShow($showNumber, $showTime, $duration = "1:00")
|
|||
//echo "show created, ID: $showId\n";
|
||||
|
||||
// populating the show with a playlist
|
||||
$instances = Application_Model_Show::getShows($showTime->format("Y-m-d H:i:s"), $showTime->format("Y-m-d H:i:s"));
|
||||
$instances = Application_Model_Show::getShows($showTime, $showTime);
|
||||
$instance = array_pop($instances);
|
||||
$show = new Application_Model_ShowInstance($instance["instance_id"]);
|
||||
//echo "Adding playlist to show instance ".$show->getShowInstanceId()."\n";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue