From e36c8a16d4194bdff590b2922a8082cc2cdad1f4 Mon Sep 17 00:00:00 2001 From: Duncan Sommerville Date: Mon, 22 Jun 2015 10:46:29 -0400 Subject: [PATCH 1/6] CC-6060 - Fix breaking tooltips when viewing context menu in library --- .../public/js/airtime/library/library.js | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/airtime_mvc/public/js/airtime/library/library.js b/airtime_mvc/public/js/airtime/library/library.js index dae2d916e..2a59ece24 100644 --- a/airtime_mvc/public/js/airtime/library/library.js +++ b/airtime_mvc/public/js/airtime/library/library.js @@ -722,17 +722,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: { @@ -755,7 +757,7 @@ var AIRTIME = (function(AIRTIME) { show: function(event, api) { // Only show the tooltip if it was a right-click if(event.originalEvent.button !== 2) { - event.preventDefault(); + event.preventDefault(); } } }, From 7645f67515317dd550a20f0b7b46785aaff685b1 Mon Sep 17 00:00:00 2001 From: Duncan Sommerville Date: Wed, 24 Jun 2015 12:18:52 -0400 Subject: [PATCH 2/6] SAAS-877 - Update live-info-v2 api --- airtime_mvc/application/configs/constants.php | 1 + .../application/controllers/ApiController.php | 27 ++++++++++--------- airtime_mvc/application/models/Schedule.php | 22 +++++++++++++++ 3 files changed, 37 insertions(+), 13 deletions(-) diff --git a/airtime_mvc/application/configs/constants.php b/airtime_mvc/application/configs/constants.php index 4c71a323c..0b6509649 100644 --- a/airtime_mvc/application/configs/constants.php +++ b/airtime_mvc/application/configs/constants.php @@ -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'); diff --git a/airtime_mvc/application/controllers/ApiController.php b/airtime_mvc/application/controllers/ApiController.php index baee530b2..02dcd1461 100644 --- a/airtime_mvc/application/controllers/ApiController.php +++ b/airtime_mvc/application/controllers/ApiController.php @@ -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 */ @@ -359,9 +360,9 @@ class ApiController extends Zend_Controller_Action $timezone ); - //Convert the UTC scheduler time ("now") to the user-defined timezone. - $result["station"]["schedulerTime"] = Application_Common_DateHelper::UTCStringToTimezoneString($result["station"]["schedulerTime"], $timezone); - $result["station"]["timezone"] = $upcase ? strtoupper($timezone) : $timezone; + //Convert the UTC scheduler time ("now") to the user-defined timezone. + $result["station"]["schedulerTime"] = Application_Common_DateHelper::UTCStringToTimezoneString($result["station"]["schedulerTime"], $timezone); + $result["station"]["timezone"] = $upcase ? strtoupper($timezone) : $timezone; } public function weekInfoAction() diff --git a/airtime_mvc/application/models/Schedule.php b/airtime_mvc/application/models/Schedule.php index 56b25e207..33a3ab357 100644 --- a/airtime_mvc/application/models/Schedule.php +++ b/airtime_mvc/application/models/Schedule.php @@ -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 = << Date: Wed, 24 Jun 2015 12:31:32 -0400 Subject: [PATCH 3/6] SAAS-877 - Update live-info-v2 api --- airtime_mvc/application/models/Schedule.php | 26 ++++++++++----------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/airtime_mvc/application/models/Schedule.php b/airtime_mvc/application/models/Schedule.php index 33a3ab357..bbf0c5bca 100644 --- a/airtime_mvc/application/models/Schedule.php +++ b/airtime_mvc/application/models/Schedule.php @@ -104,12 +104,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, $source); $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( @@ -162,12 +164,13 @@ SQL; * If a current media item is currently playing, this function then attempts to * 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 $utcNow DateTime current time in UTC + * @param $currentShowInstanceId int id of the show instance currently playing + * @param $source string id of the show instance currently playing * @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"); @@ -183,18 +186,15 @@ 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")) { + if ((count($rows) < 1 || $rows[0]["show_ends"] < $utcNow->format(DEFAULT_TIMESTAMP_FORMAT) + && ($source == self::SCHEDULED_SOURCE_NAME))) { // Only return if the show is using scheduled playback return $results; } @@ -204,7 +204,6 @@ SQL; $currentMedia["ends"] = $currentMedia["show_ends"]; } - $source = self::_getSource(); $currentMediaFileId = $currentMedia["file_id"]; $currentMediaStreamId = $currentMedia["stream_id"]; if (isset($currentMediaFileId)) { @@ -242,7 +241,6 @@ SQL; "type" => $currentMediaType, "name" => $currentMediaName, "media_item_played" => $currentMedia["media_item_played"], - "source_enabled" => $source, "record" => "0" ); From fd8194e7d8d0273e64545fe3d00be63806188731 Mon Sep 17 00:00:00 2001 From: Duncan Sommerville Date: Wed, 24 Jun 2015 12:40:51 -0400 Subject: [PATCH 4/6] Fix error getting media --- airtime_mvc/application/models/Schedule.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/airtime_mvc/application/models/Schedule.php b/airtime_mvc/application/models/Schedule.php index bbf0c5bca..a7d027dd2 100644 --- a/airtime_mvc/application/models/Schedule.php +++ b/airtime_mvc/application/models/Schedule.php @@ -105,7 +105,7 @@ SQL; $shows = Application_Model_Show::getPrevCurrentNext($utcNow, $utcTimeEnd, $showsToRetrieve); $currentShowID = count($shows['currentShow'])>0?$shows['currentShow']['instance_id']:null; $source = self::_getSource(); - $results = Application_Model_Schedule::getPreviousCurrentNextMedia($utcNow, $currentShowID, $source); + $results = Application_Model_Schedule::getPreviousCurrentNextMedia($utcNow, $currentShowID, self::_getSource()); $range = array( "station" => array ( @@ -142,8 +142,9 @@ 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, "schedulerTime" => $utcNow->format("Y-m-d H:i:s"), @@ -153,7 +154,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; From ef957fe0aa5e899099ddb7de3f18d66d0130730e Mon Sep 17 00:00:00 2001 From: Duncan Sommerville Date: Wed, 24 Jun 2015 13:07:13 -0400 Subject: [PATCH 5/6] SAAS-877 - Fix errors --- airtime_mvc/application/models/Schedule.php | 37 ++++++++++++--------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/airtime_mvc/application/models/Schedule.php b/airtime_mvc/application/models/Schedule.php index a7d027dd2..1df348900 100644 --- a/airtime_mvc/application/models/Schedule.php +++ b/airtime_mvc/application/models/Schedule.php @@ -195,8 +195,19 @@ SQL; $rows = Application_Common_Database::prepareAndExecute($sql, $params); - if ((count($rows) < 1 || $rows[0]["show_ends"] < $utcNow->format(DEFAULT_TIMESTAMP_FORMAT) - && ($source == self::SCHEDULED_SOURCE_NAME))) { // Only return if the show is using scheduled playback + if ($source != self::SCHEDULED_SOURCE_NAME) { + $show = Application_Model_Show::getCurrentShow(); + $results["current"] = array( + "starts" => $show[0]["starts"], + "ends" => $show[0]["ends"], + "type" => _($source . " Stream"), + "name" => (isset($show[0])?$show[0]["name"]:"") . " - " . _($source . " Stream"), + "media_item_played" => false, + "record" => "0" + ); + } + + if (count($rows) < 1 || $rows[0]["show_ends"] < $utcNow->format(DEFAULT_TIMESTAMP_FORMAT)) { return $results; } @@ -231,21 +242,17 @@ SQL; $currentMediaType = null; } - if ($source != self::SCHEDULED_SOURCE_NAME) { - $show = Application_Model_Show::getCurrentShow(); - $currentMediaName = isset($show[0])?$show[0]["name"]:""; - $currentMediaName .= " - " . _($source . " Stream"); + if (is_null($results["current"])) { + $results["current"] = array( + "starts" => $currentMedia["starts"], + "ends" => $currentMedia["ends"], + "type" => $currentMediaType, + "name" => $currentMediaName, + "media_item_played" => $currentMedia["media_item_played"], + "record" => "0" + ); } - $results["current"] = array( - "starts" => $currentMedia["starts"], - "ends" => $currentMedia["ends"], - "type" => $currentMediaType, - "name" => $currentMediaName, - "media_item_played" => $currentMedia["media_item_played"], - "record" => "0" - ); - $previousMedia = CcScheduleQuery::create() ->filterByDbStarts($currentMedia["starts"], Criteria::LESS_THAN) ->filterByDbId($currentMedia["id"], Criteria::NOT_EQUAL) From 616cf143d53931415ce1aa07913979b3ff558260 Mon Sep 17 00:00:00 2001 From: Duncan Sommerville Date: Wed, 24 Jun 2015 14:28:04 -0400 Subject: [PATCH 6/6] SAAS-877 - Fix live-info-v2 behaviour --- airtime_mvc/application/models/Schedule.php | 86 +++++++++++---------- 1 file changed, 44 insertions(+), 42 deletions(-) diff --git a/airtime_mvc/application/models/Schedule.php b/airtime_mvc/application/models/Schedule.php index 1df348900..6b53c35e1 100644 --- a/airtime_mvc/application/models/Schedule.php +++ b/airtime_mvc/application/models/Schedule.php @@ -6,6 +6,7 @@ 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. @@ -168,7 +169,7 @@ SQL; * * @param $utcNow DateTime current time in UTC * @param $currentShowInstanceId int id of the show instance currently playing - * @param $source string 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 */ @@ -195,54 +196,50 @@ SQL; $rows = Application_Common_Database::prepareAndExecute($sql, $params); + // 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" => _($source . " Stream"), - "name" => (isset($show[0])?$show[0]["name"]:"") . " - " . _($source . " Stream"), + "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 (count($rows) < 1 || $rows[0]["show_ends"] < $utcNow->format(DEFAULT_TIMESTAMP_FORMAT)) { - return $results; - } - - $currentMedia = $rows[0]; - - if ($currentMedia["ends"] > $currentMedia["show_ends"]) { - $currentMedia["ends"] = $currentMedia["show_ends"]; - } - - $currentMediaFileId = $currentMedia["file_id"]; - $currentMediaStreamId = $currentMedia["stream_id"]; - if (isset($currentMediaFileId)) { - $currentMediaType = "track"; - $currentFile = CcFilesQuery::create() - ->filterByDbId($currentMediaFileId) - ->findOne(); - $currentMediaName = $currentFile->getDbArtistName() . " - " . $currentFile->getDbTrackTitle(); - } else if (isset($currentMediaStreamId)) { - $currentMediaType = "webstream"; - $currentWebstream = CcWebstreamQuery::create() - ->filterByDbId($currentMediaStreamId) - ->findOne(); - $currentWebstreamMetadata = CcWebstreamMetadataQuery::create() - ->filterByDbInstanceId($currentMedia["instance_id"]) - ->orderByDbStartTime(Criteria::DESC) - ->findOne(); - $currentMediaName = $currentWebstream->getDbName(); - if (isset($currentWebstreamMetadata)) { - $currentMediaName .= " - " . $currentWebstreamMetadata->getDbLiquidsoapData(); + if ($currentMedia["ends"] > $currentMedia["show_ends"]) { + $currentMedia["ends"] = $currentMedia["show_ends"]; + } + + $currentMediaFileId = $currentMedia["file_id"]; + $currentMediaStreamId = $currentMedia["stream_id"]; + if (isset($currentMediaFileId)) { + $currentMediaType = "track"; + $currentFile = CcFilesQuery::create() + ->filterByDbId($currentMediaFileId) + ->findOne(); + $currentMediaName = $currentFile->getDbArtistName() . " - " . $currentFile->getDbTrackTitle(); + } else if (isset($currentMediaStreamId)) { + $currentMediaType = "webstream"; + $currentWebstream = CcWebstreamQuery::create() + ->filterByDbId($currentMediaStreamId) + ->findOne(); + $currentWebstreamMetadata = CcWebstreamMetadataQuery::create() + ->filterByDbInstanceId($currentMedia["instance_id"]) + ->orderByDbStartTime(Criteria::DESC) + ->findOne(); + $currentMediaName = $currentWebstream->getDbName(); + if (isset($currentWebstreamMetadata)) { + $currentMediaName .= " - " . $currentWebstreamMetadata->getDbLiquidsoapData(); + } + } else { + $currentMediaType = null; } - } else { - $currentMediaType = null; - } - if (is_null($results["current"])) { $results["current"] = array( "starts" => $currentMedia["starts"], "ends" => $currentMedia["ends"], @@ -254,8 +251,7 @@ SQL; } $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(); @@ -287,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(); @@ -322,6 +317,13 @@ 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");