Merge branch 'devel' into mediamonitor2

Conflicts:
	python_apps/api_clients/api_client.py
This commit is contained in:
Rudi Grinberg 2012-07-16 17:41:36 -04:00
commit 20e32b98ba
31 changed files with 253 additions and 143 deletions

View file

@ -90,12 +90,7 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
$userType = "";
}
$view->headScript()->appendScript("var userType = '$userType';");
if (Application_Model_Preference::GetPlanLevel() != "disabled"
&& !($_SERVER['REQUEST_URI'] == '/Dashboard/stream-player' || $_SERVER['REQUEST_URI'] == '/audiopreview/audio-preview-player')) {
$client_id = Application_Model_Preference::GetClientId();
$view->headScript()->appendScript("var livechat_client_id = '$client_id';");
$view->headScript()->appendFile($baseUrl . '/js/airtime/common/livechat.js?'.$CC_CONFIG['airtime_version'], 'text/javascript');
}
if(isset($CC_CONFIG['demo']) && $CC_CONFIG['demo'] == 1){
$view->headScript()->appendFile($baseUrl.'/js/libs/google-analytics.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
}

View file

@ -2,7 +2,7 @@
define('AIRTIME_COPYRIGHT_DATE', '2010-2012');
define('AIRTIME_REST_VERSION', '1.1');
define('AIRTIME_API_VERSION', '1.0');
define('AIRTIME_API_VERSION', '1.1');
// Metadata Keys for files
define('MDATA_KEY_FILEPATH', 'filepath');

View file

@ -262,30 +262,28 @@ class ApiController extends Zend_Controller_Action
$request = $this->getRequest();
$type = $request->getParam('type');
if ($type == "endofday") {
// make getNextShows use end of day
$limit = $request->getParam('limit');
if($limit == "" || !is_numeric($limit)) {
$limit = "5";
}
// make GetNextShows use end of day
$utcTimeEnd = Application_Common_DateHelper::GetDayEndTimestampInUtc();
$result = array("env"=>APPLICATION_ENV,
"schedulerTime"=>gmdate("Y-m-d H:i:s"),
"nextShow"=>Application_Model_Show::getNextShows($utcTimeNow, 5, $utcTimeEnd));
"nextShow"=>Application_Model_Show::getNextShows($utcTimeNow, $limit, $utcTimeEnd));
Application_Model_Show::convertToLocalTimeZone($result["nextShow"], array("starts", "ends", "start_timestamp", "end_timestamp"));
} else {
$limit = $request->getParam('limit');
if ($limit == "" || !is_numeric($limit)) {
$limit = "5";
}
$result = Application_Model_Schedule::GetPlayOrderRange();
//Convert from UTC to localtime for user.
//Convert from UTC to localtime for Web Browser.
Application_Model_Show::convertToLocalTimeZone($result["currentShow"], array("starts", "ends", "start_timestamp", "end_timestamp"));
Application_Model_Show::convertToLocalTimeZone($result["nextShow"], array("starts", "ends", "start_timestamp", "end_timestamp"));
}
$result['AIRTIME_API_VERSION'] = AIRTIME_API_VERSION; //used by caller to determine if the airtime they are running or widgets in use is out of date.
//echo json_encode($result);
header("Content-type: text/javascript");
echo $_GET['callback'].'('.json_encode($result).')';
} else {

View file

@ -125,28 +125,11 @@ class LibraryController extends Zend_Controller_Action
}
}
$hasPermission = true;
if (count($playlists)) {
// make sure use has permission to delete all playslists in the list
if (!$isAdminOrPM) {
foreach ($playlists as $pid) {
$pl = new Application_Model_Playlist($pid);
if ($pl->getCreatorId() != $user->getId()) {
$hasPermission = false;
}
}
}
}
if (!$isAdminOrPM && count($files)) {
$hasPermission = false;
}
if (!$hasPermission) {
$this->view->message = "You don't have a permission to delete all playlists/files that are selected.";
try {
Application_Model_Playlist::deletePlaylists($playlists, $user->getId());
} catch (PlaylistNoPermissionException $e) {
$this->view->message = "You don't have permission to delete selected playlists/files.";
return;
} else {
Application_Model_Playlist::DeletePlaylists($playlists);
}
foreach ($files as $id) {

View file

@ -82,7 +82,7 @@ class PlaylistController extends Zend_Controller_Action
}
}
private function playlistOutdated($pl, $e)
private function playlistOutdated($e)
{
$this->view->error = $e->getMessage();
}
@ -95,6 +95,10 @@ class PlaylistController extends Zend_Controller_Action
$this->changePlaylist(null);
$this->createFullResponse(null);
}
private function playlistNoPermission(){
$this->view->error = "You don't have permission to delete selected playlist(s).";
}
private function playlistUnknownError($e)
{
@ -137,7 +141,13 @@ class PlaylistController extends Zend_Controller_Action
try {
if (isset($this->pl_sess->id)) {
$pl = new Application_Model_Playlist($this->pl_sess->id);
$this->view->pl = $pl;
$userInfo = Zend_Auth::getInstance()->getStorage()->read();
$user = new Application_Model_User($userInfo->id);
$isAdminOrPM = $user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER));
if($isAdminOrPM || $pl->getCreatorId() == $userInfo->id){
$this->view->pl = $pl;
}
$formatter = new LengthFormatter($pl->getLength());
$this->view->length = $formatter->format();
@ -186,6 +196,9 @@ class PlaylistController extends Zend_Controller_Action
$ids = $this->_getParam('ids');
$ids = (!is_array($ids)) ? array($ids) : $ids;
$pl = null;
$userInfo = Zend_Auth::getInstance()->getStorage()->read();
$user = new Application_Model_User($userInfo->id);
try {
@ -198,9 +211,13 @@ class PlaylistController extends Zend_Controller_Action
$pl = new Application_Model_Playlist($this->pl_sess->id);
}
Application_Model_Playlist::DeletePlaylists($ids);
Application_Model_Playlist::deletePlaylists($ids, $userInfo->id);
$this->createFullResponse($pl);
} catch (PlaylistNotFoundException $e) {
}
catch (PlaylistNoPermissionException $e) {
$this->playlistNoPermission();
}
catch (PlaylistNotFoundException $e) {
$this->playlistNotFound();
} catch (Exception $e) {
$this->playlistUnknownError($e);
@ -219,7 +236,7 @@ class PlaylistController extends Zend_Controller_Action
$pl->addAudioClips($ids, $afterItem, $addType);
$this->createUpdateResponse($pl);
} catch (PlaylistOutDatedException $e) {
$this->playlistOutdated($pl, $e);
$this->playlistOutdated($e);
} catch (PlaylistNotFoundException $e) {
$this->playlistNotFound();
} catch (Exception $e) {
@ -239,7 +256,7 @@ class PlaylistController extends Zend_Controller_Action
$pl->moveAudioClips($ids, $afterItem);
$this->createUpdateResponse($pl);
} catch (PlaylistOutDatedException $e) {
$this->playlistOutdated($pl, $e);
$this->playlistOutdated($e);
} catch (PlaylistNotFoundException $e) {
$this->playlistNotFound();
} catch (Exception $e) {
@ -258,7 +275,7 @@ class PlaylistController extends Zend_Controller_Action
$pl->delAudioClips($ids);
$this->createUpdateResponse($pl);
} catch (PlaylistOutDatedException $e) {
$this->playlistOutdated($pl, $e);
$this->playlistOutdated($e);
} catch (PlaylistNotFoundException $e) {
$this->playlistNotFound();
} catch (Exception $e) {
@ -283,7 +300,7 @@ class PlaylistController extends Zend_Controller_Action
$this->view->cue_error = $response["error"];
}
} catch (PlaylistOutDatedException $e) {
$this->playlistOutdated($pl, $e);
$this->playlistOutdated($e);
} catch (PlaylistNotFoundException $e) {
$this->playlistNotFound();
} catch (Exception $e) {
@ -308,7 +325,7 @@ class PlaylistController extends Zend_Controller_Action
$this->view->fade_error = $response["error"];
}
} catch (PlaylistOutDatedException $e) {
$this->playlistOutdated($pl, $e);
$this->playlistOutdated($e);
} catch (PlaylistNotFoundException $e) {
$this->playlistNotFound();
} catch (Exception $e) {
@ -326,7 +343,7 @@ class PlaylistController extends Zend_Controller_Action
$fades = $pl->getFadeInfo($pl->getSize()-1);
$this->view->fadeOut = $fades[1];
} catch (PlaylistOutDatedException $e) {
$this->playlistOutdated($pl, $e);
$this->playlistOutdated($e);
} catch (PlaylistNotFoundException $e) {
$this->playlistNotFound();
} catch (Exception $e) {
@ -349,7 +366,7 @@ class PlaylistController extends Zend_Controller_Action
$pl->setPlaylistfades($fadeIn, $fadeOut);
$this->view->modified = $pl->getLastModified("U");
} catch (PlaylistOutDatedException $e) {
$this->playlistOutdated($pl, $e);
$this->playlistOutdated($e);
} catch (PlaylistNotFoundException $e) {
$this->playlistNotFound();
} catch (Exception $e) {
@ -367,7 +384,7 @@ class PlaylistController extends Zend_Controller_Action
$this->view->playlistName = $name;
$this->view->modified = $pl->getLastModified("U");
} catch (PlaylistOutDatedException $e) {
$this->playlistOutdated($pl, $e);
$this->playlistOutdated($e);
} catch (PlaylistNotFoundException $e) {
$this->playlistNotFound();
} catch (Exception $e) {
@ -385,7 +402,7 @@ class PlaylistController extends Zend_Controller_Action
$this->view->description = $pl->getDescription();
$this->view->modified = $pl->getLastModified("U");
} catch (PlaylistOutDatedException $e) {
$this->playlistOutdated($pl, $e);
$this->playlistOutdated($e);
} catch (PlaylistNotFoundException $e) {
$this->playlistNotFound();
} catch (Exception $e) {

View file

@ -453,13 +453,14 @@ class Application_Model_Playlist
->filterByDbPlaylistId($this->id)
->filterByDbPosition($pos)
->findOne();
#Propel returns values in form 00.000000 format which is for only seconds.
$fadeIn = $row->getDbFadein();
$fadeOut = $row->getDbFadeout();
return array($fadeIn, $fadeOut);
}
#Propel returns values in form 00.000000 format which is for only seconds.
$fadeIn = $row->getDbFadein();
$fadeOut = $row->getDbFadeout();
return array($fadeIn, $fadeOut);
}
/**
* Change fadeIn and fadeOut values for playlist Element
@ -800,12 +801,33 @@ class Application_Model_Playlist
* Delete playlists that match the ids..
* @param array $p_ids
*/
public static function DeletePlaylists($p_ids)
public static function deletePlaylists($p_ids, $p_userId)
{
CcPlaylistQuery::create()->findPKs($p_ids)->delete();
$leftOver = self::playlistsNotOwnedByUser($p_ids, $p_userId);
if (count($leftOver) == 0) {
CcPlaylistQuery::create()->findPKs($p_ids)->delete();
} else {
throw new PlaylistNoPermissionException;
}
}
// This function returns that are not owen by $p_user_id among $p_ids
private static function playlistsNotOwnedByUser($p_ids, $p_userId){
$ownedByUser = CcPlaylistQuery::create()->filterByDbCreatorId($p_userId)->find()->getData();
$selectedPls = $p_ids;
$ownedPls = array();
foreach ($ownedByUser as $pl) {
if (in_array($pl->getDbId(), $selectedPls)) {
$ownedPls[] = $pl->getDbId();
}
}
$leftOvers = array_diff($selectedPls, $ownedPls);
return $leftOvers;
}
} // class Playlist
class PlaylistNotFoundException extends Exception {}
class PlaylistNoPermissionException extends Exception {}
class PlaylistOutDatedException extends Exception {}

