Merge branch '2.5.x' into saas-pullreq77

Conflicts:
	airtime_mvc/application/Bootstrap.php
	airtime_mvc/application/controllers/ApiController.php
This commit is contained in:
Albert Santoni 2015-01-09 13:10:54 -05:00
commit f0bad70cee
11 changed files with 361 additions and 189 deletions

View file

@ -5,8 +5,19 @@ class ApiController extends Zend_Controller_Action
public function init()
{
$ignoreAuth = array("live-info", "live-info-v2", "week-info",
"station-metadata", "station-logo", "show-logo");
$ignoreAuth = array("live-info",
"live-info-v2",
"week-info",
"station-metadata",
"station-logo",
"show-history-feed",
"item-history-feed",
"shows",
"show-tracks",
"show-schedules",
"station-logo",
"show-logo"
);
$params = $this->getRequest()->getParams();
if (!in_array($params['action'], $ignoreAuth)) {
@ -274,10 +285,10 @@ class ApiController extends Zend_Controller_Action
$utcTimeEnd = $end->format("Y-m-d H:i:s");
$result = array(
"env" => APPLICATION_ENV,
"schedulerTime" => $utcTimeNow,
"currentShow" => Application_Model_Show::getCurrentShow($utcTimeNow),
"nextShow" => Application_Model_Show::getNextShows($utcTimeNow, $limit, $utcTimeEnd)
"env" => APPLICATION_ENV,
"schedulerTime" => $utcTimeNow,
"currentShow" => Application_Model_Show::getCurrentShow($utcTimeNow),
"nextShow" => Application_Model_Show::getNextShows($utcTimeNow, $limit, $utcTimeEnd)
);
} else {
$result = Application_Model_Schedule::GetPlayOrderRangeOld($limit);
@ -487,9 +498,9 @@ class ApiController extends Zend_Controller_Action
$shows,
array("starts", "ends", "start_timestamp","end_timestamp"),
$timezone
);
);
$result[$dow[$i]] = $shows;
$result[$dow[$i]] = $shows;
}
// XSS exploit prevention
@ -1420,4 +1431,175 @@ class ApiController extends Zend_Controller_Action
Application_Model_StreamSetting::SetListenerStatError($k, $v);
}
}
/**
* display played items for a given time range and show instance_id
*
* @return json array
*/
public function itemHistoryFeedAction()
{
try {
$request = $this->getRequest();
$params = $request->getParams();
$instance = $request->getParam("instance_id", null);
list($startsDT, $endsDT) = Application_Common_HTTPHelper::getStartEndFromRequest($request);
$historyService = new Application_Service_HistoryService();
$results = $historyService->getPlayedItemData($startsDT, $endsDT, $params, $instance);
$this->_helper->json->sendJson($results['history']);
}
catch (Exception $e) {
Logging::info($e);
Logging::info($e->getMessage());
}
}
/**
* display show schedules for a given time range and show instance_id
*
* @return json array
*/
public function showHistoryFeedAction()
{
try {
$request = $this->getRequest();
$params = $request->getParams();
$userId = $request->getParam("user_id", null);
list($startsDT, $endsDT) = Application_Common_HTTPHelper::getStartEndFromRequest($request);
$historyService = new Application_Service_HistoryService();
$shows = $historyService->getShowList($startsDT, $endsDT, $userId);
$this->_helper->json->sendJson($shows);
}
catch (Exception $e) {
Logging::info($e);
Logging::info($e->getMessage());
}
}
/**
* display show info (without schedule) for given show_id
*
* @return json array
*/
public function showsAction()
{
try {
$request = $this->getRequest();
$params = $request->getParams();
$showId = $request->getParam("show_id", null);
$results = array();
if (empty($showId)) {
$shows = CcShowQuery::create()->find();
foreach($shows as $show) {
$results[] = $show->getShowInfo();
}
} else {
$show = CcShowQuery::create()->findPK($showId);
$results[] = $show->getShowInfo();
}
$this->_helper->json->sendJson($results);
}
catch (Exception $e) {
Logging::info($e);
Logging::info($e->getMessage());
}
}
/**
* display show schedule for given show_id
*
* @return json array
*/
public function showSchedulesAction()
{
try {
$request = $this->getRequest();
$params = $request->getParams();
$showId = $request->getParam("show_id", null);
list($startsDT, $endsDT) = Application_Common_HTTPHelper::getStartEndFromRequest($request);
if ((!isset($showId)) || (!is_numeric($showId))) {
//if (!isset($showId)) {
$this->_helper->json->sendJson(
array("jsonrpc" => "2.0", "error" => array("code" => 400, "message" => "missing invalid type for required show_id parameter. use type int.".$showId))
);
}
$shows = Application_Model_Show::getShows($startsDT, $endsDT, FALSE, $showId);
// is this a valid show?
if (empty($shows)) {
$this->_helper->json->sendJson(
array("jsonrpc" => "2.0", "error" => array("code" => 204, "message" => "no content for requested show_id"))
);
}
$this->_helper->json->sendJson($shows);
}
catch (Exception $e) {
Logging::info($e);
Logging::info($e->getMessage());
}
}
/**
* displays track listing for given instance_id
*
* @return json array
*/
public function showTracksAction()
{
$baseUrl = Application_Common_OsPath::getBaseDir();
$prefTimezone = Application_Model_Preference::GetTimezone();
$instanceId = $this->_getParam('instance_id');
if ((!isset($instanceId)) || (!is_numeric($instanceId))) {
$this->_helper->json->sendJson(
array("jsonrpc" => "2.0", "error" => array("code" => 400, "message" => "missing invalid type for required instance_id parameter. use type int"))
);
}
$showInstance = new Application_Model_ShowInstance($instanceId);
$showInstanceContent = $showInstance->getShowListContent($prefTimezone);
// is this a valid show instance with content?
if (empty($showInstanceContent)) {
$this->_helper->json->sendJson(
array("jsonrpc" => "2.0", "error" => array("code" => 204, "message" => "no content for requested instance_id"))
);
}
$result = array();
$position = 0;
foreach ($showInstanceContent as $track) {
$elementMap = array(
'title' => isset($track['track_title']) ? $track['track_title'] : "",
'artist' => isset($track['creator']) ? $track['creator'] : "",
'position' => $position,
'id' => ++$position,
'mime' => isset($track['mime'])?$track['mime']:"",
'starts' => isset($track['starts']) ? $track['starts'] : "",
'length' => isset($track['length']) ? $track['length'] : "",
'file_id' => ($track['type'] == 0) ? $track['item_id'] : $track['filepath']
);
$result[] = $elementMap;
}
$this->_helper->json($result);
}
}

