Merge branch '2.5.x' of github.com:sourcefabric/Airtime into 2.5.x

Conflicts:
	airtime_mvc/application/models/Show.php
This commit is contained in:
Albert Santoni 2013-12-13 16:12:26 -05:00
commit 346036a9ca
43 changed files with 43859 additions and 44094 deletions

View File

@ -177,6 +177,7 @@ class LocaleController extends Zend_Controller_Action
//preferences/support-setting.js
"Image must be one of jpg, jpeg, png, or gif" => _("Image must be one of jpg, jpeg, png, or gif"),
//schedule/add-show.js
"Warning: You cannot change this field while the show is currently playing" => _("Warning: You cannot change this field while the show is currently playing"),
"No result found" => _("No result found"),
"This follows the same security pattern for the shows: only users assigned to the show can connect." => _("This follows the same security pattern for the shows: only users assigned to the show can connect."),
"Specify custom authentication which will work only for this show." => _("Specify custom authentication which will work only for this show."),

View File

@ -437,7 +437,7 @@ class ScheduleController extends Zend_Controller_Action
if ($service_showForm->validateShowForms($forms, $data, $validateStartDate,
$originalShowStartDateTime, true, $data["add_show_instance_id"])) {
$service_show->createShowFromRepeatingInstance($data);
$service_show->editRepeatingShowInstance($data);
$this->view->addNewShow = true;
$this->view->newForm = $this->view->render('schedule/add-show-form.phtml');
@ -450,7 +450,7 @@ class ScheduleController extends Zend_Controller_Action
}
$this->view->rr->getElement('add_show_record')->setOptions(array('disabled' => true));
$this->view->addNewShow = false;
$this->view->action = "edit-show";
$this->view->action = "edit-repeating-show-instance";
$this->view->form = $this->view->render('schedule/add-show-form.phtml');
}
}

View File

@ -72,4 +72,14 @@ class Application_Form_AddShowLiveStream extends Zend_Form_SubForm
return $isValid;
}
public function disable()
{
$elements = $this->getElements();
foreach ($elements as $element) {
if ($element->getType() != 'Zend_Form_Element_Hidden') {
$element->setAttrib('disabled','disabled');
}
}
}
}

View File

@ -75,4 +75,14 @@ class Application_Form_AddShowWhat extends Zend_Form_SubForm
}
}
}
public function makeReadonly()
{
$elements = $this->getElements();
foreach ($elements as $element) {
if ($element->getType() != 'Zend_Form_Element_Hidden') {
$element->setAttrib('readonly','readonly');
}
}
}
}

View File

