libretime/application/controllers/LibraryController.php

203 lines
5.2 KiB
PHP
Raw Normal View History

<?php
class LibraryController extends Zend_Controller_Action
{
protected $pl_sess = null;
2010-12-30 23:26:44 +01:00
protected $search_sess = null;
public function init()
{
2010-12-30 23:26:44 +01:00
if(!Zend_Auth::getInstance()->hasIdentity())
{
$this->_redirect('login/index');
}
$ajaxContext = $this->_helper->getHelper('AjaxContext');
$ajaxContext->addActionContext('contents', 'html')
->addActionContext('plupload', 'html')
->addActionContext('upload', 'json')
->addActionContext('delete', 'json')
->addActionContext('context-menu', 'json')
->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");
}
public function indexAction()
{
2010-12-30 23:26:44 +01:00
$this->view->headScript()->appendFile('/js/campcaster/onready/library.js','text/javascript');
$this->view->headScript()->appendFile('/js/contextmenu/jjmenu.js','text/javascript');
$this->view->headLink()->appendStylesheet('/css/contextmenu.css');
$this->_helper->layout->setLayout('library');
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
$this->_helper->actionStack('contents', 'library');
$this->_helper->actionStack('index', 'sideplaylist');
}
public function contextMenuAction()
{
2010-12-30 23:26:44 +01:00
$id = $this->_getParam('id');
$type = $this->_getParam('type');
$params = '/format/json/id/#id#/type/#type#';
$pl_sess = $this->pl_sess;
if($type === "au") {
$menu[] = array('action' => array('type' => 'ajax', 'url' => '/Library/delete'.$params, 'callback' => 'window["deleteAudioClip"]'),
'title' => 'Delete');
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 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
}
else if($type === "pl") {
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 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');
}
//returns format jjmenu is looking for.
die(json_encode($menu));
}
public function deleteAction()
{
$id = $this->_getParam('id');
2010-12-30 23:26:44 +01:00
if (!is_null($id)) {
$file = StoredFile::Recall($id);
if (PEAR::isError($file)) {
$this->view->message = $file->getMessage();
return;
}
else if(is_null($file)) {
$this->view->message = "file doesn't exist";
return;
}
$res = $file->delete();
if (PEAR::isError($res)) {
$this->view->message = $res->getMessage();
return;
}
}
$this->view->id = $id;
}
public function contentsAction()
{
2010-12-30 23:26:44 +01:00
$this->view->headScript()->appendFile('/js/campcaster/library/library.js','text/javascript');
$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-30 23:26:44 +01:00
public function editFileMdAction()
{
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-30 23:26:44 +01:00