Merge branch '2.5.x' of dev.sourcefabric.org:airtime into 2.5.x

This commit is contained in:
Naomi 2013-10-02 11:25:08 -04:00
commit faa6c7210c
11 changed files with 134 additions and 26 deletions

View File

@ -35,6 +35,7 @@ class ScheduleController extends Zend_Controller_Action
->addActionContext('calculate-duration', 'json') ->addActionContext('calculate-duration', 'json')
->addActionContext('get-current-show', 'json') ->addActionContext('get-current-show', 'json')
->addActionContext('update-future-is-scheduled', 'json') ->addActionContext('update-future-is-scheduled', 'json')
->addActionContext('localize-start-end-time', 'json')
->initContext(); ->initContext();
$this->sched_sess = new Zend_Session_Namespace("schedule"); $this->sched_sess = new Zend_Session_Namespace("schedule");
@ -644,4 +645,19 @@ class ScheduleController extends Zend_Controller_Action
$this->_helper->json->sendJson(array("redrawLibTable" => $redrawLibTable)); $this->_helper->json->sendJson(array("redrawLibTable" => $redrawLibTable));
} }
public function localizeStartEndTimeAction()
{
$newTimezone = $this->_getParam('newTimezone');
$oldTimezone = $this->_getParam('oldTimezone');
$localTime = array();
$localTime["start"] = Application_Service_ShowFormService::localizeDateTime(
$this->_getParam('startDate'), $this->_getParam('startTime'), $newTimezone, $oldTimezone);
$localTime["end"] = Application_Service_ShowFormService::localizeDateTime(
$this->_getParam('endDate'), $this->_getParam('endTime'), $newTimezone, $oldTimezone);
$this->_helper->json->sendJson($localTime);
}
} }

View File

@ -104,6 +104,10 @@ class Application_Form_AddShowRepeats extends Zend_Form_SubForm
} }
} }
if (!isset($formData['add_show_day_check'])) {
$this->getElement('add_show_day_check')->setErrors(array(_('Please select a repeat day')));
}
return true; return true;
} }

View File

