Merge branch 'saas-dev' into soundcloud
Conflicts: airtime_mvc/application/configs/constants.php
This commit is contained in:
commit
8fcaf7fc74
4 changed files with 116 additions and 81 deletions
|
@ -23,8 +23,10 @@ define('AIRTIME_REST_VERSION' , '1.1');
|
|||
define('AIRTIME_API_VERSION' , '1.1');
|
||||
define('AIRTIME_CODE_VERSION' , '2.5.13');
|
||||
|
||||
// Defaults
|
||||
define('DEFAULT_LOGO_PLACEHOLDER', 1);
|
||||
define('DEFAULT_LOGO_FILE', 'images/airtime_logo.png');
|
||||
define('DEFAULT_TIMESTAMP_FORMAT', 'Y-m-d H:i:s');
|
||||
|
||||
// Metadata Keys for files
|
||||
define('MDATA_KEY_FILEPATH' , 'filepath');
|
||||
|
@ -102,4 +104,3 @@ define('CELERY_FAILED_STATUS', 'FAILED');
|
|||
|
||||
// Celery Services
|
||||
define('SOUNDCLOUD_SERVICE_NAME', 'soundcloud');
|
||||
|
||||
|
|
|
@ -5,6 +5,10 @@ require_once('TuneIn.php');
|
|||
class ApiController extends Zend_Controller_Action
|
||||
{
|
||||
|
||||
const DEFAULT_SHOWS_TO_RETRIEVE = "5";
|
||||
|
||||
const DEFAULT_DAYS_TO_RETRIEVE = "2";
|
||||
|
||||
public function init()
|
||||
{
|
||||
$ignoreAuth = array("live-info",
|
||||
|
@ -173,7 +177,7 @@ class ApiController extends Zend_Controller_Action
|
|||
$timezone = Application_Model_Preference::GetDefaultTimezone();
|
||||
$userDefinedTimezone = strtolower($request->getParam('timezone'));
|
||||
$upcase = false; // only upcase the timezone abbreviations
|
||||
$this->checkTimezone($userDefinedTimezone, $timezone, $upcase);
|
||||
$this->updateTimezone($userDefinedTimezone, $timezone, $upcase);
|
||||
|
||||
$type = $request->getParam('type');
|
||||
$limit = $request->getParam('limit');
|
||||
|
@ -263,22 +267,19 @@ class ApiController extends Zend_Controller_Action
|
|||
|
||||
$request = $this->getRequest();
|
||||
|
||||
$utcTimeNow = gmdate("Y-m-d H:i:s");
|
||||
$utcTimeEnd = ""; // if empty, getNextShows will use interval instead of end of day
|
||||
|
||||
// default to the station timezone
|
||||
$timezone = Application_Model_Preference::GetDefaultTimezone();
|
||||
$userDefinedTimezone = strtolower($request->getParam('timezone'));
|
||||
$upcase = false; // only upcase the timezone abbreviations
|
||||
$this->checkTimezone($userDefinedTimezone, $timezone, $upcase);
|
||||
$this->updateTimezone($userDefinedTimezone, $timezone, $upcase);
|
||||
|
||||
$daysToRetrieve = $request->getParam('days');
|
||||
$showsToRetrieve = $request->getParam('shows');
|
||||
if ($daysToRetrieve == "" || !is_numeric($daysToRetrieve)) {
|
||||
$daysToRetrieve = "2";
|
||||
$daysToRetrieve = self::DEFAULT_DAYS_TO_RETRIEVE;
|
||||
}
|
||||
if ($showsToRetrieve == "" || !is_numeric($showsToRetrieve)) {
|
||||
$showsToRetrieve = "5";
|
||||
$showsToRetrieve = self::DEFAULT_SHOWS_TO_RETRIEVE;
|
||||
}
|
||||
|
||||
// set the end time to the day's start n days from now.
|
||||
|
@ -286,7 +287,7 @@ class ApiController extends Zend_Controller_Action
|
|||
// days=2 will return shows until the end of tomorrow, etc.
|
||||
$end = Application_Common_DateHelper::getEndDateTime($timezone, $daysToRetrieve);
|
||||
$end->setTimezone(new DateTimeZone("UTC"));
|
||||
$utcTimeEnd = $end->format("Y-m-d H:i:s");
|
||||
$utcTimeEnd = $end->format(DEFAULT_TIMESTAMP_FORMAT);
|
||||
|
||||
$result = Application_Model_Schedule::GetPlayOrderRange($utcTimeEnd, $showsToRetrieve);
|
||||
|
||||
|
@ -326,7 +327,7 @@ class ApiController extends Zend_Controller_Action
|
|||
* @param string $timezone the default timezone
|
||||
* @param boolean $upcase whether the timezone output should be upcased
|
||||
*/
|
||||
private function checkTimezone($userDefinedTimezone, &$timezone, &$upcase)
|
||||
private function updateTimezone($userDefinedTimezone, &$timezone, &$upcase)
|
||||
{
|
||||
$delimiter = "/";
|
||||
// if the user passes in a timezone in standard form ("Continent/City")
|
||||
|
@ -347,7 +348,7 @@ class ApiController extends Zend_Controller_Action
|
|||
* If the user passed in a timezone parameter, adjust timezone-dependent
|
||||
* variables in the result to reflect the given timezone.
|
||||
*
|
||||
* @param object $result reference to the object to send back to the user
|
||||
* @param array $result reference to the object to send back to the user
|
||||
* @param string $timezone the user's timezone parameter value
|
||||
* @param boolean $upcase whether the timezone output should be upcased
|
||||
*/
|
||||
|
|
|
@ -2,6 +2,12 @@
|
|||
|
||||
class Application_Model_Schedule
|
||||
{
|
||||
|
||||
const MASTER_SOURCE_NAME = "Master";
|
||||
const SHOW_SOURCE_NAME = "Live";
|
||||
const SCHEDULED_SOURCE_NAME = "Scheduled";
|
||||
const LIVE_STREAM = "Live Stream";
|
||||
|
||||
/**
|
||||
* Return TRUE if file is going to be played in the future.
|
||||
*
|
||||
|
@ -99,12 +105,14 @@ SQL;
|
|||
|
||||
$shows = Application_Model_Show::getPrevCurrentNext($utcNow, $utcTimeEnd, $showsToRetrieve);
|
||||
$currentShowID = count($shows['currentShow'])>0?$shows['currentShow']['instance_id']:null;
|
||||
$results = Application_Model_Schedule::getPreviousCurrentNextMedia($utcNow, $currentShowID);
|
||||
$source = self::_getSource();
|
||||
$results = Application_Model_Schedule::getPreviousCurrentNextMedia($utcNow, $currentShowID, self::_getSource());
|
||||
|
||||
$range = array(
|
||||
"station" => array (
|
||||
"env" => APPLICATION_ENV,
|
||||
"schedulerTime" => $utcNow->format("Y-m-d H:i:s")
|
||||
"schedulerTime" => $utcNow->format("Y-m-d H:i:s"),
|
||||
"source_enabled" => $source
|
||||
),
|
||||
//Previous, current, next songs!
|
||||
"tracks" => array(
|
||||
|
@ -135,7 +143,8 @@ SQL;
|
|||
|
||||
$shows = Application_Model_Show::getPrevCurrentNextOld($utcNow);
|
||||
$currentShowID = count($shows['currentShow'])>0?$shows['currentShow'][0]['instance_id']:null;
|
||||
$results = Application_Model_Schedule::getPreviousCurrentNextMedia($utcNow, $currentShowID);
|
||||
$source = self::_getSource();
|
||||
$results = Application_Model_Schedule::getPreviousCurrentNextMedia($utcNow, $currentShowID, $source);
|
||||
|
||||
$range = array(
|
||||
"env" => APPLICATION_ENV,
|
||||
|
@ -146,7 +155,8 @@ SQL;
|
|||
"next"=> $results['next'] !=null?$results['next']:(count($shows['nextShow'])>0?$shows['nextShow'][0]:null),
|
||||
//Current and next shows
|
||||
"currentShow"=>$shows['currentShow'],
|
||||
"nextShow"=>$shows['nextShow']
|
||||
"nextShow"=>$shows['nextShow'],
|
||||
"source_enabled" => $source
|
||||
);
|
||||
|
||||
return $range;
|
||||
|
@ -158,11 +168,12 @@ SQL;
|
|||
* find an item that played previously and is scheduled to play next.
|
||||
*
|
||||
* @param $utcNow DateTime current time in UTC
|
||||
* @param $currentShowInstanceId cc_show_instance id of the show instance currently playing
|
||||
* @param $currentShowInstanceId int id of the show instance currently playing
|
||||
* @param $source string the current prioritized source
|
||||
* @return array with data about the previous, current, and next media items playing.
|
||||
* Returns an empty arrays if there is no media item currently playing
|
||||
*/
|
||||
public static function getPreviousCurrentNextMedia($utcNow, $currentShowInstanceId)
|
||||
public static function getPreviousCurrentNextMedia($utcNow, $currentShowInstanceId, $source)
|
||||
{
|
||||
$timeZone = new DateTimeZone("UTC"); //This function works entirely in UTC.
|
||||
assert(get_class($utcNow) === "DateTime");
|
||||
|
@ -178,21 +189,26 @@ SQL;
|
|||
and s.ends >= :p2 and s.instance_id = :p3 order by starts desc limit 1";
|
||||
|
||||
$params = array(
|
||||
":p1" => $utcNow->format("Y-m-d H:i:s"),
|
||||
":p2" => $utcNow->format("Y-m-d H:i:s"),
|
||||
":p1" => $utcNow->format(DEFAULT_TIMESTAMP_FORMAT),
|
||||
":p2" => $utcNow->format(DEFAULT_TIMESTAMP_FORMAT),
|
||||
":p3" => $currentShowInstanceId
|
||||
);
|
||||
|
||||
$rows = Application_Common_Database::prepareAndExecute($sql, $params);
|
||||
|
||||
if (count($rows) < 1) {
|
||||
return $results;
|
||||
}
|
||||
|
||||
if ($rows[0]["show_ends"] < $utcNow->format("Y-m-d H:i:s")) {
|
||||
return $results;
|
||||
}
|
||||
|
||||
// If live streaming (master or show source) is enabled, set the current
|
||||
// track information to the current show values
|
||||
if ($source != self::SCHEDULED_SOURCE_NAME) {
|
||||
$show = Application_Model_Show::getCurrentShow();
|
||||
$results["current"] = array(
|
||||
"starts" => $show[0]["starts"],
|
||||
"ends" => $show[0]["ends"],
|
||||
"type" => _("livestream"),
|
||||
"name" => (isset($show[0])?$show[0]["name"]:"") . " - " . _(self::LIVE_STREAM),
|
||||
"media_item_played" => false,
|
||||
"record" => "0"
|
||||
);
|
||||
} else if (count($rows) >= 1) {
|
||||
$currentMedia = $rows[0];
|
||||
|
||||
if ($currentMedia["ends"] > $currentMedia["show_ends"]) {
|
||||
|
@ -223,6 +239,7 @@ SQL;
|
|||
} else {
|
||||
$currentMediaType = null;
|
||||
}
|
||||
|
||||
$results["current"] = array(
|
||||
"starts" => $currentMedia["starts"],
|
||||
"ends" => $currentMedia["ends"],
|
||||
|
@ -231,10 +248,10 @@ SQL;
|
|||
"media_item_played" => $currentMedia["media_item_played"],
|
||||
"record" => "0"
|
||||
);
|
||||
}
|
||||
|
||||
$previousMedia = CcScheduleQuery::create()
|
||||
->filterByDbStarts($currentMedia["starts"], Criteria::LESS_THAN)
|
||||
->filterByDbId($currentMedia["id"], Criteria::NOT_EQUAL)
|
||||
->filterByDbEnds($utcNow, Criteria::LESS_THAN)
|
||||
->filterByDbPlayoutStatus(0, Criteria::GREATER_THAN)
|
||||
->orderByDbStarts(Criteria::DESC)
|
||||
->findOne();
|
||||
|
@ -266,8 +283,7 @@ SQL;
|
|||
}
|
||||
|
||||
$nextMedia = CcScheduleQuery::create()
|
||||
->filterByDbStarts($currentMedia["starts"], Criteria::GREATER_THAN)
|
||||
->filterByDbId($currentMedia["id"], Criteria::NOT_EQUAL)
|
||||
->filterByDbStarts($utcNow, Criteria::GREATER_THAN)
|
||||
->filterByDbPlayoutStatus(0, Criteria::GREATER_THAN)
|
||||
->orderByDbStarts(Criteria::ASC)
|
||||
->findOne();
|
||||
|
@ -301,6 +317,21 @@ SQL;
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current prioritized source
|
||||
*
|
||||
* Priority order is Master->Live/Show->Scheduled.
|
||||
*
|
||||
* @return string the source name
|
||||
*/
|
||||
private static function _getSource() {
|
||||
$live_dj = Application_Model_Preference::GetSourceStatus("live_dj");
|
||||
$master_dj = Application_Model_Preference::GetSourceStatus("master_dj");
|
||||
$source = ($master_dj ? self::MASTER_SOURCE_NAME
|
||||
: ($live_dj ? self::SHOW_SOURCE_NAME : self::SCHEDULED_SOURCE_NAME));
|
||||
return $source;
|
||||
}
|
||||
|
||||
public static function GetLastScheduleItem($p_timeNow)
|
||||
{
|
||||
$sql = <<<SQL
|
||||
|
|
|
@ -711,17 +711,19 @@ var AIRTIME = (function(AIRTIME) {
|
|||
// icon.
|
||||
$(nRow).find("td:not(.library_checkbox, .library_type)").qtip({
|
||||
content: {
|
||||
text: $.i18n._("Loading..."),
|
||||
text: function(event, api) {
|
||||
$.get(baseUrl+"library/get-file-metadata",
|
||||
({format: "html", id : aData.id, type: aData.ftype}),
|
||||
function (html) {
|
||||
api.set('content.text', html);
|
||||
}, "html")
|
||||
.fail(function (xhr, status, error) {
|
||||
api.set('content.text', status + ': ' + error)
|
||||
});
|
||||
return 'Loading...';
|
||||
},
|
||||
title: {
|
||||
text: aData.track_title
|
||||
},
|
||||
ajax: {
|
||||
url: baseUrl+"Library/get-file-metadata",
|
||||
type: "get",
|
||||
data: ({format: "html", id : aData.id, type: aData.ftype}),
|
||||
success: function(data, status) {
|
||||
this.set('content.text', data);
|
||||
}
|
||||
}
|
||||
},
|
||||
position: {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue