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

This commit is contained in:
Martin Konecny 2011-11-24 16:05:23 -05:00
commit cd1e55bffc
9 changed files with 88 additions and 21 deletions

View File

@ -96,7 +96,7 @@ $pages = array(
),
array(
'label' => 'User Manual',
'uri' => "http://en.flossmanuals.net/airtime/",
'uri' => "http://manuals.sourcefabric.org/",
'target' => "_blank"
),
array(

View File

@ -172,6 +172,21 @@ class ApiController extends Zend_Controller_Action
return;
}
/**
* Retrieve the currently playing show as well as upcoming shows.
* Number of shows returned and the time interval in which to
* get the next shows can be configured as post parameters.
*
* TODO: in the future, make interval length a parameter instead of hardcode to 48
*
* Possible parameters:
* type - Can have values of "endofday" or "interval". If set to "endofday",
* the function will retrieve shows from now to end of day.
* If set to "interval", shows in the next 48 hours will be retrived.
* Default is "interval".
* limit - How many shows to retrieve
* Default is "5".
*/
public function liveInfoAction()
{
if (Application_Model_Preference::GetAllow3rdPartyApi()){
@ -181,11 +196,24 @@ class ApiController extends Zend_Controller_Action
$date = new Application_Model_DateHelper;
$utcTimeNow = $date->getUtcTimestamp();
$utcTimeEnd = ""; // if empty, GetNextShows will use interval instead of end of day
$request = $this->getRequest();
$type = $request->getParam('type');
if($type == "endofday") {
// make GetNextShows use end of day
$utcTimeEnd = Application_Model_DateHelper::GetDayEndTimestampInUtc();
}
$limit = $request->getParam('limit');
if($limit == "") {
$limit = "5";
}
$result = array("env"=>APPLICATION_ENV,
"schedulerTime"=>gmdate("Y-m-d H:i:s"),
"currentShow"=>Application_Model_Show::GetCurrentShow($utcTimeNow),
"nextShow"=>Application_Model_Show::GetNextShows($utcTimeNow, 5),
"nextShow"=>Application_Model_Show::GetNextShows($utcTimeNow, $limit, $utcTimeEnd),
"timezone"=> date("T"),
"timezoneOffset"=> date("Z"));
@ -219,7 +247,7 @@ class ApiController extends Zend_Controller_Action
$result = array();
for ($i=0; $i<7; $i++){
$utcDayEnd = Application_Model_DateHelper::GetDayEndTimestamp($utcDayStart);
$shows = Application_Model_Show::GetNextShows($utcDayStart, 0, $utcDayEnd);
$shows = Application_Model_Show::GetNextShows($utcDayStart, "0", $utcDayEnd);
$utcDayStart = $utcDayEnd;
Application_Model_Show::ConvertToLocalTimeZone($shows, array("starts", "ends", "start_timestamp", "end_timestamp"));

View File

@ -493,7 +493,7 @@ class ScheduleController extends Zend_Controller_Action
$startsDateTime = new DateTime($show->getStartDate()." ".$show->getStartTime(), new DateTimeZone("UTC"));
$endsDateTime = new DateTime($show->getEndDate()." ".$show->getEndTime(), new DateTimeZone("UTC"));
$startsDateTime->setTimezone(new DateTimeZone(date_default_timezone_get()));
$endsDateTime->setTimezone(new DateTimeZone(date_default_timezone_get()));
@ -508,13 +508,16 @@ class ScheduleController extends Zend_Controller_Action
$formWhen->getElement('add_show_start_date')->setOptions(array('disabled' => true));
}
//need to get the days of the week in the php timezone (for the front end).
$days = array();
$showDays = CcShowDaysQuery::create()->filterByDbShowId($showInstance->getShowId())->find();
foreach($showDays as $showDay){
array_push($days, $showDay->getDbDay());
$showStartDay = new DateTime($showDay->getDbFirstShow(), new DateTimeZone($showDay->getDbTimezone()));
$showStartDay->setTimezone(new DateTimeZone(date_default_timezone_get()));
array_push($days, $showStartDay->format('w'));
}
$displayedEndDate = new DateTime($show->getRepeatingEndDate(), new DateTimeZone("UTC"));
$displayedEndDate = new DateTime($show->getRepeatingEndDate(), new DateTimeZone($showDays[0]->getDbTimezone()));
$displayedEndDate->sub(new DateInterval("P1D"));//end dates are stored non-inclusively.
$displayedEndDate->setTimezone(new DateTimeZone(date_default_timezone_get()));
@ -742,7 +745,7 @@ class ScheduleController extends Zend_Controller_Action
$this->view->absoluteRebroadcast = $formAbsoluteRebroadcast;
$this->view->rebroadcast = $formRebroadcast;
$this->view->addNewShow = true;
//the form still needs to be "update" since
//the validity test failed.
if ($data['add_show_id'] != -1){
@ -751,9 +754,9 @@ class ScheduleController extends Zend_Controller_Action
if (!$startDateModified){
$formWhen->getElement('add_show_start_date')->setOptions(array('disabled' => true));
}
$this->view->form = $this->view->render('schedule/add-show-form.phtml');
}
}else{
$userInfo = Zend_Auth::getInstance()->getStorage()->read();

View File

@ -1,5 +1,6 @@
<?php
require_once 'customvalidators/ConditionalNotEmpty.php';
require_once 'customvalidators/PasswordNotEmpty.php';
class Application_Form_SoundcloudPreferences extends Zend_Form_SubForm
{
@ -76,7 +77,7 @@ class Application_Form_SoundcloudPreferences extends Zend_Form_SubForm
// which is something we don't want
'allowEmpty' => false,
'validators' => array(
new ConditionalNotEmpty(array('UploadToSoundcloudOption'=>'1'))
new PasswordNotEmpty(array('UploadToSoundcloudOption'=>'1'))
)
));

View File

@ -0,0 +1,18 @@
<?php
class PasswordNotEmpty extends ConditionalNotEmpty {
public function isValid($value, $context = null)
{
$result = parent::isValid($value, $context);
if (!$result) {
// allow empty if username/email was set before and didn't change
$storedUser = Application_Model_Preference::GetSoundCloudUser();
if ($storedUser != '' && $storedUser == $context['SoundCloudUser']) {
return true;
}
}
return $result;
}
}
?>

View File

@ -84,7 +84,7 @@ class Application_Model_DateHelper
public static function GetDayEndTimestampInUtc($time = "") {
$dayEndTimestamp = Application_Model_DateHelper::GetDayEndTimestamp($time);
return Application_Model_DateHelper::ConvertToUtcDateTime($dayEndTimestamp);
return Application_Model_DateHelper::ConvertToUtcDateTimeString($dayEndTimestamp);
}
/**

View File

@ -187,14 +187,16 @@ class Application_Model_Show {
$uncheckedDaysImploded = implode(",", $p_uncheckedDays);
$showId = $this->getId();
$date = new Application_Model_DateHelper;
$timestamp = $date->getTimestamp();
$timestamp = gmdate("Y-m-d H:i:s");
$sql = "DELETE FROM cc_show_instances"
." WHERE EXTRACT(DOW FROM starts) IN ($uncheckedDaysImploded)"
." AND starts > TIMESTAMP '$timestamp'"
." AND show_id = $showId";
Logging::log("sql for removing unchecked days");
Logging::log($sql);
$CC_DBC->query($sql);
}
@ -856,7 +858,8 @@ class Application_Model_Show {
//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.
$startDow = gmdate("w", $utcStartDateTime->getTimestamp());
//DOW in local time.
$startDow = date("w", $startDateTime->getTimestamp());
if (!$data['add_show_repeats']) {
$data['add_show_day_check'] = array($startDow);
} else if ($data['add_show_repeats'] && $data['add_show_day_check'] == "") {
@ -907,7 +910,10 @@ class Application_Model_Show {
$showDay->setDbRecord($isRecorded);
$showDay->save();
} else {
Logging::log("startDow is: {$startDow}");
foreach ($data['add_show_day_check'] as $day) {
Logging::log("day is: {$day}");
$daysAdd=0;
$startDateTimeClone = clone $startDateTime;
if ($startDow !== $day){
@ -916,7 +922,10 @@ class Application_Model_Show {
else
$daysAdd = $day - $startDow;
Logging::log("days to add: {$daysAdd}");
$startDateTimeClone->add(new DateInterval("P".$daysAdd."D"));
Logging::log("start date: {$startDateTimeClone->format("Y-m-d")}");
}
if (is_null($endDate) || $startDateTimeClone->getTimestamp() <= $endDateTime->getTimestamp()) {
$showDay = new CcShowDays();
@ -1556,7 +1565,7 @@ class Application_Model_Show {
* @param String $timeEnd - interval end time (in UTC)
* @return array - the next $limit number of shows within the time interval
*/
public static function GetNextShows($timeStart, $limit = 0, $timeEnd = "")
public static function GetNextShows($timeStart, $limit = "0", $timeEnd = "")
{
global $CC_CONFIG, $CC_DBC;
@ -1577,7 +1586,7 @@ class Application_Model_Show {
." ORDER BY si.starts";
// defaults to retrieve all shows within the interval if $limit not set
if($limit != 0) {
if($limit != "0") {
$sql = $sql . " LIMIT $limit";
}

View File

@ -8,7 +8,7 @@ function getContent() {
var msg = "";
if(isUpToDate()) {
msg = "You are running the latest version";
} else if(diff == 1) {
} else if(diff <= 1) { // new version is possible when major diff = 0
msg = "New version available: " + link;
} else if(diff == 2) {
msg = "This version will soon be obsolete.<br/>Please upgrade to " + link;

View File

@ -52,9 +52,13 @@
}
function getServerData(){
$.ajax({ url: options.sourceDomain + "api/live-info/", dataType:"jsonp", success:function(data){
$.ajax({url: options.sourceDomain + "api/live-info/",
data: {type:"endofday",limit:"5"},
dataType: "jsonp",
success:function(data) {
processData(data);
}, error:airtimeScheduleJsonpError});
},
error: airtimeScheduleJsonpError});
setTimeout(getServerData, options.updatePeriod*1000);
}
});
@ -130,9 +134,13 @@
}
function getServerData(){
$.ajax({ url: options.sourceDomain + "api/live-info/", dataType:"jsonp", success:function(data){
$.ajax({url: options.sourceDomain + "api/live-info/",
data: {type:"interval",limit:"5"},
dataType: "jsonp",
success: function(data) {
processData(data);
}, error:airtimeScheduleJsonpError});
},
error: airtimeScheduleJsonpError});
setTimeout(getServerData, options.updatePeriod*1000);
}
});