sintonia/application/controllers/PlaylistController.php

363 lines
8.2 KiB
PHP
Raw Normal View History

<?php
class PlaylistController extends Zend_Controller_Action
{
protected $pl_sess = null;
public function init()
{
$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('new', 'json')
->addActionContext('metadata', 'json')
->addActionContext('edit', 'json')
->addActionContext('delete-active', 'json')
->addActionContext('delete', 'json')
->addActionContext('set-playlist-fades', 'json')
->initContext();
$this->pl_sess = new Zend_Session_Namespace(UI_PLAYLIST_SESSNAME);
}
private function getPlaylist()
{
$pl_sess = $this->pl_sess;
2010-12-22 18:42:46 +01:00
if(isset($pl_sess->id)) {
$pl = Playlist::Recall($pl_sess->id);
if($pl === FALSE) {
unset($pl_sess->id);
return;
2010-12-22 18:42:46 +01:00
}
return $pl;
}
}
private function changePlaylist($pl_id)
{
$pl_sess = $this->pl_sess;
if(isset($pl_sess->id)) {
$pl = Playlist::Recall($pl_sess->id);
if($pl !== FALSE) {
$this->closePlaylist($pl);
}
}
$userInfo = Zend_Auth::getInstance()->getStorage()->read();
$pl = Playlist::Recall($pl_id);
if($pl === FALSE) {
return FALSE;
}
$pl->lock($userInfo->id);
$pl_sess->id = $pl_id;
}
private function closePlaylist($pl)
2010-12-22 18:42:46 +01:00
{
$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()
{
$this->view->headScript()->appendFile('/js/airtime/library/spl.js','text/javascript');
$this->view->headLink()->appendStylesheet('/css/playlist_builder.css');
$this->_helper->viewRenderer->setResponseSegment('spl');
$this->view->pl = $this->getPlaylist();
}
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("Untitled Playlist");
$pl->setPLMetaData('dc:creator', $userInfo->login);
$this->changePlaylist($pl_id);
$form = new Application_Form_PlaylistMetadata();
$this->view->fieldset = $form;
$this->view->form = $this->view->render('playlist/new.phtml');
}
public function metadataAction()
{
$request = $this->getRequest();
$form = new Application_Form_PlaylistMetadata();
2010-12-30 21:10:05 +01:00
$pl_id = $this->_getParam('id', null);
//not a new playlist
if(!is_null($pl_id)) {
$this->changePlaylist($pl_id);
$pl = $this->getPlaylist();
$title = $pl->getPLMetaData(UI_MDATA_KEY_TITLE);
$desc = $pl->getPLMetaData(UI_MDATA_KEY_DESCRIPTION);
$data = array( 'title' => $title, 'description' => $desc);
$form->populate($data);
}
if ($request->isPost()) {
$title = $this->_getParam('title', null);
$description = $this->_getParam('description', null);
$pl = $this->getPlaylist();
if($title)
$pl->setName($title);
if(isset($description)) {
$pl->setPLMetaData(UI_MDATA_KEY_DESCRIPTION, $description);
}
$this->view->pl = $pl;
$this->view->html = $this->view->render('playlist/index.phtml');
unset($this->view->pl);
}
$this->view->fieldset = $form;
$this->view->form = $this->view->render('playlist/new.phtml');
}
public function editAction()
{
$pl_id = $this->_getParam('id', null);
if(!is_null($pl_id)) {
$this->changePlaylist($pl_id);
}
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->html = $this->view->render('playlist/index.phtml');
unset($this->view->pl);
}
public function addItemAction()
{
$id = $this->_getParam('id');
$pos = $this->_getParam('pos', null);
if (!is_null($id)) {
2010-12-22 18:42:46 +01:00
$pl = $this->getPlaylist();
$res = $pl->addAudioClip($id, $pos);
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('playlist/update.phtml');
2010-12-22 18:42:46 +01:00
$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()
{
$oldPos = $this->_getParam('oldPos');
2010-12-22 18:42:46 +01:00
$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;
$this->view->html = $this->view->render('playlist/update.phtml');
2010-12-22 18:42:46 +01:00
$this->view->name = $pl->getName();
$this->view->length = $pl->getLength();
unset($this->view->pl);
}
public function deleteItemAction()
{
$positions = $this->_getParam('pos', array());
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;
$this->view->html = $this->view->render('playlist/update.phtml');
2010-12-22 18:42:46 +01:00
$this->view->name = $pl->getName();
$this->view->length = $pl->getLength();
unset($this->view->pl);
}
public function setCueAction()
{
$request = $this->getRequest();
2010-12-22 18:42:46 +01:00
$pos = $this->_getParam('pos');
$pl = $this->getPlaylist();
if($request->isPost()) {
$cueIn = $this->_getParam('cueIn', null);
$cueOut = $this->_getParam('cueOut', null);
$response = $pl->changeClipLength($pos, $cueIn, $cueOut);
$this->view->response = $response;
return;
}
$cues = $pl->getCueInfo($pos);
$this->view->pos = $pos;
$this->view->cueIn = $cues[0];
$this->view->cueOut = $cues[1];
$this->view->origLength = $cues[2];
$this->view->html = $this->view->render('playlist/set-cue.phtml');
}
public function setFadeAction()
{
$request = $this->getRequest();
2010-12-22 18:42:46 +01:00
$pos = $this->_getParam('pos');
$pl = $this->getPlaylist();
if($request->isPost()) {
$fadeIn = $this->_getParam('fadeIn', null);
$fadeOut = $this->_getParam('fadeOut', null);
$response = $pl->changeFadeInfo($pos, $fadeIn, $fadeOut);
$this->view->response = $response;
return;
}
$this->view->pos = intval($pos);
$fades = $pl->getFadeInfo($pos+1);
$this->view->fadeIn = $fades[0];
$fades = $pl->getFadeInfo($pos);
$this->view->fadeOut = $fades[1];
$this->view->html = $this->view->render('playlist/set-fade.phtml');
}
public function deleteAction()
{
$id = $this->_getParam('id', null);
$pl = Playlist::Recall($id);
2010-12-22 18:42:46 +01:00
if ($pl !== FALSE) {
Playlist::Delete($id);
$pl_sess = $this->pl_sess;
if($pl_sess->id === $id){
unset($pl_sess->id);
}
}
$this->view->id = $id;
}
public function deleteActiveAction()
{
$pl = $this->getPlaylist();
Playlist::Delete($pl->getId());
$pl_sess = $this->pl_sess;
2010-12-22 18:42:46 +01:00
unset($pl_sess->id);
$this->view->html = $this->view->render('playlist/index.phtml');
}
2010-12-22 18:42:46 +01:00
public function closeAction()
{
$pl = $this->getPlaylist();
2010-12-22 18:42:46 +01:00
$this->closePlaylist($pl);
$this->view->html = $this->view->render('playlist/index.phtml');
}
public function setPlaylistFadesAction()
{
$request = $this->getRequest();
$pl = $this->getPlaylist();
if($request->isPost()) {
$fadeIn = $this->_getParam('fadeIn', null);
$fadeOut = $this->_getParam('fadeOut', null);
if($fadeIn)
$response = $pl->changeFadeInfo(0, $fadeIn, $fadeOut);
else if($fadeOut)
$response = $pl->changeFadeInfo($pl->getSize(), $fadeIn, $fadeOut);
$this->view->response = $response;
return;
}
$fades = $pl->getFadeInfo(0);
$this->view->fadeIn = $fades[0];
$fades = $pl->getFadeInfo($pl->getSize());
$this->view->fadeOut = $fades[1];
}
}
2010-12-22 18:42:46 +01:00