SAAS-877 - Update live-info-v2 api

This commit is contained in:
Duncan Sommerville 2015-06-24 12:18:52 -04:00
parent e36c8a16d4
commit 7645f67515
3 changed files with 37 additions and 13 deletions

View file

@ -102,3 +102,4 @@ define('PROVISIONING_STATUS_ACTIVE' , 'Active');
//TuneIn integration
define("TUNEIN_API_URL", "http://air.radiotime.com/Playing.ashx");
define('DEFAULT_TIMESTAMP_FORMAT', 'Y-m-d H:i:s');

View file

@ -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
*/

View file

@ -2,6 +2,11 @@
class Application_Model_Schedule
{
const MASTER_SOURCE_NAME = "Master";
const SHOW_SOURCE_NAME = "Live";
const SCHEDULED_SOURCE_NAME = "Scheduled";
/**
* Return TRUE if file is going to be played in the future.
*
@ -199,6 +204,7 @@ SQL;
$currentMedia["ends"] = $currentMedia["show_ends"];
}
$source = self::_getSource();
$currentMediaFileId = $currentMedia["file_id"];
$currentMediaStreamId = $currentMedia["stream_id"];
if (isset($currentMediaFileId)) {
@ -223,12 +229,20 @@ SQL;
} else {
$currentMediaType = null;
}
if ($source != self::SCHEDULED_SOURCE_NAME) {
$show = Application_Model_Show::getCurrentShow();
$currentMediaName = isset($show[0])?$show[0]["name"]:"";
$currentMediaName .= " - " . _($source . " Stream");
}
$results["current"] = array(
"starts" => $currentMedia["starts"],
"ends" => $currentMedia["ends"],
"type" => $currentMediaType,
"name" => $currentMediaName,
"media_item_played" => $currentMedia["media_item_played"],
"source_enabled" => $source,
"record" => "0"
);
@ -301,6 +315,14 @@ SQL;
}
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