@ -78,6 +78,15 @@ class Application_Form_AddShowWhen extends Zend_Form_SubForm
'decorators' => array('ViewHelper') 'decorators' => array('ViewHelper')
)); ));
$timezone = new Zend_Form_Element_Select('add_show_timezone');
$timezone->setRequired(true)
->setLabel(_("Timezone:"))
->setMultiOptions(Application_Common_Timezone::getTimezones())
->setValue(Application_Model_Preference::GetDefaultTimezone())
->setAttrib('class', 'input_select add_show_input_select')
->setDecorators(array('ViewHelper'));
$this->addElement($timezone);
// Add repeats element // Add repeats element
$this->addElement('checkbox', 'add_show_repeats', array( $this->addElement('checkbox', 'add_show_repeats', array(
'label' => _('Repeats?'), 'label' => _('Repeats?'),
@ -158,7 +167,7 @@ class Application_Form_AddShowWhen extends Zend_Form_SubForm
*/ */
if ($valid) { if ($valid) {
$utc = new DateTimeZone('UTC'); $utc = new DateTimeZone('UTC');
$localTimezone = new DateTimeZone(Application_Model_Preference::GetTimezone()); $showTimezone = new DateTimeZone($formData["add_show_timezone"]);
$show_start = new DateTime($start_time); $show_start = new DateTime($start_time);
$show_start->setTimezone($utc); $show_start->setTimezone($utc);
$show_end = new DateTime($end_time); $show_end = new DateTime($end_time);
@ -202,13 +211,17 @@ class Application_Form_AddShowWhen extends Zend_Form_SubForm
$overlapping = Application_Model_Schedule::checkOverlappingShows( $overlapping = Application_Model_Schedule::checkOverlappingShows(
$show_start, $show_end); $show_start, $show_end);
} }
//$overlapping = Application_Model_Schedule::checkOverlappingShows($show_start, $show_end, $update, $instanceId);
/* Check if repeats overlap with previously scheduled shows /* Check if repeats overlap with previously scheduled shows
* Do this for each show day * Do this for each show day
*/ */
if (!$overlapping) { if (!$overlapping) {
$startDow = date("w", $show_start->getTimestamp()); $startDow = date("w", $show_start->getTimestamp());
if (!isset($formData['add_show_day_check'])) {
return false;
}
foreach ($formData["add_show_day_check"] as $day) { foreach ($formData["add_show_day_check"] as $day) {
$repeatShowStart = clone $show_start; $repeatShowStart = clone $show_start;
$repeatShowEnd = clone $show_end; $repeatShowEnd = clone $show_end;
@ -224,8 +237,8 @@ class Application_Form_AddShowWhen extends Zend_Form_SubForm
* adding the interval for the next repeating show * adding the interval for the next repeating show
*/ */
$repeatShowStart->setTimezone($localTimezone); $repeatShowStart->setTimezone($showTimezone);
$repeatShowEnd->setTimezone($localTimezone); $repeatShowEnd->setTimezone($showTimezone);
$repeatShowStart->add(new DateInterval("P".$daysAdd."D")); $repeatShowStart->add(new DateInterval("P".$daysAdd."D"));
$repeatShowEnd->add(new DateInterval("P".$daysAdd."D")); $repeatShowEnd->add(new DateInterval("P".$daysAdd."D"));
//set back to UTC //set back to UTC
@ -264,8 +277,8 @@ class Application_Form_AddShowWhen extends Zend_Form_SubForm
$this->getElement('add_show_duration')->setErrors(array(_('Cannot schedule overlapping shows'))); $this->getElement('add_show_duration')->setErrors(array(_('Cannot schedule overlapping shows')));
break 1; break 1;
} else { } else {
$repeatShowStart->setTimezone($localTimezone); $repeatShowStart->setTimezone($showTimezone);
$repeatShowEnd->setTimezone($localTimezone); $repeatShowEnd->setTimezone($showTimezone);
$repeatShowStart->add(new DateInterval($interval)); $repeatShowStart->add(new DateInterval($interval));
$repeatShowEnd->add(new DateInterval($interval)); $repeatShowEnd->add(new DateInterval($interval));
$repeatShowStart->setTimezone($utc); $repeatShowStart->setTimezone($utc);
@ -328,7 +341,7 @@ class Application_Form_AddShowWhen extends Zend_Form_SubForm
* show start back to local time * show start back to local time
*/ */
$rebroadcastShowStart->setTimezone(new DateTimeZone( $rebroadcastShowStart->setTimezone(new DateTimeZone(
Application_Model_Preference::GetTimezone())); $formData["add_show_timezone"]));
$rebroadcastWhenDays = explode(" ", $formData["add_show_rebroadcast_date_".$i]); $rebroadcastWhenDays = explode(" ", $formData["add_show_rebroadcast_date_".$i]);
$rebroadcastWhenTime = explode(":", $formData["add_show_rebroadcast_time_".$i]); $rebroadcastWhenTime = explode(":", $formData["add_show_rebroadcast_time_".$i]);
$rebroadcastShowStart->add(new DateInterval("P".$rebroadcastWhenDays[0]."D")); $rebroadcastShowStart->add(new DateInterval("P".$rebroadcastWhenDays[0]."D"));

View File

@ -505,12 +505,14 @@ class Application_Model_Preference
return self::getValue("description"); return self::getValue("description");
} }
// Sets station default timezone (from preferences)
public static function SetDefaultTimezone($timezone) public static function SetDefaultTimezone($timezone)
{ {
self::setValue("timezone", $timezone); self::setValue("timezone", $timezone);
date_default_timezone_set($timezone); date_default_timezone_set($timezone);
} }
// Returns station default timezone (from preferences)
public static function GetDefaultTimezone() public static function GetDefaultTimezone()
{ {
return self::getValue("timezone"); return self::getValue("timezone");
@ -536,6 +538,7 @@ class Application_Model_Preference
} }
} }
// Always attempts to returns the current user's personal timezone setting
public static function GetTimezone() public static function GetTimezone()
{ {
$auth = Zend_Auth::getInstance(); $auth = Zend_Auth::getInstance();

View File

@ -31,6 +31,7 @@ class CcShowDays extends BaseCcShowDays {
return $dt; return $dt;
} }
// Returns the start of a show in the timezone it was created in
public function getLocalStartDateAndTime() public function getLocalStartDateAndTime()
{ {
$dt = new DateTime( $dt = new DateTime(
@ -38,16 +39,16 @@ class CcShowDays extends BaseCcShowDays {
new DateTimeZone($this->getDbTimezone()) new DateTimeZone($this->getDbTimezone())
); );
//make timezone current user specific //set timezone to that of the show
$dt->setTimezone(new DateTimeZone(Application_Model_Preference::GetTimezone())); $dt->setTimezone(new DateTimeZone($this->getDbTimezone()));
return $dt; return $dt;
} }
/** /**
* *
* Enter description here ... * Returns the end of a show in the timezone it was created in
* @param DateTime $startDateTime first show in user's local time * @param DateTime $startDateTime first show in show's local time
*/ */
public function getLocalEndDateAndTime($showStart) public function getLocalEndDateAndTime($showStart)
{ {

View File

@ -150,6 +150,7 @@ class Application_Service_ShowFormService
'add_show_end_date_no_repeat' => $showEnd->format("Y-m-d"), 'add_show_end_date_no_repeat' => $showEnd->format("Y-m-d"),
'add_show_end_time' => $showEnd->format("H:i"), 'add_show_end_time' => $showEnd->format("H:i"),
'add_show_duration' => $ccShowDay->formatDuration(true), 'add_show_duration' => $ccShowDay->formatDuration(true),
'add_show_timezone' => $ccShowDay->getDbTimezone(),
'add_show_repeats' => $ccShowDay->isRepeating() ? 1 : 0)); 'add_show_repeats' => $ccShowDay->isRepeating() ? 1 : 0));
return $showStart; return $showStart;
@ -159,13 +160,16 @@ class Application_Service_ShowFormService
{ {
$ccShowInstance = CcShowInstancesQuery::create()->findPk($this->instanceId); $ccShowInstance = CcShowInstancesQuery::create()->findPk($this->instanceId);
$timezone = new DateTimeZone(Application_Model_Preference::GetTimezone()); //get timezone the show is created in
$timezone = $ccShowInstance->getCcShow()->getFirstCcShowDay()->getDbTimezone();
//$timezone = new DateTimeZone(Application_Model_Preference::GetDefaultTimezone());
//DateTime object in UTC //DateTime object in UTC
$showStart = $ccShowInstance->getDbStarts(null); $showStart = $ccShowInstance->getDbStarts(null);
$showStart->setTimezone($timezone); $showStart->setTimezone(new DateTimeZone($timezone));
$showEnd = $ccShowInstance->getDbEnds(null); $showEnd = $ccShowInstance->getDbEnds(null);
$showEnd->setTimezone($timezone); $showEnd->setTimezone(new DateTimeZone($timezone));
//if the show has started, do not allow editing on the start time //if the show has started, do not allow editing on the start time
if ($showStart->getTimestamp() <= time()) { if ($showStart->getTimestamp() <= time()) {
@ -180,6 +184,7 @@ class Application_Service_ShowFormService
'add_show_end_time' => $showEnd->format("H:i"), 'add_show_end_time' => $showEnd->format("H:i"),
'add_show_duration' => $this->calculateDuration( 'add_show_duration' => $this->calculateDuration(
$showStart->format("Y-m-d H:i:s"), $showEnd->format("Y-m-d H:i:s")), $showStart->format("Y-m-d H:i:s"), $showEnd->format("Y-m-d H:i:s")),
'add_show_timezone' => $timezone,
'add_show_repeats' => 0)); 'add_show_repeats' => 0));
$form->getElement('add_show_repeats')->setOptions(array("disabled" => true)); $form->getElement('add_show_repeats')->setOptions(array("disabled" => true));
@ -300,13 +305,14 @@ class Application_Service_ShowFormService
private function populateFormRebroadcastAbsolute($form) private function populateFormRebroadcastAbsolute($form)
{ {
$absolutRebroadcasts = $this->ccShow->getRebroadcastsAbsolute(); $absolutRebroadcasts = $this->ccShow->getRebroadcastsAbsolute();
$timezone = $this->ccShow->getFirstCcShowDay()->getDbTimezone();
$formValues = array(); $formValues = array();
$i = 1; $i = 1;
foreach ($absolutRebroadcasts as $ar) { foreach ($absolutRebroadcasts as $ar) {
//convert dates to user's local time //convert dates to user's local time
$start = new DateTime($ar->getDbStarts(), new DateTimeZone("UTC")); $start = new DateTime($ar->getDbStarts(), new DateTimeZone("UTC"));
$start->setTimezone(new DateTimeZone(Application_Model_Preference::GetTimezone())); $start->setTimezone(new DateTimeZone($timezone));
$formValues["add_show_rebroadcast_date_absolute_$i"] = $start->format("Y-m-d"); $formValues["add_show_rebroadcast_date_absolute_$i"] = $start->format("Y-m-d");
$formValues["add_show_rebroadcast_time_absolute_$i"] = $start->format("H:i"); $formValues["add_show_rebroadcast_time_absolute_$i"] = $start->format("H:i");
$i++; $i++;
@ -389,10 +395,10 @@ class Application_Service_ShowFormService
$starts = new DateTime($ccShowInstance->getDbStarts(), new DateTimeZone("UTC")); $starts = new DateTime($ccShowInstance->getDbStarts(), new DateTimeZone("UTC"));
$ends = new DateTime($ccShowInstance->getDbEnds(), new DateTimeZone("UTC")); $ends = new DateTime($ccShowInstance->getDbEnds(), new DateTimeZone("UTC"));
$userTimezone = Application_Model_Preference::GetTimezone(); $showTimezone = $this->ccShow->getFirstCcShowDay()->getDbTimezone();
$starts->setTimezone(new DateTimeZone($userTimezone)); $starts->setTimezone(new DateTimeZone($showTimezone));
$ends->setTimezone(new DateTimeZone($userTimezone)); $ends->setTimezone(new DateTimeZone($showTimezone));
return array($starts, $ends); return array($starts, $ends);
} }
@ -482,4 +488,24 @@ class Application_Service_ShowFormService
return "Invalid Date"; return "Invalid Date";
} }
} }
/**
* When the timezone is changed in add-show form this function
* applies the new timezone to the start and end time
*
* @param $date String
* @param $time String
* @param $timezone String
*/
public static function localizeDateTime($date, $time, $newTimezone, $oldTimezone)
{
$dt = new DateTime($date." ".$time, new DateTimeZone($oldTimezone));
$dt->setTimeZone(new DateTimeZone($newTimezone));
return array(
"date" => $dt->format("Y-m-d"),
"time" => $dt->format("H:i")
);
}
} }

View File

@ -54,10 +54,10 @@ class Application_Service_ShowService
$oldCcShow = CcShowQuery::create() $oldCcShow = CcShowQuery::create()
->findPk($showData["add_show_id"]); ->findPk($showData["add_show_id"]);
//DateTime in user's local time //DateTime in shows's local time
$newStartDateTime = new DateTime($showData["add_show_start_date"]." ". $newStartDateTime = new DateTime($showData["add_show_start_date"]." ".
$showData["add_show_start_time"], $showData["add_show_start_time"],
new DateTimeZone(Application_Model_Preference::GetTimezone())); new DateTimeZone($showData["add_show_timezone"]));
$ccShowInstanceOrig = CcShowInstancesQuery::create() $ccShowInstanceOrig = CcShowInstancesQuery::create()
->findPk($showData["add_show_instance_id"]); ->findPk($showData["add_show_instance_id"]);
@ -740,10 +740,10 @@ SQL;
//CcShowDay object //CcShowDay object
$currentShowDay = $this->ccShow->getFirstCcShowDay(); $currentShowDay = $this->ccShow->getFirstCcShowDay();
//DateTime in user's local time //DateTime in show's local time
$newStartDateTime = new DateTime($showData["add_show_start_date"]." ". $newStartDateTime = new DateTime($showData["add_show_start_date"]." ".
$showData["add_show_start_time"], $showData["add_show_start_time"],
new DateTimeZone(Application_Model_Preference::GetTimezone())); new DateTimeZone($showData["add_show_timezone"]));
$diff = $this->calculateShowStartDiff($newStartDateTime, $diff = $this->calculateShowStartDiff($newStartDateTime,
$currentShowDay->getLocalStartDateAndTime()); $currentShowDay->getLocalStartDateAndTime());
@ -1152,6 +1152,7 @@ SQL;
do { do {
$nextDT = date_create($weekNumberOfMonth." ".$dayOfWeek. $nextDT = date_create($weekNumberOfMonth." ".$dayOfWeek.
" of ".$tempDT->format("F")." ".$tempDT->format("Y")); " of ".$tempDT->format("F")." ".$tempDT->format("Y"));
$nextDT->setTimezone(new DateTimeZone($timezone));
/* We have to check if the next date is in the same month in case /* We have to check if the next date is in the same month in case
* the repeat day is in the fifth week of the month. * the repeat day is in the fifth week of the month.
@ -1330,7 +1331,7 @@ SQL;
$showDay->setDbFirstShow($startDateTime->format("Y-m-d")); $showDay->setDbFirstShow($startDateTime->format("Y-m-d"));
$showDay->setDbLastShow($endDate); $showDay->setDbLastShow($endDate);
$showDay->setDbStartTime($startDateTime->format("H:i:s")); $showDay->setDbStartTime($startDateTime->format("H:i:s"));
$showDay->setDbTimezone(Application_Model_Preference::GetTimezone()); $showDay->setDbTimezone($showData['add_show_timezone']);
$showDay->setDbDuration($showData['add_show_duration']); $showDay->setDbDuration($showData['add_show_duration']);
$showDay->setDbRepeatType($this->repeatType); $showDay->setDbRepeatType($this->repeatType);
$showDay->setDbShowId($showId); $showDay->setDbShowId($showId);
@ -1356,7 +1357,7 @@ SQL;
$showDay->setDbFirstShow($startDateTimeClone->format("Y-m-d")); $showDay->setDbFirstShow($startDateTimeClone->format("Y-m-d"));
$showDay->setDbLastShow($endDate); $showDay->setDbLastShow($endDate);
$showDay->setDbStartTime($startDateTimeClone->format("H:i")); $showDay->setDbStartTime($startDateTimeClone->format("H:i"));
$showDay->setDbTimezone(Application_Model_Preference::GetTimezone()); $showDay->setDbTimezone($showData['add_show_timezone']);
$showDay->setDbDuration($showData['add_show_duration']); $showDay->setDbDuration($showData['add_show_duration']);
$showDay->setDbDay($day); $showDay->setDbDay($day);
$showDay->setDbRepeatType($this->repeatType); $showDay->setDbRepeatType($this->repeatType);
@ -1481,12 +1482,13 @@ SQL;
private function createUTCStartEndDateTime($showStart, $duration, $offset=null) private function createUTCStartEndDateTime($showStart, $duration, $offset=null)
{ {
$startDateTime = clone $showStart; $startDateTime = clone $showStart;
$timezone = $startDateTime->getTimezone();
if (isset($offset)) { if (isset($offset)) {
//$offset["hours"] and $offset["mins"] represents the start time //$offset["hours"] and $offset["mins"] represents the start time
//of a rebroadcast show //of a rebroadcast show
$startDateTime = new DateTime($startDateTime->format("Y-m-d")." ". $startDateTime = new DateTime($startDateTime->format("Y-m-d")." ".
$offset["hours"].":".$offset["mins"]); $offset["hours"].":".$offset["mins"], $timezone);
$startDateTime->add(new DateInterval("P{$offset["days"]}D")); $startDateTime->add(new DateInterval("P{$offset["days"]}D"));
} }
//convert time to UTC //convert time to UTC

View File

@ -55,6 +55,16 @@
<?php endforeach; ?> <?php endforeach; ?>
</ul> </ul>
<?php } ?> <?php } ?>
<dt id="add_show_timezone-label">
<label class="required">
<?php echo $this->element->getElement('add_show_timezone')->getLabel() ?>
</label>
</dt>
<dd id="add_show_timezone-element">
<?php echo $this->element->getElement('add_show_timezone') ?>
</dd>
<dt id="add_show_repeats-label"> <dt id="add_show_repeats-label">
<label><?php echo $this->element->getElement('add_show_repeats')->getLabel() ?></label> <label><?php echo $this->element->getElement('add_show_repeats')->getLabel() ?></label>
</dt> </dt>

View File

@ -450,6 +450,10 @@ input[type="text"]:focus, input[type="password"]:focus, textarea:focus, .input_t
vertical-align: top; vertical-align: top;
} }
.add_show_input_select{
width: 150px;
}
/***** LIBRARY QTIP METADATA SPECIFIC STYLES BEGIN *****/ /***** LIBRARY QTIP METADATA SPECIFIC STYLES BEGIN *****/
table.library-track-md{ table.library-track-md{
width: 280px; width: 280px;

View File

@ -227,6 +227,35 @@ function setAddShowEvents() {
} }
}); });
// in case user is creating a new show, there will be
// no show_id so we have to store the default timezone
// to be able to do the conversion when the timezone
// setting changes
var currentTimezone = form.find("#add_show_timezone").val();
form.find("#add_show_timezone").change(function(){
var startDateField = form.find("#add_show_start_date"),
startTimeField = form.find("#add_show_start_time"),
endDateField = form.find("#add_show_end_date_no_repeat"),
endTimeField = form.find("#add_show_end_time"),
newTimezone = form.find("#add_show_timezone").val();
$.post(baseUrl+"Schedule/localize-start-end-time",
{format: "json",
startDate: startDateField.val(),
startTime: startTimeField.val(),
endDate: endDateField.val(),
endTime: endTimeField.val(),
newTimezone: newTimezone,
oldTimezone: currentTimezone}, function(json){
startDateField.val(json.start.date);
startTimeField.val(json.start.time);
endDateField.val(json.end.date);
endTimeField.val(json.end.time);
});
});
form.find("#add_show_repeat_type").change(function(){ form.find("#add_show_repeat_type").change(function(){
toggleRepeatDays(); toggleRepeatDays();
toggleMonthlyRepeatType(); toggleMonthlyRepeatType();

View File

@ -312,7 +312,7 @@ AIRTIME = (function(AIRTIME) {
if (fn.hasOwnProperty("ops")) { if (fn.hasOwnProperty("ops")) {
data["myShows"] = fn.ops.myShows; data["myShows"] = fn.ops.myShows;
data["showFilter"] = fn.ops.showFilter; data["showFilter"] = fn.ops.showFilter;
data["showFilter"] = fn.ops.showInstanceFilter; data["showInstanceFilter"] = fn.ops.showInstanceFilter;
} }
$.ajax( { $.ajax( {