Merge branch 'devel' of dev.sourcefabric.org:airtime into devel
This commit is contained in:
commit
e7689e5355
|
@ -7,9 +7,6 @@ require_once 'formatters/BitrateFormatter.php';
|
|||
class LibraryController extends Zend_Controller_Action
|
||||
{
|
||||
|
||||
protected $obj_sess = null;
|
||||
protected $search_sess = null;
|
||||
|
||||
public function init()
|
||||
{
|
||||
$ajaxContext = $this->_helper->getHelper('AjaxContext');
|
||||
|
@ -23,8 +20,6 @@ class LibraryController extends Zend_Controller_Action
|
|||
->addActionContext('set-num-entries', 'json')
|
||||
->initContext();
|
||||
|
||||
$this->obj_sess = new Zend_Session_Namespace(UI_PLAYLISTCONTROLLER_OBJ_SESSNAME);
|
||||
$this->search_sess = new Zend_Session_Namespace("search");
|
||||
}
|
||||
|
||||
public function indexAction()
|
||||
|
@ -59,32 +54,90 @@ class LibraryController extends Zend_Controller_Action
|
|||
|
||||
try {
|
||||
|
||||
if (isset($this->obj_sess->id)) {
|
||||
Logging::info($this->obj_sess->type);
|
||||
$obj_sess = new Zend_Session_Namespace(UI_PLAYLISTCONTROLLER_OBJ_SESSNAME);
|
||||
//Application_Model_Library::changePlaylist(null, null);
|
||||
if (isset($obj_sess->id)) {
|
||||
Logging::info($obj_sess->type);
|
||||
$objInfo = Application_Model_Library::getObjInfo($this->obj_sess->type);
|
||||
Logging::info($this->obj_sess->id);
|
||||
$obj = new $objInfo['className']($this->obj_sess->id);
|
||||
Logging::info($obj_sess->id);
|
||||
$obj = new $objInfo['className']($obj_sess->id);
|
||||
$userInfo = Zend_Auth::getInstance()->getStorage()->read();
|
||||
$user = new Application_Model_User($userInfo->id);
|
||||
$isAdminOrPM = $user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER));
|
||||
|
||||
if ($isAdminOrPM || $obj->getCreatorId() == $userInfo->id) {
|
||||
$this->view->obj = $obj;
|
||||
if ($this->obj_sess->type == "block") {
|
||||
if ($obj_sess->type == "block") {
|
||||
$form = new Application_Form_SmartBlockCriteria();
|
||||
$form->startForm($this->obj_sess->id);
|
||||
$form->startForm($obj_sess->id);
|
||||
$this->view->form = $form;
|
||||
}
|
||||
}
|
||||
|
||||
$formatter = new LengthFormatter($obj->getLength());
|
||||
$this->view->length = $formatter->format();
|
||||
$this->view->type = $this->obj_sess->type;
|
||||
$this->view->type = $obj_sess->type;
|
||||
}
|
||||
} catch (PlaylistNotFoundException $e) {
|
||||
$this->playlistNotFound($this->obj_sess->type);
|
||||
$this->playlistNotFound($obj_sess->type);
|
||||
} catch (Exception $e) {
|
||||
$this->playlistUnknownError($e);
|
||||
$this->playlistNotFound($obj_sess->type);
|
||||
//$this->playlistUnknownError($e);
|
||||
}
|
||||
}
|
||||
|
||||
protected function playlistNotFound($p_type)
|
||||
{
|
||||
$this->view->error = "{$p_type} not found";
|
||||
|
||||
Logging::info("{$p_type} not found");
|
||||
Application_Model_Library::changePlaylist(null, $p_type);
|
||||
$this->createFullResponse(null);
|
||||
}
|
||||
|
||||
protected function playlistUnknownError($e)
|
||||
{
|
||||
$this->view->error = "Something went wrong.";
|
||||
|
||||
Logging::info("{$e->getFile()}");
|
||||
Logging::info("{$e->getLine()}");
|
||||
Logging::info("{$e->getMessage()}");
|
||||
}
|
||||
|
||||
protected function createFullResponse($obj = null, $isJson = false)
|
||||
{
|
||||
$isBlock = false;
|
||||
$viewPath = 'playlist/playlist.phtml';
|
||||
if ($obj instanceof Application_Model_Block) {
|
||||
$isBlock = true;
|
||||
$viewPath = 'playlist/smart-block.phtml';
|
||||
}
|
||||
|
||||
if (isset($obj)) {
|
||||
$formatter = new LengthFormatter($obj->getLength());
|
||||
$this->view->length = $formatter->format();
|
||||
|
||||
if ($isBlock) {
|
||||
$form = new Application_Form_SmartBlockCriteria();
|
||||
$form->removeDecorator('DtDdWrapper');
|
||||
$form->startForm($obj->getId());
|
||||
|
||||
$this->view->form = $form;
|
||||
$this->view->obj = $obj;
|
||||
$this->view->id = $obj->getId();
|
||||
if ($isJson) {
|
||||
return $this->view->render($viewPath);
|
||||
} else {
|
||||
$this->view->html = $this->view->render($viewPath);
|
||||
}
|
||||
} else {
|
||||
$this->view->obj = $obj;
|
||||
$this->view->id = $obj->getId();
|
||||
$this->view->html = $this->view->render($viewPath);
|
||||
unset($this->view->obj);
|
||||
}
|
||||
} else {
|
||||
$this->view->html = $this->view->render($viewPath);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -111,17 +164,18 @@ class LibraryController extends Zend_Controller_Action
|
|||
|
||||
$file = Application_Model_StoredFile::Recall($id);
|
||||
|
||||
if (isset($this->obj_sess->id) && $screen == "playlist") {
|
||||
$obj_sess = new Zend_Session_Namespace(UI_PLAYLISTCONTROLLER_OBJ_SESSNAME);
|
||||
if (isset($obj_sess->id) && $screen == "playlist") {
|
||||
// if the user is not admin or pm, check the creator and see if this person owns the playlist or Block
|
||||
if ($this->obj_sess->type == 'playlist') {
|
||||
$obj = new Application_Model_Playlist($this->obj_sess->id);
|
||||
if ($obj_sess->type == 'playlist') {
|
||||
$obj = new Application_Model_Playlist($obj_sess->id);
|
||||
} else {
|
||||
$obj = new Application_Model_Block($this->obj_sess->id);
|
||||
$obj = new Application_Model_Block($obj_sess->id);
|
||||
}
|
||||
if ($isAdminOrPM || $obj->getCreatorId() == $user->getId()) {
|
||||
if ($this->obj_sess->type === "playlist") {
|
||||
if ($obj_sess->type === "playlist") {
|
||||
$menu["pl_add"] = array("name"=> "Add to Playlist", "icon" => "add-playlist", "icon" => "copy");
|
||||
} else if ($this->obj_sess->type === "block") {
|
||||
} else if ($obj_sess->type === "block") {
|
||||
$menu["pl_add"] = array("name"=> "Add to Smart Block", "icon" => "add-playlist", "icon" => "copy");
|
||||
}
|
||||
}
|
||||
|
@ -142,13 +196,13 @@ class LibraryController extends Zend_Controller_Action
|
|||
unset($menu["play"]);
|
||||
}
|
||||
if (($isAdminOrPM || $obj->getCreatorId() == $user->getId()) && $screen == "playlist") {
|
||||
if ($this->obj_sess->type === "playlist") {
|
||||
if ($obj_sess->type === "playlist") {
|
||||
$menu["pl_add"] = array("name"=> "Add to Playlist", "icon" => "add-playlist", "icon" => "copy");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->obj_sess->id !== $id && $screen == "playlist") {
|
||||
if ($obj_sess->id !== $id && $screen == "playlist") {
|
||||
if ($isAdminOrPM || $obj->getCreatorId() == $user->getId()) {
|
||||
$menu["edit"] = array("name"=> "Edit", "icon" => "edit");
|
||||
}
|
||||
|
@ -160,9 +214,9 @@ class LibraryController extends Zend_Controller_Action
|
|||
|
||||
$webstream = CcWebstreamQuery::create()->findPK($id);
|
||||
$obj = new Application_Model_Webstream($webstream);
|
||||
if (isset($this->obj_sess->id) && $screen == "playlist") {
|
||||
if (isset($obj_sess->id) && $screen == "playlist") {
|
||||
if ($isAdminOrPM || $obj->getCreatorId() == $user->getId()) {
|
||||
if ($this->obj_sess->type === "playlist") {
|
||||
if ($obj_sess->type === "playlist") {
|
||||
$menu["pl_add"] = array("name"=> "Add to Playlist", "icon" => "add-playlist", "icon" => "copy");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
class PlaylistController extends Zend_Controller_Action
|
||||
{
|
||||
protected $obj_sess = null;
|
||||
|
||||
public function init()
|
||||
{
|
||||
|
@ -28,7 +27,6 @@ class PlaylistController extends Zend_Controller_Action
|
|||
->addActionContext('get-block-info', 'json')
|
||||
->initContext();
|
||||
|
||||
$this->obj_sess = new Zend_Session_Namespace(UI_PLAYLISTCONTROLLER_OBJ_SESSNAME);
|
||||
}
|
||||
|
||||
private function getPlaylist($p_type)
|
||||
|
@ -36,8 +34,9 @@ class PlaylistController extends Zend_Controller_Action
|
|||
$obj = null;
|
||||
$objInfo = Application_Model_Library::getObjInfo($p_type);
|
||||
|
||||
if (isset($this->obj_sess->id)) {
|
||||
$obj = new $objInfo['className']($this->obj_sess->id);
|
||||
$obj_sess = new Zend_Session_Namespace(UI_PLAYLISTCONTROLLER_OBJ_SESSNAME);
|
||||
if (isset($obj_sess->id)) {
|
||||
$obj = new $objInfo['className']($obj_sess->id);
|
||||
|
||||
$modified = $this->_getParam('modified', null);
|
||||
if ($obj->getLastModified("U") !== $modified) {
|
||||
|
@ -205,14 +204,17 @@ class PlaylistController extends Zend_Controller_Action
|
|||
$userInfo = Zend_Auth::getInstance()->getStorage()->read();
|
||||
$user = new Application_Model_User($userInfo->id);
|
||||
|
||||
|
||||
$obj_sess = new Zend_Session_Namespace(UI_PLAYLISTCONTROLLER_OBJ_SESSNAME);
|
||||
|
||||
try {
|
||||
Logging::info("Currently active {$type} {$this->obj_sess->id}");
|
||||
if (in_array($this->obj_sess->id, $ids)) {
|
||||
Logging::info("Currently active {$type} {$obj_sess->id}");
|
||||
if (in_array($obj_sess->id, $ids)) {
|
||||
Logging::info("Deleting currently active {$type}");
|
||||
Application_Model_Library::changePlaylist(null, $type);
|
||||
} else {
|
||||
Logging::info("Not deleting currently active {$type}");
|
||||
$obj = new $objInfo['className']($this->obj_sess->id);
|
||||
$obj = new $objInfo['className']($obj_sess->id);
|
||||
}
|
||||
|
||||
if (strcmp($objInfo['className'], 'Application_Model_Playlist')==0) {
|
||||
|
|
|
@ -238,7 +238,7 @@ class ScheduleController extends Zend_Controller_Action
|
|||
}
|
||||
|
||||
$isAdminOrPM = $user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER));
|
||||
$isDJ = $user->isHost($instance->getShowId());
|
||||
$isDJ = $user->isHostOfShow($instance->getShowId());
|
||||
|
||||
$showStartLocalDT = Application_Common_DateHelper::ConvertToLocalDateTime($instance->getShowInstanceStart());
|
||||
$showEndLocalDT = Application_Common_DateHelper::ConvertToLocalDateTime($instance->getShowInstanceEnd());
|
||||
|
@ -338,7 +338,7 @@ class ScheduleController extends Zend_Controller_Action
|
|||
return false;
|
||||
}
|
||||
|
||||
if($user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER, UTYPE_HOST),$show->getShowId()))
|
||||
if($user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER) && $user->isHostOfShow($show->getShowId())))
|
||||
$show->clearShow();
|
||||
}
|
||||
|
||||
|
@ -403,7 +403,7 @@ class ScheduleController extends Zend_Controller_Action
|
|||
return false;
|
||||
}
|
||||
|
||||
if ($user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER, UTYPE_HOST),$show->getShowId())) {
|
||||
if ($user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER) && $user->isHostOfShow($show->getShowId()))) {
|
||||
$show->removeGroupFromShow($group_id);
|
||||
}
|
||||
|
||||
|
@ -543,7 +543,7 @@ class ScheduleController extends Zend_Controller_Action
|
|||
}
|
||||
|
||||
$isAdminOrPM = $user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER));
|
||||
$isDJ = $user->isHost($showInstance->getShowId());
|
||||
$isDJ = $user->isHostOfShow($showInstance->getShowId());
|
||||
|
||||
if (!($isAdminOrPM || $isDJ)) {
|
||||
return;
|
||||
|
|
|
@ -16,10 +16,15 @@ class WebstreamController extends Zend_Controller_Action
|
|||
{
|
||||
|
||||
$userInfo = Zend_Auth::getInstance()->getStorage()->read();
|
||||
if (!$this->isAuthorized(-1)) {
|
||||
header("Status: 401 Not Authorized");
|
||||
return;
|
||||
}
|
||||
|
||||
$webstream = new CcWebstream();
|
||||
|
||||
//we're not saving this primary key in the DB so it's OK
|
||||
//$webstream->setDbId(-1);
|
||||
$webstream->setDbId(-1);
|
||||
$webstream->setDbName("Untitled Webstream");
|
||||
$webstream->setDbDescription("");
|
||||
$webstream->setDbUrl("http://");
|
||||
|
@ -28,8 +33,9 @@ class WebstreamController extends Zend_Controller_Action
|
|||
$webstream->setDbCreatorId($userInfo->id);
|
||||
$webstream->setDbUtime(new DateTime("now", new DateTimeZone('UTC')));
|
||||
$webstream->setDbMtime(new DateTime("now", new DateTimeZone('UTC')));
|
||||
$webstream->save();
|
||||
//$webstream->save();
|
||||
|
||||
/*
|
||||
$type = "stream";
|
||||
$objInfo = Application_Model_Library::getObjInfo($type);
|
||||
|
||||
|
@ -39,6 +45,7 @@ class WebstreamController extends Zend_Controller_Action
|
|||
|
||||
$type = "stream";
|
||||
Application_Model_Library::changePlaylist($obj->getId(), $type);
|
||||
*/
|
||||
|
||||
$this->view->obj = new Application_Model_Webstream($webstream);
|
||||
$this->view->action = "new";
|
||||
|
@ -81,7 +88,7 @@ class WebstreamController extends Zend_Controller_Action
|
|||
|
||||
}
|
||||
|
||||
public function isAuthorized($id)
|
||||
public function isAuthorized($webstream_id)
|
||||
{
|
||||
$hasPermission = false;
|
||||
$user = Application_Model_User::getCurrentUser();
|
||||
|
@ -89,15 +96,18 @@ class WebstreamController extends Zend_Controller_Action
|
|||
$hasPermission = true;
|
||||
}
|
||||
|
||||
if (!$hasPermission) {
|
||||
if ($id != -1) {
|
||||
$webstream = CcWebstreamQuery::create()->findPK($id);
|
||||
if ($user->isHost()) {
|
||||
if ($webstream_id != -1) {
|
||||
$webstream = CcWebstreamQuery::create()->findPK($webstream_id);
|
||||
//we are updating a playlist. Ensure that if the user is a host/dj, that he has the correct permission.
|
||||
$user = Application_Model_User::getCurrentUser();
|
||||
|
||||
if ($webstream->getDbCreatorId() == $user->getId()) {
|
||||
$hasPermission = true;
|
||||
}
|
||||
} else {
|
||||
//we are creating a new stream. Don't need to check whether the DJ/Host owns the stream
|
||||
$hasPermission = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -108,10 +118,6 @@ class WebstreamController extends Zend_Controller_Action
|
|||
{
|
||||
$request = $this->getRequest();
|
||||
|
||||
|
||||
$user = Application_Model_User::getCurrentUser();
|
||||
$hasPermission = $user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER, UTYPE_HOST));
|
||||
|
||||
$id = $request->getParam("id");
|
||||
|
||||
$parameters = array();
|
||||
|
@ -131,6 +137,9 @@ class WebstreamController extends Zend_Controller_Action
|
|||
try {
|
||||
if (Application_Model_Webstream::isValid($analysis)) {
|
||||
$streamId = Application_Model_Webstream::save($parameters, $mime, $di);
|
||||
|
||||
Application_Model_Library::changePlaylist($streamId, "stream");
|
||||
|
||||
$this->view->statusMessage = "<div class='success'>Webstream saved.</div>";
|
||||
$this->view->streamId = $streamId;
|
||||
} else {
|
||||
|
|
|
@ -11,5 +11,13 @@ class RabbitMqPlugin extends Zend_Controller_Plugin_Abstract
|
|||
Application_Model_RabbitMq::SendMessageToShowRecorder("update_recorder_schedule");
|
||||
}
|
||||
}
|
||||
|
||||
if (memory_get_peak_usage() > 25*pow(2, 20)) {
|
||||
|
||||
Logging::debug("Peak memory usage: "
|
||||
.(memory_get_peak_usage()/1000000)
|
||||
." MB while accessing URI ".$_SERVER['REQUEST_URI']);
|
||||
Logging::debug("Should try to keep memory footprint under 25 MB");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm
|
|||
private $criteriaOptions = array(
|
||||
0 => "Select criteria",
|
||||
"album_title" => "Album",
|
||||
"bit_rate" => "Bit Rate",
|
||||
"bit_rate" => "Bit Rate (Kbps)",
|
||||
"bpm" => "Bpm",
|
||||
"comments" => "Comments",
|
||||
"composer" => "Composer",
|
||||
|
@ -23,7 +23,7 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm
|
|||
"name" => "Name",
|
||||
"orchestra" => "Orchestra",
|
||||
"rating" => "Rating",
|
||||
"sample_rate" => "Sample Rate",
|
||||
"sample_rate" => "Sample Rate (kHz)",
|
||||
"track_title" => "Title",
|
||||
"track_number" => "Track Number",
|
||||
"utime" => "Uploaded",
|
||||
|
|
|
@ -1162,7 +1162,7 @@ EOT;
|
|||
$spCriteria = 'date('.$spCriteria.')';
|
||||
$spCriteriaValue = substr($spCriteriaValue, 0, 10);
|
||||
}
|
||||
} else if($spCriteria == "bit_rate") {
|
||||
} else if($spCriteria == "bit_rate" || $spCriteria == 'sample_rate') {
|
||||
// multiply 1000 because we store only number value
|
||||
// e.g 192kps is stored as 192000
|
||||
$spCriteriaValue = $criteria['value']*1000;
|
||||
|
@ -1177,7 +1177,7 @@ EOT;
|
|||
} else if ($spCriteriaModifier == "contains" || $spCriteriaModifier == "does not contain") {
|
||||
$spCriteriaValue = "%$spCriteriaValue%";
|
||||
} else if ($spCriteriaModifier == "is in the range") {
|
||||
$spCriteriaValue = "$spCriteria > '$spCriteriaValue' AND $spCriteria <= '$criteria[extra]'";
|
||||
$spCriteriaValue = "$spCriteria >= '$spCriteriaValue' AND $spCriteria <= '$criteria[extra]'";
|
||||
}
|
||||
|
||||
$spCriteriaModifier = self::$modifier2CriteriaMap[$spCriteriaModifier];
|
||||
|
|
|
@ -1065,10 +1065,11 @@ SQL;
|
|||
if ($update) {
|
||||
$sql = "SELECT id, starts, ends FROM ".$CC_CONFIG["showInstances"]."
|
||||
where ends <= '{$show_end->format('Y-m-d H:i:s')}'
|
||||
and id != ".$instanceId. " order by ends";
|
||||
and modified_instance = false and id != ".$instanceId. " order by ends";
|
||||
} else {
|
||||
$sql = "SELECT id, starts, ends FROM ".$CC_CONFIG["showInstances"]."
|
||||
where ends <= '{$show_end->format('Y-m-d H:i:s')}' order by ends";
|
||||
where ends <= '{$show_end->format('Y-m-d H:i:s')}'
|
||||
and modified_instance = false order by ends";
|
||||
}
|
||||
$rows = $con->query($sql);
|
||||
|
||||
|
|
|
@ -32,9 +32,17 @@ class Application_Model_User
|
|||
return $this->getType() == UTYPE_GUEST;
|
||||
}
|
||||
|
||||
public function isHostOfShow($showId)
|
||||
{
|
||||
$userId = $this->_userInstance->getDbId();
|
||||
return CcShowHostsQuery::create()
|
||||
->filterByDbShow($showId)
|
||||
->filterByDbHost($userId)->count() > 0;
|
||||
}
|
||||
|
||||
public function isHost($showId)
|
||||
{
|
||||
return $this->isUserType(UTYPE_HOST, $showId);
|
||||
return $this->isUserType(UTYPE_HOST);
|
||||
}
|
||||
|
||||
public function isPM()
|
||||
|
@ -61,7 +69,7 @@ class Application_Model_User
|
|||
return $result;
|
||||
}
|
||||
|
||||
public function isUserType($type, $showId='')
|
||||
public function isUserType($type)
|
||||
{
|
||||
if (is_array($type)) {
|
||||
$result = false;
|
||||
|
@ -71,10 +79,7 @@ class Application_Model_User
|
|||
$result = $this->_userInstance->getDbType() === 'A';
|
||||
break;
|
||||
case UTYPE_HOST:
|
||||
$userId = $this->_userInstance->getDbId();
|
||||
$result = CcShowHostsQuery::create()
|
||||
->filterByDbShow($showId)
|
||||
->filterByDbHost($userId)->count() > 0;
|
||||
$result = $this->_userInstance->getDbType() === 'H';
|
||||
break;
|
||||
case UTYPE_PROGRAM_MANAGER:
|
||||
$result = $this->_userInstance->getDbType() === 'P';
|
||||
|
@ -89,9 +94,7 @@ class Application_Model_User
|
|||
case UTYPE_ADMIN:
|
||||
return $this->_userInstance->getDbType() === 'A';
|
||||
case UTYPE_HOST:
|
||||
$userId = $this->_userInstance->getDbId();
|
||||
|
||||
return CcShowHostsQuery::create()->filterByDbShow($showId)->filterByDbHost($userId)->count() > 0;
|
||||
return $this->_userInstance->getDbId() === 'H';
|
||||
case UTYPE_PROGRAM_MANAGER:
|
||||
return $this->_userInstance->getDbType() === 'P';
|
||||
}
|
||||
|
|
|
@ -7,9 +7,11 @@ class Application_Model_Webstream implements Application_Model_LibraryEditable
|
|||
public function __construct($webstream)
|
||||
{
|
||||
//TODO: hacky...
|
||||
Logging::info("x ".$webstream);
|
||||
if (is_int($webstream)) {
|
||||
$this->webstream = CcWebstreamQuery::create()->findPK($webstream);
|
||||
if (is_null($this->webstream)) {
|
||||
throw new Exception();
|
||||
}
|
||||
} else {
|
||||
$this->webstream = $webstream;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue