CC-5450 : Refactor Media Management
redone webstreams, will come back to do finishing touches for error handling after a bit more generic work on media.
This commit is contained in:
parent
b0901abbf7
commit
f55e8327d2
|
@ -31,105 +31,37 @@ class WebstreamController extends Zend_Controller_Action
|
|||
|
||||
$this->view->action = "new";
|
||||
$this->view->html = $form->render();
|
||||
|
||||
/*
|
||||
$userInfo = Zend_Auth::getInstance()->getStorage()->read();
|
||||
if (!$this->isAuthorized(-1)) {
|
||||
// TODO: this header call does not actually print any error message
|
||||
header("Status: 401 Not Authorized");
|
||||
return;
|
||||
}
|
||||
|
||||
$webstream = new CcWebstream();
|
||||
|
||||
//we're not saving this primary key in the DB so it's OK to be -1
|
||||
$webstream->setDbId(-1);
|
||||
$webstream->setDbName(_("Untitled Webstream"));
|
||||
$webstream->setDbDescription("");
|
||||
$webstream->setDbUrl("http://");
|
||||
$webstream->setDbLength("00:30:00");
|
||||
$webstream->setDbName(_("Untitled Webstream"));
|
||||
$webstream->setDbCreatorId($userInfo->id);
|
||||
$webstream->setDbUtime(new DateTime("now", new DateTimeZone('UTC')));
|
||||
$webstream->setDbMtime(new DateTime("now", new DateTimeZone('UTC')));
|
||||
|
||||
//clear the session in case an old playlist was open: CC-4196
|
||||
Application_Model_Library::changePlaylist(null, null);
|
||||
|
||||
$this->view->obj = new Application_Model_Webstream($webstream);
|
||||
$this->view->action = "new";
|
||||
$this->view->html = $this->view->render('webstream/webstream.phtml');
|
||||
*/
|
||||
}
|
||||
|
||||
public function editAction()
|
||||
{
|
||||
$request = $this->getRequest();
|
||||
|
||||
$id = $request->getParam("id");
|
||||
if (is_null($id)) {
|
||||
throw new Exception("Missing parameter 'id'");
|
||||
}
|
||||
|
||||
$service = new Application_Service_WebstreamService();
|
||||
$form = $service->makeWebstreamForm($id, true);
|
||||
|
||||
Application_Model_Library::changePlaylist($id, "stream");
|
||||
|
||||
$webstream = CcWebstreamQuery::create()->findPK($id);
|
||||
if ($webstream) {
|
||||
Application_Model_Library::changePlaylist($id, "stream");
|
||||
}
|
||||
$this->view->obj = new Application_Model_Webstream($webstream);
|
||||
$this->view->action = "edit";
|
||||
$this->view->html = $this->view->render('webstream/webstream.phtml');
|
||||
$this->view->html = $form->render();
|
||||
}
|
||||
|
||||
public function deleteAction()
|
||||
{
|
||||
$request = $this->getRequest();
|
||||
$id = $request->getParam("ids");
|
||||
$ids = $request->getParam("ids");
|
||||
|
||||
if (!$this->isAuthorized($id)) {
|
||||
header("Status: 401 Not Authorized");
|
||||
Application_Model_Library::changePlaylist(null, null);
|
||||
|
||||
$service = new Application_Service_WebstreamService();
|
||||
$service->deleteWebstreams($ids);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$type = "stream";
|
||||
Application_Model_Library::changePlaylist(null, $type);
|
||||
|
||||
$webstream = CcWebstreamQuery::create()->findPK($id)->delete();
|
||||
|
||||
$this->view->obj = null;
|
||||
$this->view->action = "delete";
|
||||
$this->view->html = $this->view->render('webstream/webstream.phtml');
|
||||
$this->view->html = $this->view->render('form/webstream.phtml');
|
||||
|
||||
}
|
||||
|
||||
/*TODO : make a user object be passed a parameter into this function so
|
||||
that it does not have to be fetched multiple times.*/
|
||||
public function isAuthorized($webstream_id)
|
||||
{
|
||||
$user = Application_Model_User::getCurrentUser();
|
||||
if ($user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($user->isHost()) {
|
||||
// not creating a webstream
|
||||
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();
|
||||
//only allow when webstream belongs to the DJ
|
||||
return $webstream->getDbCreatorId() == $user->getId();
|
||||
}
|
||||
/*we are creating a new stream. Don't need to check whether the
|
||||
DJ/Host owns the stream*/
|
||||
return true;
|
||||
} else {
|
||||
Logging::info( $user );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function saveAction()
|
||||
{
|
||||
$request = $this->getRequest();
|
||||
|
@ -150,42 +82,18 @@ class WebstreamController extends Zend_Controller_Action
|
|||
$values = $form->getValues();
|
||||
Logging::info($values);
|
||||
|
||||
$service->saveWebstream($values);
|
||||
$ws = $service->saveWebstream($values);
|
||||
|
||||
$this->view->statusMessage = "<div class='success'>"._("Webstream saved.")."</div>";
|
||||
$this->view->streamId = $ws->getId();
|
||||
$this->view->length = "00:05"; //$di->format("%Hh %Im");
|
||||
}
|
||||
else {
|
||||
Logging::info("form is not valid");
|
||||
|
||||
$this->view->statusMessage = "<div class='errors'>"._("Invalid form values.")."</div>";
|
||||
$this->view->streamId = -1;
|
||||
$this->view->errors = $form->getMessages();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
if (!$this->isAuthorized($id)) {
|
||||
header("Status: 401 Not Authorized");
|
||||
return;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
list($analysis, $mime, $mediaUrl, $di) = Application_Model_Webstream::analyzeFormData($parameters);
|
||||
try {
|
||||
if (Application_Model_Webstream::isValid($analysis)) {
|
||||
$streamId = Application_Model_Webstream::save($parameters, $mime, $mediaUrl, $di);
|
||||
|
||||
Application_Model_Library::changePlaylist($streamId, "stream");
|
||||
|
||||
$this->view->statusMessage = "<div class='success'>"._("Webstream saved.")."</div>";
|
||||
$this->view->streamId = $streamId;
|
||||
$this->view->length = $di->format("%Hh %Im");
|
||||
} else {
|
||||
throw new Exception("isValid returned false");
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
Logging::debug($e->getMessage());
|
||||
$this->view->statusMessage = "<div class='errors'>"._("Invalid form values.")."</div>";
|
||||
$this->view->streamId = -1;
|
||||
$this->view->analysis = $analysis;
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ class MediaItem extends BaseMediaItem
|
|||
{
|
||||
public function preInsert(PropelPDO $con = null)
|
||||
{
|
||||
//TODO, don't overwrite owner here if already set (from media monitor request)
|
||||
try {
|
||||
$service = new Application_Service_UserService();
|
||||
$this->setCcSubjs($service->getCurrentUser());
|
||||
|
@ -34,4 +35,20 @@ class MediaItem extends BaseMediaItem
|
|||
//have to return true for the insert to work.
|
||||
return true;
|
||||
}
|
||||
|
||||
public function preDelete(PropelPDO $con = null)
|
||||
{
|
||||
try {
|
||||
$service = new Application_Service_UserService();
|
||||
$user = $service->getCurrentUser();
|
||||
|
||||
//only users who are admins, PMs or owners of the media can delete the item.
|
||||
return $user->isAdminOrPM() || $user->getId() === $this->getOwnerId();
|
||||
}
|
||||
catch(Exception $e) {
|
||||
Logging::warn("Unable to get current user while trying to delete media item {$this->getId()}");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ class Application_Service_WebstreamService
|
|||
$length = $webstream->getHoursMins();
|
||||
|
||||
$formValues = array(
|
||||
"id" => $id,
|
||||
"name" => $webstream->getName(),
|
||||
"description" => $webstream->getDescription(),
|
||||
"url" => $webstream->getUrl(),
|
||||
|
@ -84,4 +85,9 @@ class Application_Service_WebstreamService
|
|||
|
||||
return $ws;
|
||||
}
|
||||
|
||||
public function deleteWebstreams($ids) {
|
||||
|
||||
WebstreamQuery::create()->findPks($ids)->delete();
|
||||
}
|
||||
}
|
|
@ -24,7 +24,7 @@
|
|||
</div>
|
||||
|
||||
<?php if (isset($form)) : ?>
|
||||
<input id="ws_id" type="hidden" value="<?php echo $form->getElement("id")->getValue() ?>"></input>
|
||||
<input id="obj_id" type="hidden" value="<?php echo $form->getElement("id")->getValue() ?>"></input>
|
||||
<input id="obj_lastMod" type="hidden" value="<?php echo "1";//$this->obj->getLastModified('U'); ?>"></input>
|
||||
<div class="status" style="display:none;"></div>
|
||||
|
||||
|
|
|
@ -784,7 +784,7 @@ var AIRTIME = (function(AIRTIME){
|
|||
|
||||
$pl.on("click", "#webstream_save", function() {
|
||||
//get all fields and POST to server
|
||||
var id = $pl.find("#ws_id").attr("value");
|
||||
var id = $pl.find("#obj_id").attr("value");
|
||||
var description = $pl.find("#ws_description").val();
|
||||
var streamurl = $pl.find("#ws_url").val();
|
||||
var hours = $pl.find("#ws_hours").val();
|
||||
|
@ -1084,16 +1084,14 @@ var AIRTIME = (function(AIRTIME){
|
|||
};
|
||||
|
||||
mod.fnWsDelete = function(wsid) {
|
||||
var url, id, lastMod;
|
||||
var url, id;
|
||||
|
||||
stopAudioPreview();
|
||||
id = (wsid === undefined) ? getId() : wsid;
|
||||
lastMod = getModified();
|
||||
type = $('#obj_type').val();
|
||||
url = baseUrl+'Webstream/delete';
|
||||
|
||||
$.post(url,
|
||||
{format: "json", ids: id, modified: lastMod, type: type},
|
||||
{format: "json", ids: id},
|
||||
function(json){
|
||||
openPlaylist(json);
|
||||
redrawLib();
|
||||
|
|
Loading…
Reference in New Issue