sintonia/application/controllers/PlaylistController.php

284 lines
5.9 KiB
PHP
Raw Normal View History

<?php
class PlaylistController extends Zend_Controller_Action
{
protected $pl_sess = null;
public function init()
{
2010-12-22 18:42:46 +01:00
if(!Zend_Auth::getInstance()->hasIdentity())
{
$this->_redirect('login/index');
}
$ajaxContext = $this->_helper->getHelper('AjaxContext');
$ajaxContext->addActionContext('add-item', 'json')
->addActionContext('delete-item', 'json')
->addActionContext('set-fade', 'json')
->addActionContext('set-cue', 'json')
->addActionContext('move-item', 'json')
2010-12-22 18:42:46 +01:00
->addActionContext('close', 'json')
->addActionContext('delete-active', 'json')
->initContext();
$this->pl_sess = new Zend_Session_Namespace(UI_PLAYLIST_SESSNAME);
}
2010-12-22 18:42:46 +01:00
private function getPlaylist()
{
$pl_sess = $this->pl_sess;
if(isset($pl_sess->id)) {
$pl = Playlist::Recall($pl_sess->id);
if($pl === FALSE) {
unset($pl_sess->id);
$this->_helper->redirector('index');
}
return $pl;
}
$this->_helper->redirector('index');
}
private function closePlaylist($pl)
{
$userInfo = Zend_Auth::getInstance()->getStorage()->read();
$res = $pl->unlock($userInfo->id);
$pl_sess = $this->pl_sess;
unset($pl_sess->id);
return $res;
}
public function indexAction()
{
2010-12-22 18:42:46 +01:00
}
public function newAction()
{
2010-12-22 18:42:46 +01:00
$pl_sess = $this->pl_sess;
$userInfo = Zend_Auth::getInstance()->getStorage()->read();
$pl = new Playlist();
$pl_id = $pl->create("Test Zend Auth");
$pl->setPLMetaData('dc:creator', $userInfo->login);
$pl->lock($userInfo->id);
//set this playlist as active id.
$pl_sess->id = $pl_id;
$this->_helper->redirector('metadata');
}
public function metadataAction()
{
2010-12-22 18:42:46 +01:00
$request = $this->getRequest();
$form = new Application_Form_PlaylistMetadata();
if ($request->isPost()) {
if ($form->isValid($request->getPost())) {
$formdata = $form->getValues();
2010-12-22 18:42:46 +01:00
$pl = $this->getPlaylist();
$pl->setPLMetaData(UI_MDATA_KEY_TITLE, $formdata["title"]);
if(isset($formdata["description"]))
$pl->setPLMetaData(UI_MDATA_KEY_DESCRIPTION, $formdata["description"]);
$this->_helper->redirector('edit');
}
}
$this->view->form = $form;
}
public function editAction()
{
2010-12-22 18:42:46 +01:00
$this->view->headScript()->appendFile('/js/campcaster/playlist/playlist.js','text/javascript');
2010-12-22 18:42:46 +01:00
$pl = $this->getPlaylist();
2010-12-22 18:42:46 +01:00
$this->view->pl = $pl;
$this->view->playlistcontents = $pl->getContents();
}
public function addItemAction()
2010-12-22 18:42:46 +01:00
{
$id = $this->_getParam('id');
if (!is_null($id)) {
2010-12-22 18:42:46 +01:00
$pl = $this->getPlaylist();
$res = $pl->addAudioClip($id);
2010-12-22 18:42:46 +01:00
if (PEAR::isError($res)) {
$this->view->message = $res->getMessage();
}
2010-12-22 18:42:46 +01:00
$this->view->pl = $pl;
$this->view->html = $this->view->render('sideplaylist/update.phtml');
$this->view->name = $pl->getName();
$this->view->length = $pl->getLength();
2010-12-22 18:42:46 +01:00
unset($this->view->pl);
return;
}
$this->view->message = "a file is not chosen";
}
public function moveItemAction()
{
2010-12-22 18:42:46 +01:00
$oldPos = $this->_getParam('oldPos');
$newPos = $this->_getParam('newPos');
2010-12-22 18:42:46 +01:00
$pl = $this->getPlaylist();
2010-12-22 18:42:46 +01:00
$pl->moveAudioClip($oldPos, $newPos);
2010-12-22 18:42:46 +01:00
$this->view->pl = $pl;
2010-12-22 18:42:46 +01:00
if($display === 'pl') {
$this->view->html = $this->view->render('playlist/update.phtml');
}
else {
$this->view->html = $this->view->render('sideplaylist/update.phtml');
}
$this->view->name = $pl->getName();
$this->view->length = $pl->getLength();
unset($this->view->pl);
}
public function deleteItemAction()
{
2010-12-22 18:42:46 +01:00
$positions = $this->_getParam('pos', array());
$display = $this->_getParam('view');
2010-12-22 18:42:46 +01:00
if (!is_array($positions))
$positions = array($positions);
2010-12-22 18:42:46 +01:00
//so the automatic updating of playlist positioning doesn't affect removal.
sort($positions);
$positions = array_reverse($positions);
2010-12-22 18:42:46 +01:00
$pl = $this->getPlaylist();
2010-12-22 18:42:46 +01:00
foreach ($positions as $pos) {
$pl->delAudioClip($pos);
}
2010-12-22 18:42:46 +01:00
$this->view->pl = $pl;
2010-12-22 18:42:46 +01:00
if($display === 'pl') {
$this->view->html = $this->view->render('playlist/update.phtml');
}
else {
$this->view->html = $this->view->render('sideplaylist/update.phtml');
}
$this->view->name = $pl->getName();
$this->view->length = $pl->getLength();
unset($this->view->pl);
}
public function setCueAction()
{
2010-12-22 18:42:46 +01:00
$pos = $this->_getParam('pos');
$cueIn = $this->_getParam('cueIn', null);
$cueOut = $this->_getParam('cueOut', null);
2010-12-22 18:42:46 +01:00
$pl = $this->getPlaylist();
$response = $pl->changeClipLength($pos, $cueIn, $cueOut);
2010-12-22 18:42:46 +01:00
die(json_encode($response));
}
public function setFadeAction()
{
2010-12-22 18:42:46 +01:00
$pos = $this->_getParam('pos');
$fadeIn = $this->_getParam('fadeIn', null);
$fadeOut = $this->_getParam('fadeOut', null);
2010-12-22 18:42:46 +01:00
$pl = $this->getPlaylist();
$response = $pl->changeFadeInfo($pos, $fadeIn, $fadeOut);
2010-12-22 18:42:46 +01:00
die(json_encode($response));
}
public function deleteAction()
{
$id = $this->_getParam('id', null);
2010-12-22 18:42:46 +01:00
if (!is_null($id)) {
$this->closePlaylist();
Playlist::Delete($id);
}
}
public function deleteActiveAction()
2010-12-22 18:42:46 +01:00
{
$display = $this->_getParam('view');
$pl = $this->getPlaylist();
Playlist::Delete($pl->getId());
$pl_sess = $this->pl_sess;
2010-12-22 18:42:46 +01:00
unset($pl_sess->id);
if($display === 'spl') {
$this->view->html = $this->view->render('sideplaylist/index.phtml');
return;
}
$this->_helper->redirector('index');
}
2010-12-22 18:42:46 +01:00
public function closeAction()
{
2010-12-22 18:42:46 +01:00
$display = $this->_getParam('view');
$pl = $this->getPlaylist();
$this->closePlaylist($pl);
if($display === 'spl') {
$this->view->html = $this->view->render('sideplaylist/index.phtml');
return;
}
$this->_helper->redirector('index');
}
}
2010-12-22 18:42:46 +01:00