View file

@ -10,49 +10,6 @@ class ListenerstatController extends Zend_Controller_Action
->initContext();
}
private function getStartEnd()
{
$request = $this->getRequest();
$userTimezone = new DateTimeZone(Application_Model_Preference::GetUserTimezone());
$utcTimezone = new DateTimeZone("UTC");
$utcNow = new DateTime("now", $utcTimezone);
$start = $request->getParam("start");
$end = $request->getParam("end");
if (empty($start) || empty($end)) {
$startsDT = clone $utcNow;
$startsDT->sub(new DateInterval("P1D"));
$endsDT = clone $utcNow;
}
else {
try {
$startsDT = new DateTime($start, $userTimezone);
$startsDT->setTimezone($utcTimezone);
$endsDT = new DateTime($end, $userTimezone);
$endsDT->setTimezone($utcTimezone);
if ($startsDT > $endsDT) {
throw new Exception("start greater than end");
}
}
catch (Exception $e) {
Logging::info($e);
Logging::info($e->getMessage());
$startsDT = clone $utcNow;
$startsDT->sub(new DateInterval("P1D"));
$endsDT = clone $utcNow;
}
}
return array($startsDT, $endsDT);
}
public function indexAction()
{
$CC_CONFIG = Config::getConfig();
@ -69,7 +26,7 @@ class ListenerstatController extends Zend_Controller_Action
$this->view->headLink()->appendStylesheet($baseUrl.'css/jquery.ui.timepicker.css?'.$CC_CONFIG['airtime_version']);
list($startsDT, $endsDT) = $this->getStartEnd();
list($startsDT, $endsDT) = Application_Common_HTTPHelper::getStartEndFromRequest($request);
$userTimezone = new DateTimeZone(Application_Model_Preference::GetUserTimezone());
$startsDT->setTimezone($userTimezone);
$endsDT->setTimezone($userTimezone);
@ -98,7 +55,7 @@ class ListenerstatController extends Zend_Controller_Action
}
public function getDataAction(){
list($startsDT, $endsDT) = $this->getStartEnd();
list($startsDT, $endsDT) = Application_Common_HTTPHelper::getStartEndFromRequest($this->getRequest());
$data = Application_Model_ListenerStat::getDataPointsWithinRange($startsDT->format("Y-m-d H:i:s"), $endsDT->format("Y-m-d H:i:s"));
$this->_helper->json->sendJson($data);

View file

@ -19,56 +19,13 @@ class PlayouthistoryController extends Zend_Controller_Action
->initContext();
}
private function getStartEnd()
{
$request = $this->getRequest();
$userTimezone = new DateTimeZone(Application_Model_Preference::GetUserTimezone());
$utcTimezone = new DateTimeZone("UTC");
$utcNow = new DateTime("now", $utcTimezone);
$start = $request->getParam("start");
$end = $request->getParam("end");
if (empty($start) || empty($end)) {
$startsDT = clone $utcNow;
$startsDT->sub(new DateInterval("P1D"));
$endsDT = clone $utcNow;
}
else {
try {
$startsDT = new DateTime($start, $userTimezone);
$startsDT->setTimezone($utcTimezone);
$endsDT = new DateTime($end, $userTimezone);
$endsDT->setTimezone($utcTimezone);
if ($startsDT > $endsDT) {
throw new Exception("start greater than end");
}
}
catch (Exception $e) {
Logging::info($e);
Logging::info($e->getMessage());
$startsDT = clone $utcNow;
$startsDT->sub(new DateInterval("P1D"));
$endsDT = clone $utcNow;
}
}
return array($startsDT, $endsDT);
}
public function indexAction()
{
$CC_CONFIG = Config::getConfig();
$baseUrl = Application_Common_OsPath::getBaseDir();
list($startsDT, $endsDT) = $this->getStartEnd();
list($startsDT, $endsDT) = Application_Common_HTTPHelper::getStartEndFromRequest($this->getRequest());
$userTimezone = new DateTimeZone(Application_Model_Preference::GetUserTimezone());
$startsDT->setTimezone($userTimezone);
$endsDT->setTimezone($userTimezone);
@ -123,7 +80,7 @@ class PlayouthistoryController extends Zend_Controller_Action
$params = $request->getParams();
$instance = $request->getParam("instance_id", null);
list($startsDT, $endsDT) = $this->getStartEnd();
list($startsDT, $endsDT) = Application_Common_HTTPHelper::getStartEndFromRequest($request);
$historyService = new Application_Service_HistoryService();
$r = $historyService->getFileSummaryData($startsDT, $endsDT, $params);
@ -146,7 +103,7 @@ class PlayouthistoryController extends Zend_Controller_Action
$params = $request->getParams();
$instance = $request->getParam("instance_id", null);
list($startsDT, $endsDT) = $this->getStartEnd();
list($startsDT, $endsDT) = Application_Common_HTTPHelper::getStartEndFromRequest($request);
$historyService = new Application_Service_HistoryService();
$r = $historyService->getPlayedItemData($startsDT, $endsDT, $params, $instance);
@ -169,7 +126,7 @@ class PlayouthistoryController extends Zend_Controller_Action
$params = $request->getParams();
$instance = $request->getParam("instance_id", null);
list($startsDT, $endsDT) = $this->getStartEnd();
list($startsDT, $endsDT) = Application_Common_HTTPHelper::getStartEndFromRequest($request);
$historyService = new Application_Service_HistoryService();
$shows = $historyService->getShowList($startsDT, $endsDT);

View file

@ -244,49 +244,6 @@ class ShowbuilderController extends Zend_Controller_Action
$this->view->dialog = $this->view->render('showbuilder/builderDialog.phtml');
}
private function getStartEnd()
{
$request = $this->getRequest();
$userTimezone = new DateTimeZone(Application_Model_Preference::GetUserTimezone());
$utcTimezone = new DateTimeZone("UTC");
$utcNow = new DateTime("now", $utcTimezone);
$start = $request->getParam("start");
$end = $request->getParam("end");
if (empty($start) || empty($end)) {
$startsDT = clone $utcNow;
$startsDT->sub(new DateInterval("P1D"));
$endsDT = clone $utcNow;
}
else {
try {
$startsDT = new DateTime($start, $userTimezone);
$startsDT->setTimezone($utcTimezone);
$endsDT = new DateTime($end, $userTimezone);
$endsDT->setTimezone($utcTimezone);
if ($startsDT > $endsDT) {
throw new Exception("start greater than end");
}
}
catch (Exception $e) {
Logging::info($e);
Logging::info($e->getMessage());
$startsDT = clone $utcNow;
$startsDT->sub(new DateInterval("P1D"));
$endsDT = clone $utcNow;
}
}
return array($startsDT, $endsDT);
}
public function checkBuilderFeedAction()
{
$request = $this->getRequest();
@ -295,7 +252,7 @@ class ShowbuilderController extends Zend_Controller_Action
$timestamp = intval($request->getParam("timestamp", -1));
$instances = $request->getParam("instances", array());
list($startsDT, $endsDT) = $this->getStartEnd();
list($startsDT, $endsDT) = Application_Common_HTTPHelper::getStartEndFromRequest($request);
$opts = array("myShows" => $my_shows, "showFilter" => $show_filter);
$showBuilder = new Application_Model_ShowBuilder($startsDT, $endsDT, $opts);
@ -315,7 +272,7 @@ class ShowbuilderController extends Zend_Controller_Action
$show_instance_filter = intval($request->getParam("showInstanceFilter", 0));
$my_shows = intval($request->getParam("myShows", 0));
list($startsDT, $endsDT) = $this->getStartEnd();
list($startsDT, $endsDT) = Application_Common_HTTPHelper::getStartEndFromRequest($request);
$opts = array("myShows" => $my_shows,
"showFilter" => $show_filter,