Merge branch 'devel' of dev.sourcefabric.org:airtime into devel

This commit is contained in:
Naomi Aro 2012-04-26 12:15:31 +02:00
commit 2c84420424
10 changed files with 142 additions and 101 deletions

View File

@ -65,7 +65,8 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
$view->headScript()->appendFile($baseUrl.'/js/libs/jquery-ui-1.8.18.custom.min.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
$view->headScript()->appendFile($baseUrl.'/js/libs/jquery.stickyPanel.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
$view->headScript()->appendFile($baseUrl.'/js/qtip/jquery.qtip.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
$view->headScript()->appendFile($baseUrl.'/js/jplayer/jquery.jplayer.min.js?'.$CC_CONFIG['airtime_version']);
$view->headScript()->appendFile($baseUrl.'/js/jplayer/jquery.jplayer.min.js?'.$CC_CONFIG['airtime_version'], 'text/javascript');
$view->headScript()->appendFile($baseUrl.'/js/sprintf/sprintf-0.7-beta1.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
$view->headScript()->appendScript("var baseUrl='$baseUrl/'");
//scripts for now playing bar

View File

@ -31,6 +31,7 @@ class ScheduleController extends Zend_Controller_Action
->addActionContext('set-time-interval', 'json')
->addActionContext('edit-show-instance', 'json')
->addActionContext('dj-edit-show', 'json')
->addActionContext('calculate-duration', 'json')
->initContext();
$this->sched_sess = new Zend_Session_Namespace("schedule");
@ -777,6 +778,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->form = $this->view->render('schedule/add-show-form.phtml');
}
}
@ -891,12 +893,25 @@ class ScheduleController extends Zend_Controller_Action
public function setTimeIntervalAction() {
Application_Model_Preference::SetCalendarTimeInterval($this->_getParam('timeInterval'));
}
public function calculateDurationAction() {
global $CC_CONFIG;
$startParam = $this->_getParam('startTime');
$endParam = $this->_getParam('endTime');
$startDateTime = new DateTime($startParam);
$endDateTime = new DateTime($endParam);
$UTCStartDateTime = $startDateTime->setTimezone(new DateTimeZone('UTC'));
$UTCEndDateTime = $endDateTime->setTimezone(new DateTimeZone('UTC'));
$duration = $UTCEndDateTime->diff($UTCStartDateTime);
$result = $duration->format('%r%Hh %Im');
echo Zend_Json::encode($result);
exit();
}
}

View File

@ -10,7 +10,6 @@ class SystemstatusController extends Zend_Controller_Action
$baseUrl = $request->getBaseUrl();
$this->view->headScript()->appendFile($baseUrl.'/js/airtime/status/status.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
$this->view->headScript()->appendFile($baseUrl.'/js/sprintf/sprintf-0.7-beta1.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
}
public function indexAction()

View File

@ -868,14 +868,6 @@ class Application_Model_Show {
$this->updateDurationTime($p_data);
}
if ($isRecorded){
//delete all rebroadcasts. They will simply be recreated later
//in the execution of this PHP script. This simplifies having to
//reason about whether we should keep individual rebroadcasts or
//delete them or move them around etc.
$this->deleteAllRebroadcasts();
}
if ($p_data['add_show_repeats']){
if (($repeatType == 1 || $repeatType == 2) &&
$p_data['add_show_start_date'] != $this->getStartDate()){
@ -1172,8 +1164,8 @@ class Application_Model_Show {
$sql = "SELECT * FROM cc_show_days WHERE show_id = $p_showId";
$res = $con->query($sql)->fetchAll();
foreach ($res as $showRow) {
Application_Model_Show::populateShow($showRow, $p_populateUntilDateTime);
foreach ($res as $showDaysRow) {
Application_Model_Show::populateShow($showDaysRow, $p_populateUntilDateTime);
}
}
@ -1188,18 +1180,18 @@ class Application_Model_Show {
* @param DateTime $p_populateUntilDateTime
* DateTime object in UTC time.
*/
private static function populateShow($p_showRow, $p_populateUntilDateTime) {
if($p_showRow["repeat_type"] == -1) {
Application_Model_Show::populateNonRepeatingShow($p_showRow, $p_populateUntilDateTime);
private static function populateShow($p_showDaysRow, $p_populateUntilDateTime) {
if($p_showDaysRow["repeat_type"] == -1) {
Application_Model_Show::populateNonRepeatingShow($p_showDaysRow, $p_populateUntilDateTime);
}
else if($p_showRow["repeat_type"] == 0) {
Application_Model_Show::populateRepeatingShow($p_showRow, $p_populateUntilDateTime, 'P7D');
else if($p_showDaysRow["repeat_type"] == 0) {
Application_Model_Show::populateRepeatingShow($p_showDaysRow, $p_populateUntilDateTime, 'P7D');
}
else if($p_showRow["repeat_type"] == 1) {
Application_Model_Show::populateRepeatingShow($p_showRow, $p_populateUntilDateTime, 'P14D');
else if($p_showDaysRow["repeat_type"] == 1) {
Application_Model_Show::populateRepeatingShow($p_showDaysRow, $p_populateUntilDateTime, 'P14D');
}
else if($p_showRow["repeat_type"] == 2) {
Application_Model_Show::populateRepeatingShow($p_showRow, $p_populateUntilDateTime, 'P1M');
else if($p_showDaysRow["repeat_type"] == 2) {
Application_Model_Show::populateRepeatingShow($p_showDaysRow, $p_populateUntilDateTime, 'P1M');
}
Application_Model_RabbitMq::PushSchedule();
}
@ -1258,9 +1250,10 @@ class Application_Model_Show {
$sql = "SELECT * FROM cc_show_rebroadcast WHERE show_id={$show_id}";
$rebroadcasts = $con->query($sql)->fetchAll();
//Logging::log('$start time of non repeating record '.$start);
self::createRebroadcastInstances($rebroadcasts, $currentUtcTimestamp, $show_id, $show_instance_id, $start, $duration, $timezone);
if ($showInstance->isRecorded()){
$showInstance->deleteRebroadcasts();
self::createRebroadcastInstances($rebroadcasts, $currentUtcTimestamp, $show_id, $show_instance_id, $start, $duration, $timezone);
}
}
}
@ -1276,19 +1269,19 @@ class Application_Model_Show {
* @param string $p_interval
* Period of time between repeating shows (in php DateInterval notation 'P7D')
*/
private static function populateRepeatingShow($p_showRow, $p_populateUntilDateTime, $p_interval)
private static function populateRepeatingShow($p_showDaysRow, $p_populateUntilDateTime, $p_interval)
{
$con = Propel::getConnection();
$show_id = $p_showRow["show_id"];
$next_pop_date = $p_showRow["next_pop_date"];
$first_show = $p_showRow["first_show"]; //non-UTC
$last_show = $p_showRow["last_show"]; //non-UTC
$start_time = $p_showRow["start_time"]; //non-UTC
$duration = $p_showRow["duration"];
$day = $p_showRow["day"];
$record = $p_showRow["record"];
$timezone = $p_showRow["timezone"];
$show_id = $p_showDaysRow["show_id"];
$next_pop_date = $p_showDaysRow["next_pop_date"];
$first_show = $p_showDaysRow["first_show"]; //non-UTC
$last_show = $p_showDaysRow["last_show"]; //non-UTC
$start_time = $p_showDaysRow["start_time"]; //non-UTC
$duration = $p_showDaysRow["duration"];
$day = $p_showDaysRow["day"];
$record = $p_showDaysRow["record"];
$timezone = $p_showDaysRow["timezone"];
$currentUtcTimestamp = gmdate("Y-m-d H:i:s");
@ -1314,6 +1307,12 @@ class Application_Model_Show {
if ($show->hasInstanceOnDate($utcStartDateTime)){
$ccShowInstance = $show->getInstanceOnDate($utcStartDateTime);
if ($ccShowInstance->getDbModifiedInstance()){
//show instance on this date has been deleted.
continue;
}
$newInstance = false;
} else {
$ccShowInstance = new CcShowInstances();
@ -1341,10 +1340,8 @@ class Application_Model_Show {
$showInstance->correctScheduleStartTimes();
}
//don't create rebroadcasts for a deleted recorded show.
if ($ccShowInstance->getDbModifiedInstance() == false) {
self::createRebroadcastInstances($rebroadcasts, $currentUtcTimestamp, $show_id, $show_instance_id, $start, $duration, $timezone);
}
$showInstance->deleteRebroadcasts();
self::createRebroadcastInstances($rebroadcasts, $currentUtcTimestamp, $show_id, $show_instance_id, $start, $duration, $timezone);
if ($p_interval == 'P1M'){
/* When adding months, there is a problem if we are on January 31st and add one month with PHP.

View File

@ -30,6 +30,20 @@ class Application_Model_ShowInstance {
public function getShow(){
return new Application_Model_Show($this->getShowId());
}
public function deleteRebroadcasts(){
$con = Propel::getConnection();
$timestamp = gmdate("Y-m-d H:i:s");
$instance_id = $this->getShowInstanceId();
$sql = "DELETE FROM cc_show_instances"
." WHERE starts > TIMESTAMP '$timestamp'"
." AND instance_id = $instance_id"
." AND rebroadcast = 1";
$con->exec($sql);
}
/* This function is weird. It should return a boolean, but instead returns
* an integer if it is a rebroadcast, or returns null if it isn't. You can convert

View File

@ -82,4 +82,8 @@ function openPreviewWindow(url) {
//var elemID = "spl_"+elemIndexString;
//$('#'+elemID+' div.list-item-container a span').attr("class", "ui-icon ui-icon-pause");
return false;
}
}
function pad(number, length) {
return sprintf("%'0"+length+"d", number);
}

View File

@ -11,6 +11,23 @@ function popup(mylink){
return false;
}
/* Take a string representing a date in the format 2012-04-25 and return
* a javascript date object representing this date. */
function getDateFromString(time){
var date = time.split("-");
if (date.length != 3){
return null;
}
var year = parseInt(date[0], 10);
var month = parseInt(date[1], 10) -1;
var day = parseInt(date[2], 10);
return new Date(year, month, day);
}
function convertSecondsToDaysHoursMinutesSeconds(seconds){
if (seconds < 0)
seconds = 0;

View File

@ -110,7 +110,22 @@ function setAddShowEvents() {
form.find("#add_show_repeats").click(function(){
$(this).blur();
form.find("#schedule-show-when > fieldset:last").toggle();
var checkBoxSelected = false;
var days = form.find("#add_show_day_check-element input").each( function() {
var currentCheckBox = $(this).attr("checked");
if (currentCheckBox && currentCheckBox == "checked"){
checkBoxSelected = true;
}
});
if (!checkBoxSelected){
var d = getDateFromString(form.find("#add_show_start_date").attr("value"));
if ( d != null)
form.find("#add_show_day_check-"+d.getDay()).attr('checked', true);
}
//must switch rebroadcast displays
if(form.find("#add_show_rebroadcast").attr('checked')) {
@ -364,12 +379,16 @@ function setAddShowEvents() {
// when start date/time changes, set end date/time to start date/time+1 hr
$('#add_show_start_date, #add_show_start_time').change(function(){
var startDate = $('#add_show_start_date').val().split('-');
var startTime = $('#add_show_start_time').val().split(':');
var startDateString = $('#add_show_start_date').val();
var startTimeString = $('#add_show_start_time').val();
var startDate = startDateString.split('-');
var startTime = startTimeString.split(':');
var startDateTime = new Date(startDate[0], parseInt(startDate[1], 10)-1, startDate[2], startTime[0], startTime[1], 0, 0);
var endDate = $('#add_show_end_date_no_repeat').val().split('-');
var endTime = $('#add_show_end_time').val().split(':');
var endDateString = $('#add_show_end_date_no_repeat').val();
var endTimeString = $('#add_show_end_time').val()
var endDate = endDateString.split('-');
var endTime = endTimeString.split(':');
var endDateTime = new Date(endDate[0], parseInt(endDate[1], 10)-1, endDate[2], endTime[0], endTime[1], 0, 0);
if(startDateTime.getTime() >= endDateTime.getTime()){
@ -393,17 +412,23 @@ function setAddShowEvents() {
$('#add_show_end_time').val(endTimeFormat);
// calculate duration
calculateDuration(endDateTime, startDateTime);
var startDateTimeString = startDateString + " " + startTimeString;
var endDateTimeString = $('#add_show_end_date_no_repeat').val() + " " + $('#add_show_end_time').val();
calculateDuration(startDateTimeString, endDateTimeString);
});
// when end date/time changes, check if the changed date is in past of start date/time
$('#add_show_end_date_no_repeat, #add_show_end_time').change(function(){
var startDate = $('#add_show_start_date').val().split('-');
var startTime = $('#add_show_start_time').val().split(':');
var startDateString = $('#add_show_start_date').val();
var startTimeString = $('#add_show_start_time').val();
var startDate = startDateString.split('-');
var startTime = startTimeString.split(':');
var startDateTime = new Date(startDate[0], parseInt(startDate[1], 10)-1, startDate[2], startTime[0], startTime[1], 0, 0);
var endDate = $('#add_show_end_date_no_repeat').val().split('-');
var endTime = $('#add_show_end_time').val().split(':');
var endDateString = $('#add_show_end_date_no_repeat').val();
var endTimeString = $('#add_show_end_time').val()
var endDate = endDateString.split('-');
var endTime = endTimeString.split(':');
var endDateTime = new Date(endDate[0], parseInt(endDate[1], 10)-1, endDate[2], endTime[0], endTime[1], 0, 0);
if(startDateTime.getTime() > endDateTime.getTime()){
@ -415,7 +440,9 @@ function setAddShowEvents() {
}
// calculate duration
calculateDuration(endDateTime, startDateTime);
var startDateTimeString = startDateString + " " + startTimeString;
var endDateTimeString = endDateString + " " + endTimeString;
calculateDuration(startDateTimeString, endDateTimeString);
});
if($('#cb_custom_auth').attr('checked')){
@ -434,27 +461,9 @@ function setAddShowEvents() {
function calculateDuration(endDateTime, startDateTime){
var duration;
var durationSeconds = (endDateTime.getTime() - startDateTime.getTime())/1000;
if(isNaN(durationSeconds)){
duration = '1h';
}
else if(durationSeconds != 0){
var durationHour = parseInt(durationSeconds/3600, 10);
var durationMin = parseInt((durationSeconds%3600)/60, 10);
duration = (durationHour == 0 ? '' : durationHour+'h'+' ')+(durationMin == 0 ? '' : durationMin+'m');
}else{
duration = '0m';
}
$('#add_show_duration').val(duration);
}
function pad(number, length) {
var str = '' + number;
while (str.length < length) {
str = '0' + str;
}
return str;
$.post("/Schedule/calculate-duration", {startTime: startDateTime, endTime: endDateTime}, function(data){
$('#add_show_duration').val(JSON.parse(data));
});
}
}

View File

@ -58,17 +58,6 @@ function removeAddShowButton(){
span.remove();
}
function pad(number, length) {
var str = '' + number;
while (str.length < length) {
str = '0' + str;
}
return str;
}
function makeTimeStamp(date){
var sy, sm, sd, h, m, s, timestamp;
sy = date.getFullYear();
@ -82,15 +71,6 @@ function makeTimeStamp(date){
return timestamp;
}
function pad(number, length) {
var str = '' + number;
while (str.length < length) {
str = '0' + str;
}
return str;
}
function dayClick(date, allDay, jsEvent, view){
// The show from will be preloaded if the user is admin or program manager.
// Hence, if the user if DJ then it won't open anything.
@ -141,7 +121,7 @@ function dayClick(date, allDay, jsEvent, view){
}else{
// if in day or week view, selected has all the time info as well
// so we don't ahve to calculate it explicitly
startTime_string = selected.getHours()+":"+selected.getMinutes()
startTime_string = pad(selected.getHours(),2)+":"+pad(selected.getMinutes(),2)
startTime = 0
}
@ -155,7 +135,7 @@ function dayClick(date, allDay, jsEvent, view){
$("#add_show_end_date_no_repeat").val(endDateFormat);
$("#add_show_end_date").val(endDateFormat);
if(view.name !== "month") {
var endTimeString = endDateTime.getHours()+":"+endDateTime.getMinutes();
var endTimeString = pad(endDateTime.getHours(),2)+":"+pad(endDateTime.getMinutes(),2);
$("#add_show_start_time").val(startTime_string)
$("#add_show_end_time").val(endTimeString)
}

View File

@ -134,11 +134,16 @@ class ShowRecorder(Thread):
recorded_file['title'] = name
recorded_file['artist'] = artist
recorded_file['date'] = md[0]
recorded_file['tracknumber'] = self.show_instance
#You cannot pass ints into the metadata of a file. Even tracknumber needs to be a string
recorded_file['tracknumber'] = unicode(self.show_instance)
recorded_file.save()
except Exception, e:
self.logger.error("Exception: %s", e)
import traceback
top = traceback.format_exc()
self.logger.error('Exception: %s', e)
self.logger.error("traceback: %s", top)
def run(self):
code, filepath = self.record_show()