@ -1056,13 +1056,17 @@ SQL;
/**
* Calculates the percentage of a show scheduled given the start and end times in date/time format
* and the time_filled as the total time the schow is scheduled for in time format.
*
* TODO when using propel properly this should be a method on the propel show instance model.
**/
private static function getPercentScheduled($p_starts, $p_ends, $p_time_filled)
{
$durationSeconds = (strtotime($p_ends) - strtotime($p_starts));
$time_filled = Application_Model_Schedule::WallTimeToMillisecs($p_time_filled) / 1000;
if ($durationSeconds != 0) { //Prevent division by zero if zero length show occurs.
$utcTimezone = new DatetimeZone("UTC");
$startDt = new DateTime($p_starts, $utcTimezone);
$endDt = new DateTime($p_ends, $utcTimezone);
$durationSeconds = intval($endDt->format("U")) - intval($startDt->format("U"));
$time_filled = Application_Common_DateHelper::playlistTimeToSeconds($p_time_filled);
if ($durationSeconds != 0) { //Prevent division by zero if the show duration somehow becomes zero.
$percent = ceil(( $time_filled / $durationSeconds) * 100);
} else {
$percent = 0;

View File

@ -164,43 +164,6 @@ SQL;
$this->_showInstance->getDbModifiedInstance();
}
public function correctScheduleStartTimes()
{
$con = Propel::getConnection();
$instance_id = $this->getShowInstanceId();
$sql = <<<SQL
SELECT starts
FROM cc_schedule
WHERE instance_id = :instanceId
ORDER BY starts LIMIT 1;
SQL;
$scheduleStarts = Application_Common_Database::prepareAndExecute( $sql,
array( ':instanceId' => $instance_id ), 'column' );
if ($scheduleStarts) {
$scheduleStartsEpoch = strtotime($scheduleStarts);
$showStartsEpoch = strtotime($this->getShowInstanceStart());
$diff = $showStartsEpoch - $scheduleStartsEpoch;
if ($diff != 0) {
$sql = <<<SQL
UPDATE cc_schedule
SET starts = starts + :diff1::INTERVAL SECOND,
ends = ends + :diff2::INTERVAL SECOND
WHERE instance_id = :instanceId
SQL;
Application_Common_Database::prepareAndExecute($sql,
array(
':diff1' => $diff,
':diff2' => $diff,
':instanceId' => $instance_id ), 'execute');
}
}
Application_Model_RabbitMq::PushSchedule();
}
/*
* @param $dateTime
* php Datetime object to add deltas to
@ -239,67 +202,6 @@ SQL;
return $newDateTime;
}
public function resizeShow($deltaDay, $deltaMin)
{
$con = Propel::getConnection();
$hours = $deltaMin / 60;
$hours = ($hours > 0) ? floor($hours) : ceil($hours);
$mins = abs($deltaMin % 60);
$today_timestamp = gmdate("Y-m-d H:i:s");
$starts = $this->getShowInstanceStart();
$ends = $this->getShowInstanceEnd();
if (strtotime($today_timestamp) > strtotime($starts)) {
return _("can't resize a past show");
}
//$sql = "SELECT timestamp '{$ends}' + interval '{$deltaDay} days' + interval '{$hours}:{$mins}'";
$sql = "SELECT timestamp :ends + interval :deltaDays + interval :deltaTime";
$now_ends = Application_Common_Database::prepareAndExecute($sql,
array(':ends' => $ends,
':deltaDays' => "$deltaDay days",
':deltaTime' => "{$hours}:{$mins}"), 'column'
);
//only need to check overlap if show increased in size.
if (strtotime($now_ends) > strtotime($ends)) {
$utcStartDateTime = new DateTime($ends, new DateTimeZone("UTC"));
$utcEndDateTime = new DateTime($now_ends, new DateTimeZone("UTC"));
$overlap = Application_Model_Show::getShows($utcStartDateTime, $utcEndDateTime);
if (count($overlap) > 0) {
// TODO : fix ghetto error handling -- RG
return _("Should not overlap shows");
}
}
//with overbooking no longer need to check already scheduled content still fits.
//must update length of all rebroadcast instances.
if ($this->isRecorded()) {
$sql = <<<SQL
UPDATE cc_show_instances
SET ends = (ends + interval :deltaDays + interval :interval)
WHERE rebroadcast = 1
AND instance_id = :instanceId;
SQL;
Application_Common_Database::prepareAndExecute( $sql, array(
':deltaDays' => "$deltaDay days",
':interval' => "$hours:$mins",
':instanceId' => $this->_instanceId ), 'execute');
}
$this->setShowEnd($now_ends);
Application_Model_RabbitMq::PushSchedule();
}
/**
* Add a playlist as the last item of the current show.
*
@ -733,21 +635,6 @@ SQL;
return ($query !== false) ? $query : null;
}
public function getShowEndGapTime()
{
$showEnd = $this->getShowInstanceEnd();
$lastItemEnd = $this->getLastAudioItemEnd();
if (is_null($lastItemEnd)) {
$lastItemEnd = $this->getShowInstanceStart();
}
$diff = strtotime($showEnd) - strtotime($lastItemEnd);
return ($diff < 0) ? 0 : $diff;
}
public static function GetLastShowInstance($p_timeNow)
{
$sql = <<<SQL

View File

@ -149,7 +149,7 @@ class Application_Service_CalendarService
if ($isRepeating) {
if ($populateInstance) {
$menu["edit"] = array(
"name" => _("Edit Show"),
"name" => _("Edit This Instance"),
"icon" => "edit",
"url" => $baseUrl."Schedule/populate-repeating-show-instance-form");
} else {

View File

@ -81,9 +81,20 @@ class Application_Service_ShowFormService
$this->populateFormLive($forms["live"]);
$this->populateFormStyle($forms["style"]);
//no need to populate these forms since the user won't
//be able to see them
/* Only the field on the 'when' form will get updated so we should
* make all other forms disabled or readonly
*
* 'what' needs to be readonly because zendform will not validate
* if they are disabled
*
* All other forms can be disabled because we do not update those values
* when the user edits a repeating instance
*/
$forms["what"]->makeReadonly();
$forms["repeats"]->disable();
$forms["who"]->disable();
$forms["style"]->disable();
$forms["live"]->disable();
$forms["record"]->disable();
$forms["rebroadcast"]->disable();
$forms["abs_rebroadcast"]->disable();
@ -215,12 +226,13 @@ class Application_Service_ShowFormService
}
$service_show = new Application_Service_ShowService($this->ccShow->getDbId());
$repeatEndDate = new DateTime($service_show->getRepeatingEndDate(), new DateTimeZone(
$ccShowDays[0]->getDbTimezone()));
$repeatEndDate = $service_show->getRepeatingEndDate();
//end dates are stored non-inclusively so we need to
//subtract one day
$repeatEndDate->sub(new DateInterval("P1D"));
if (!is_null($repeatEndDate)) {
$repeatEndDate->sub(new DateInterval("P1D"));
}
//default monthly repeat type
$monthlyRepeatType = 2;
$repeatType = $ccShowDays[0]->getDbRepeatType();
@ -237,20 +249,24 @@ class Application_Service_ShowFormService
'add_show_linked' => $this->ccShow->getDbLinked(),
'add_show_repeat_type' => $repeatType,
'add_show_day_check' => $days,
'add_show_end_date' => $repeatEndDate->format("Y-m-d"),
'add_show_no_end' => (!$service_show->getRepeatingEndDate()),
'add_show_end_date' => (!is_null($repeatEndDate)) ? $repeatEndDate->format("Y-m-d"):null,
'add_show_no_end' => (is_null($repeatEndDate)),
'add_show_monthly_repeat_type' => $monthlyRepeatType));
if (!$this->ccShow->isLinkable() || $this->ccShow->isRecorded()) {
$form->getElement('add_show_linked')->setOptions(array('disabled' => true));
}
/* Because live editing of a linked show is disabled, we will disable
* the linking option if the current show is being edited. We don't
* want the user to suddenly not be able to edit the current show
/* Because live editing of a linked show is disabled, we will make
* the linking option readonly if the current show is being edited. We
* dont' want the user to suddenly not be able to edit the current show
*
* Readonly does not work with checkboxes but we can't disable it
* because the value won't get posted. In add-show.js we stop the
* onclick event from firing by returning false
*/
if ($this->hasShowStarted($nextFutureShowStart)) {
$form->getElement('add_show_linked')->setOptions(array('disabled' => true));
$form->getElement('add_show_linked')->setAttrib('readonly', 'readonly');
}
}

