2010-12-07 20:19:27 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class LibraryController extends Zend_Controller_Action
|
|
|
|
{
|
|
|
|
protected $pl_sess = null;
|
2010-12-30 23:26:44 +01:00
|
|
|
protected $search_sess = null;
|
2010-12-07 20:19:27 +01:00
|
|
|
|
|
|
|
public function init()
|
|
|
|
{
|
2010-12-30 23:26:44 +01:00
|
|
|
if(!Zend_Auth::getInstance()->hasIdentity())
|
2010-12-07 20:19:27 +01:00
|
|
|
{
|
|
|
|
$this->_redirect('login/index');
|
|
|
|
}
|
|
|
|
|
|
|
|
$ajaxContext = $this->_helper->getHelper('AjaxContext');
|
|
|
|
$ajaxContext->addActionContext('contents', 'html')
|
|
|
|
->addActionContext('plupload', 'html')
|
|
|
|
->addActionContext('upload', 'json')
|
|
|
|
->addActionContext('delete', 'json')
|
2010-12-30 00:43:17 +01:00
|
|
|
->addActionContext('context-menu', 'json')
|
2010-12-07 20:19:27 +01:00
|
|
|
->initContext();
|
|
|
|
|
|
|
|
$this->pl_sess = new Zend_Session_Namespace(UI_PLAYLIST_SESSNAME);
|
2010-12-22 21:08:38 +01:00
|
|
|
$this->search_sess = new Zend_Session_Namespace("search");
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function indexAction()
|
|
|
|
{
|
2010-12-30 23:26:44 +01:00
|
|
|
$this->view->headScript()->appendFile('/js/campcaster/onready/library.js','text/javascript');
|
2010-12-30 00:43:17 +01:00
|
|
|
$this->view->headScript()->appendFile('/js/contextmenu/jjmenu.js','text/javascript');
|
|
|
|
$this->view->headLink()->appendStylesheet('/css/contextmenu.css');
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2010-12-22 05:33:58 +01:00
|
|
|
$this->_helper->layout->setLayout('library');
|
|
|
|
|
2011-01-03 19:29:57 +01:00
|
|
|
unset($this->search_sess->page);
|
2010-12-22 21:08:38 +01:00
|
|
|
unset($this->search_sess->md);
|
2011-01-03 17:47:21 +01:00
|
|
|
|
2010-12-22 05:33:58 +01:00
|
|
|
$this->_helper->actionStack('contents', 'library');
|
|
|
|
$this->_helper->actionStack('index', 'sideplaylist');
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function contextMenuAction()
|
|
|
|
{
|
2010-12-30 23:26:44 +01:00
|
|
|
$id = $this->_getParam('id');
|
2010-12-30 00:43:17 +01:00
|
|
|
$type = $this->_getParam('type');
|
2010-12-22 05:33:58 +01:00
|
|
|
|
2010-12-30 00:43:17 +01:00
|
|
|
$params = '/format/json/id/#id#/type/#type#';
|
2010-12-22 05:33:58 +01:00
|
|
|
|
2010-12-07 20:19:27 +01:00
|
|
|
$pl_sess = $this->pl_sess;
|
|
|
|
|
2010-12-30 00:43:17 +01:00
|
|
|
if($type === "au") {
|
|
|
|
|
2010-12-30 19:32:59 +01:00
|
|
|
$menu[] = array('action' => array('type' => 'ajax', 'url' => '/Library/delete'.$params, 'callback' => 'window["deleteAudioClip"]'),
|
|
|
|
'title' => 'Delete');
|
2010-12-30 00:43:17 +01:00
|
|
|
|
2010-12-30 19:32:59 +01:00
|
|
|
if(isset($pl_sess->id)) {
|
|
|
|
$menu[] = array('action' => array('type' => 'ajax', 'url' => '/Playlist/add-item'.$params, 'callback' => 'window["setSPLContent"]'),
|
|
|
|
'title' => 'Add to Playlist');
|
|
|
|
}
|
2010-12-30 00:43:17 +01:00
|
|
|
|
2010-12-30 23:26:44 +01:00
|
|
|
$menu[] = array('action' => array('type' => 'gourl', 'url' => '/Library/edit-file-md/id/#id#'),
|
2011-01-03 17:47:21 +01:00
|
|
|
'title' => 'Edit Metadata');
|
2010-12-30 23:26:44 +01:00
|
|
|
|
2010-12-30 00:43:17 +01:00
|
|
|
}
|
|
|
|
else if($type === "pl") {
|
|
|
|
|
2010-12-30 19:32:59 +01:00
|
|
|
if(!isset($pl_sess->id) || $pl_sess->id !== $id) {
|
|
|
|
$menu[] = array('action' =>
|
|
|
|
array('type' => 'ajax',
|
|
|
|
'url' => '/Playlist/edit/view/spl'.$params,
|
|
|
|
'callback' => 'window["openDiffSPL"]'),
|
|
|
|
'title' => 'Edit');
|
|
|
|
}
|
2010-12-30 20:29:15 +01:00
|
|
|
else if(isset($pl_sess->id) && $pl_sess->id === $id) {
|
|
|
|
$menu[] = array('action' =>
|
|
|
|
array('type' => 'ajax',
|
|
|
|
'url' => '/Playlist/close/view/spl'.$params,
|
|
|
|
'callback' => 'window["noOpenPL"]'),
|
|
|
|
'title' => 'Close');
|
|
|
|
}
|
2010-12-30 00:43:17 +01:00
|
|
|
|
2010-12-30 21:10:05 +01:00
|
|
|
$menu[] = array('action' => array('type' => 'gourl', 'url' => '/Playlist/metadata'.$params),
|
|
|
|
'title' => 'Description');
|
|
|
|
|
|
|
|
$menu[] = array('action' => array('type' => 'ajax', 'url' => '/Playlist/delete'.$params, 'callback' => 'window["deletePlaylist"]'),
|
|
|
|
'title' => 'Delete');
|
|
|
|
|
2010-12-30 00:43:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//returns format jjmenu is looking for.
|
|
|
|
die(json_encode($menu));
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function deleteAction()
|
|
|
|
{
|
|
|
|
$id = $this->_getParam('id');
|
2010-12-30 23:26:44 +01:00
|
|
|
|
2010-12-07 20:19:27 +01:00
|
|
|
if (!is_null($id)) {
|
|
|
|
$file = StoredFile::Recall($id);
|
|
|
|
|
|
|
|
if (PEAR::isError($file)) {
|
2010-12-21 22:45:36 +01:00
|
|
|
$this->view->message = $file->getMessage();
|
|
|
|
return;
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
else if(is_null($file)) {
|
2010-12-30 00:43:17 +01:00
|
|
|
$this->view->message = "file doesn't exist";
|
2010-12-21 22:45:36 +01:00
|
|
|
return;
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$res = $file->delete();
|
|
|
|
|
|
|
|
if (PEAR::isError($res)) {
|
2010-12-21 22:45:36 +01:00
|
|
|
$this->view->message = $res->getMessage();
|
|
|
|
return;
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
}
|
2010-12-30 19:32:59 +01:00
|
|
|
|
|
|
|
$this->view->id = $id;
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function contentsAction()
|
|
|
|
{
|
2010-12-30 23:26:44 +01:00
|
|
|
$this->view->headScript()->appendFile('/js/campcaster/library/library.js','text/javascript');
|
|
|
|
|
2010-12-22 05:33:58 +01:00
|
|
|
$this->_helper->viewRenderer->setResponseSegment('library');
|
|
|
|
|
2011-01-03 17:47:21 +01:00
|
|
|
$cat = $this->_getParam('ob', null);
|
|
|
|
$or = $this->_getParam('order', null);
|
|
|
|
$page = $this->_getParam('page', null);
|
|
|
|
|
|
|
|
if(!is_null($cat) && !is_null($or)) {
|
|
|
|
$order["category"] = $cat;
|
|
|
|
$order["order"] = $or;
|
|
|
|
$this->search_sess->order = $order;
|
|
|
|
}
|
|
|
|
else if(isset($this->search_sess->order)){
|
|
|
|
$order = $this->search_sess->order;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
$order = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($this->search_sess->page)) {
|
|
|
|
$last_page = $this->search_sess->page;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
$last_page = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$currpage = isset($page) ? $page : $last_page;
|
|
|
|
$this->search_sess->page = $currpage;
|
2010-12-22 05:56:14 +01:00
|
|
|
|
2010-12-22 21:08:38 +01:00
|
|
|
$md = isset($this->search_sess->md) ? $this->search_sess->md : array();
|
|
|
|
|
2011-01-03 17:47:21 +01:00
|
|
|
$count = StoredFile::searchFiles($md, $order, true);
|
|
|
|
|
|
|
|
$paginator = new Zend_Paginator(new Zend_Paginator_Adapter_Null($count));
|
|
|
|
$paginator->setCurrentPageNumber($currpage);
|
|
|
|
$this->view->paginator = $paginator;
|
|
|
|
$this->view->files = StoredFile::searchFiles($md, $order, false, $paginator->getCurrentPageNumber(), $paginator->getItemCountPerPage());
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
2010-12-30 23:26:44 +01:00
|
|
|
public function editFileMdAction()
|
2010-12-07 20:19:27 +01:00
|
|
|
{
|
2010-12-30 23:26:44 +01:00
|
|
|
$request = $this->getRequest();
|
|
|
|
$form = new Application_Form_EditAudioMD();
|
|
|
|
|
|
|
|
$file_id = $this->_getParam('id', null);
|
|
|
|
|
|
|
|
$file = StoredFile::Recall($file_id);
|
|
|
|
$form->populate($file->md);
|
|
|
|
|
|
|
|
if ($request->isPost()) {
|
|
|
|
if ($form->isValid($request->getPost())) {
|
|
|
|
|
|
|
|
$formdata = $form->getValues();
|
|
|
|
$file->replaceDbMetadata($formdata);
|
|
|
|
|
|
|
|
$this->_helper->redirector('index');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->view->form = $form;
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-12-30 23:26:44 +01:00
|
|
|
|
|
|
|
|