View file

@ -32,6 +32,7 @@ class Application_Model_Schedule
{
if (!is_int($p_prev) || !is_int($p_next)) {
//must enter integers to specify ranges
Logging::log("Invalid range parameters: $p_prev or $p_next");
return array();
}
@ -49,7 +50,6 @@ class Application_Model_Schedule
"schedulerTime"=>$timeNow,
"previous"=>$results['previous'] !=null?$results['previous']:(count($shows['previousShow'])>0?$shows['previousShow'][0]:null),
"current"=>$results['current'] !=null?$results['current']:((count($shows['currentShow'])>0 && $shows['currentShow'][0]['record'] == 1)?$shows['currentShow'][0]:null),
//"current"=>$results['current'] !=null?$results['current']:(count($shows['currentShow'])>0?$shows['currentShow'][0]:null),
"next"=> $results['next'] !=null?$results['next']:(count($shows['nextShow'])>0?$shows['nextShow'][0]:null),
"currentShow"=>$shows['currentShow'],
"nextShow"=>$shows['nextShow'],

View file

@ -1876,9 +1876,9 @@ class Application_Model_Show
/**
* Given a start time $timeStart and end time $timeEnd, returns the next $limit
* number of shows within the time interval;
* If $timeEnd not given, shows within next 48 hours from $timeStart are returned;
* If $limit not given, all shows within the intervals are returns;
* number of shows within the time interval
* If $timeEnd not given, shows within next 48 hours from $timeStart are returned
* If $limit not given, all shows within the intervals are returned
* Times are all in UTC time.
*
* @param String $timeStart - interval start time (in UTC)