View File

@ -41,7 +41,7 @@ class Application_Service_ShowService
$this->isUpdate = $isUpdate;
}
public function createShowFromRepeatingInstance($showData) {
public function editRepeatingShowInstance($showData) {
$service_user = new Application_Service_UserService();
$currentUser = $service_user->getCurrentUser();
@ -108,9 +108,6 @@ class Application_Service_ShowService
*/
$this->setCcShowDays($showData);
// DO WE NEED THIS?
$this->setCcShowHosts($showData);
/*
* We need to find the new show day rule we just created by passing
* in the first show and start time in case multiple single
@ -196,8 +193,8 @@ class Application_Service_ShowService
$this->deleteRebroadcastInstances();
//$this->deleteCcShowDays();
$this->deleteCcShowHosts();
if ($this->isRebroadcast) {
//delete entry in cc_show_rebroadcast
$this->deleteCcShowRebroadcasts();
@ -413,13 +410,8 @@ SQL;
$currentShowDay = $this->ccShow->getFirstCcShowDay();
}
//new end date in users' local time
//new end date in the show's timezone (from the select box)
$endDateTime = $this->calculateEndDate($showData);
if (!is_null($endDateTime)) {
$endDate = $endDateTime->format("Y-m-d");
} else {
$endDate = $endDateTime;
}
//repeat option was toggled
if ($showData['add_show_repeats'] != $currentShowDay->isRepeating()) {
@ -512,28 +504,27 @@ SQL;
}
}
$currentShowEndDate = $this->getRepeatingEndDate();
//check if "no end" option has changed
if ($currentShowEndDate != $showData['add_show_no_end']) {
//get the endate from the past for this show.
//check if this is null if "no end"
$currentShowEndDateTime = $this->getRepeatingEndDate();
if ($currentShowEndDateTime != $endDateTime) {
$endDate = clone $endDateTime;
$endDate->setTimezone(new DateTimeZone("UTC"));
//show "No End" option was toggled
if (!$showData['add_show_no_end']) {
//or the end date comes earlier
if (is_null($currentShowEndDateTime) || ($endDateTime < $currentShowEndDateTime)) {
//"No End" option was unchecked so we need to delete the
//repeat instances that are scheduled after the new end date
$this->deleteInstancesFromDate($endDate, $showId);
//OR
//end date was pushed back so we have to delete any
//instances of this show scheduled after the new end date
$this->deleteInstancesFromDate($endDate->format("Y-m-d"), $showId);
}
}
if ($currentShowEndDate != $showData['add_show_end_date']) {
//end date was changed
$newEndDate = strtotime($showData['add_show_end_date']);
$oldEndDate = strtotime($currentShowEndDate);
if ($newEndDate < $oldEndDate) {
//end date was pushed back so we have to delete any
//instances of this show scheduled after the new end date
$this->deleteInstancesFromDate($endDate, $showId);
}
}
}//if repeats
}
return $daysAdded;
}
@ -554,19 +545,32 @@ SQL;
}
}
/*
* returns a DateTime of the current show end date set to the timezone of the show.
*/
public function getRepeatingEndDate()
{
$sql = <<<SQL
SELECT last_show
SELECT last_show, timezone
FROM cc_show_days
WHERE show_id = :showId
ORDER BY last_show DESC
LIMIT 1
SQL;
$query = Application_Common_Database::prepareAndExecute( $sql,
array( 'showId' => $this->ccShow->getDbId() ), 'column' );
return ($query !== false) ? $query : false;
array( 'showId' => $this->ccShow->getDbId() ), 'single');
$date = null;
if ($query !== false && isset($query["last_show"])) {
$date = new DateTime(
$query["last_show"],
new DateTimeZone($query["timezone"])
);
}
return $date;
}
private function deleteInstancesFromDate($endDate, $showId)
@ -823,13 +827,24 @@ SQL;
*/
private function calculateEndDate($showData)
{
//if no end return null
if ($showData['add_show_no_end']) {
$endDate = NULL;
} elseif ($showData['add_show_repeats']) {
$endDate = new DateTime($showData['add_show_end_date']);
$endDate = null;
}
//if the show is repeating & ends, then return the end date
elseif ($showData['add_show_repeats']) {
$endDate = new DateTime(
$showData['add_show_end_date'],
new DateTimeZone($showData["add_show_timezone"])
);
$endDate->add(new DateInterval("P1D"));
} else {
$endDate = new DateTime($showData['add_show_start_date']);
}
//the show doesn't repeat, so add one day to the start date.
else {
$endDate = new DateTime(
$showData['add_show_start_date'],
new DateTimeZone($showData["add_show_timezone"])
);
$endDate->add(new DateInterval("P1D"));
}
@ -1407,25 +1422,24 @@ SQL;
{
$showId = $this->ccShow->getDbId();
$startDateTime = new DateTime($showData['add_show_start_date']." ".$showData['add_show_start_time']);
$startDateTime = new DateTime(
$showData['add_show_start_date']." ".$showData['add_show_start_time'],
new DateTimeZone($showData['add_show_timezone'])
);
$endDateTime = $this->calculateEndDate($showData);
if (!is_null($endDateTime)) {
$endDate = $endDateTime->format("Y-m-d");
} else {
$endDate = $endDateTime;
}
else {
$endDate = null;
}
/* What we are doing here is checking if the show repeats or if
* any repeating days have been checked. If not, then by default
* the "selected" DOW is the initial day.
* DOW in local time.
*/
$startDow = date("w", $startDateTime->getTimestamp());
//Our calculated start DOW must be used for non repeating since a day has not been selected.
//For all repeating shows, only the selected days of the week will be repeated on.
$startDow = $startDateTime->format("w");
if (!$showData['add_show_repeats']) {
$showData['add_show_day_check'] = array($startDow);
} elseif ($showData['add_show_repeats'] && $showData['add_show_day_check'] == "") {
$showData['add_show_day_check'] = array($startDow);
}
// Don't set day for monthly repeat type, it's invalid

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -264,6 +264,13 @@ function setAddShowEvents(form) {
});
form.find("#add_show_linked").click(function(){
if ($(this).attr("readonly")) {
if ($("#show-link-readonly-warning").length === 0) {
$(this).parent().after("<ul id='show-link-readonly-warning' class='errors'><li>"+$.i18n._("Warning: You cannot change this field while the show is currently playing")+"</li></ul>");
}
return false;
}
if (!$(this).attr("checked") && $("#show-link-warning").length === 0) {
$(this).parent().after("<ul id='show-link-warning' class='errors'><li>"+$.i18n._("Warning: Shows cannot be re-linked")+"</li></ul>");
}