2010-12-07 20:19:27 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class PlaylistController extends Zend_Controller_Action
|
|
|
|
{
|
|
|
|
|
|
|
|
protected $pl_sess = null;
|
|
|
|
|
|
|
|
public function init()
|
|
|
|
{
|
|
|
|
$ajaxContext = $this->_helper->getHelper('AjaxContext');
|
|
|
|
$ajaxContext->addActionContext('add-item', 'json')
|
2010-12-21 22:45:36 +01:00
|
|
|
->addActionContext('delete-item', 'json')
|
2010-12-07 20:19:27 +01:00
|
|
|
->addActionContext('set-fade', 'json')
|
|
|
|
->addActionContext('set-cue', 'json')
|
2010-12-21 22:45:36 +01:00
|
|
|
->addActionContext('move-item', 'json')
|
2010-12-22 18:42:46 +01:00
|
|
|
->addActionContext('close', 'json')
|
2011-01-16 23:12:02 +01:00
|
|
|
->addActionContext('new', 'json')
|
|
|
|
->addActionContext('metadata', 'json')
|
2010-12-30 19:32:59 +01:00
|
|
|
->addActionContext('edit', 'json')
|
2010-12-22 19:05:32 +01:00
|
|
|
->addActionContext('delete-active', 'json')
|
2010-12-30 00:43:17 +01:00
|
|
|
->addActionContext('delete', 'json')
|
2011-02-08 22:10:48 +01:00
|
|
|
->addActionContext('set-playlist-fades', 'json')
|
2010-12-07 20:19:27 +01:00
|
|
|
->initContext();
|
|
|
|
|
|
|
|
$this->pl_sess = new Zend_Session_Namespace(UI_PLAYLIST_SESSNAME);
|
|
|
|
}
|
|
|
|
|
2011-02-08 22:10:48 +01:00
|
|
|
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);
|
2011-01-16 22:00:44 +01:00
|
|
|
return;
|
2010-12-22 18:42:46 +01:00
|
|
|
}
|
|
|
|
return $pl;
|
2011-02-08 22:10:48 +01:00
|
|
|
}
|
|
|
|
}
|
2010-12-30 19:32:59 +01:00
|
|
|
|
2011-02-08 22:10:48 +01:00
|
|
|
private function changePlaylist($pl_id)
|
|
|
|
{
|
|
|
|
$pl_sess = $this->pl_sess;
|
|
|
|
|
2010-12-30 19:32:59 +01:00
|
|
|
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);
|
2011-02-08 22:10:48 +01:00
|
|
|
$pl_sess->id = $pl_id;
|
|
|
|
}
|
2010-12-30 19:32:59 +01:00
|
|
|
|
2011-02-08 22:10:48 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2010-12-07 20:19:27 +01:00
|
|
|
public function indexAction()
|
|
|
|
{
|
2011-01-16 21:35:00 +01:00
|
|
|
$this->view->headScript()->appendFile('/js/airtime/library/spl.js','text/javascript');
|
|
|
|
$this->view->headLink()->appendStylesheet('/css/playlist_builder.css');
|
|
|
|
|
|
|
|
$this->_helper->viewRenderer->setResponseSegment('spl');
|
2011-01-16 22:00:44 +01:00
|
|
|
$this->view->pl = $this->getPlaylist();
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function newAction()
|
|
|
|
{
|
2010-12-22 18:42:46 +01:00
|
|
|
$pl_sess = $this->pl_sess;
|
2010-12-07 20:19:27 +01:00
|
|
|
$userInfo = Zend_Auth::getInstance()->getStorage()->read();
|
|
|
|
|
|
|
|
$pl = new Playlist();
|
2011-02-09 23:02:32 +01:00
|
|
|
$pl_id = $pl->create("Untitled Playlist");
|
2010-12-07 20:19:27 +01:00
|
|
|
$pl->setPLMetaData('dc:creator', $userInfo->login);
|
|
|
|
|
2010-12-30 19:32:59 +01:00
|
|
|
$this->changePlaylist($pl_id);
|
2011-01-16 23:12:02 +01:00
|
|
|
$form = new Application_Form_PlaylistMetadata();
|
2011-02-12 00:55:08 +01:00
|
|
|
$this->view->fieldset = $form;
|
|
|
|
$this->view->form = $this->view->render('playlist/new.phtml');
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function metadataAction()
|
2011-02-08 22:10:48 +01:00
|
|
|
{
|
2010-12-07 20:19:27 +01:00
|
|
|
$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);
|
|
|
|
}
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2010-12-08 21:40:53 +01:00
|
|
|
if ($request->isPost()) {
|
2011-02-12 00:55:08 +01:00
|
|
|
$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);
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
2011-02-12 00:55:08 +01:00
|
|
|
$this->view->fieldset = $form;
|
|
|
|
$this->view->form = $this->view->render('playlist/new.phtml');
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function editAction()
|
|
|
|
{
|
2011-02-08 22:10:48 +01:00
|
|
|
$pl_id = $this->_getParam('id', null);
|
|
|
|
|
2010-12-30 19:32:59 +01:00
|
|
|
if(!is_null($pl_id)) {
|
|
|
|
$this->changePlaylist($pl_id);
|
|
|
|
}
|
|
|
|
|
2010-12-22 18:42:46 +01:00
|
|
|
$pl = $this->getPlaylist();
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2010-12-22 18:42:46 +01:00
|
|
|
$this->view->pl = $pl;
|
2011-01-16 21:35:00 +01:00
|
|
|
$this->view->html = $this->view->render('playlist/index.phtml');
|
|
|
|
unset($this->view->pl);
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function addItemAction()
|
2011-02-08 22:10:48 +01:00
|
|
|
{
|
|
|
|
$id = $this->_getParam('id');
|
2011-01-27 21:11:19 +01:00
|
|
|
$pos = $this->_getParam('pos', null);
|
2010-12-07 20:19:27 +01:00
|
|
|
|
|
|
|
if (!is_null($id)) {
|
2010-12-22 18:42:46 +01:00
|
|
|
|
|
|
|
$pl = $this->getPlaylist();
|
2011-01-27 21:11:19 +01:00
|
|
|
$res = $pl->addAudioClip($id, $pos);
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2010-12-22 18:42:46 +01:00
|
|
|
if (PEAR::isError($res)) {
|
|
|
|
$this->view->message = $res->getMessage();
|
|
|
|
}
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2010-12-22 18:42:46 +01:00
|
|
|
$this->view->pl = $pl;
|
2011-01-16 21:35:00 +01:00
|
|
|
$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-21 22:45:36 +01:00
|
|
|
|
2010-12-22 18:42:46 +01:00
|
|
|
unset($this->view->pl);
|
|
|
|
return;
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
2010-12-21 22:45:36 +01:00
|
|
|
$this->view->message = "a file is not chosen";
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function moveItemAction()
|
|
|
|
{
|
2011-02-08 22:10:48 +01:00
|
|
|
$oldPos = $this->_getParam('oldPos');
|
2010-12-22 18:42:46 +01:00
|
|
|
$newPos = $this->_getParam('newPos');
|
2011-01-16 21:35:00 +01:00
|
|
|
|
2010-12-22 18:42:46 +01:00
|
|
|
$pl = $this->getPlaylist();
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2010-12-22 18:42:46 +01:00
|
|
|
$pl->moveAudioClip($oldPos, $newPos);
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2010-12-22 18:42:46 +01:00
|
|
|
$this->view->pl = $pl;
|
2011-01-16 21:35:00 +01:00
|
|
|
$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);
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function deleteItemAction()
|
|
|
|
{
|
2011-02-08 22:10:48 +01:00
|
|
|
$positions = $this->_getParam('pos', array());
|
|
|
|
|
2010-12-22 18:42:46 +01:00
|
|
|
if (!is_array($positions))
|
|
|
|
$positions = array($positions);
|
2010-12-07 20:19:27 +01:00
|
|
|
|
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-07 20:19:27 +01:00
|
|
|
|
2010-12-22 18:42:46 +01:00
|
|
|
$pl = $this->getPlaylist();
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2010-12-22 18:42:46 +01:00
|
|
|
foreach ($positions as $pos) {
|
|
|
|
$pl->delAudioClip($pos);
|
|
|
|
}
|
2010-12-21 22:45:36 +01:00
|
|
|
|
2010-12-22 18:42:46 +01:00
|
|
|
$this->view->pl = $pl;
|
2011-01-16 21:35:00 +01:00
|
|
|
$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();
|
|
|
|
|
2011-02-08 22:10:48 +01:00
|
|
|
unset($this->view->pl);
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function setCueAction()
|
|
|
|
{
|
2011-02-08 22:10:48 +01:00
|
|
|
$request = $this->getRequest();
|
2010-12-22 18:42:46 +01:00
|
|
|
$pos = $this->_getParam('pos');
|
|
|
|
$pl = $this->getPlaylist();
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2011-01-17 01:31:10 +01:00
|
|
|
if($request->isPost()) {
|
|
|
|
$cueIn = $this->_getParam('cueIn', null);
|
|
|
|
$cueOut = $this->_getParam('cueOut', null);
|
|
|
|
|
|
|
|
$response = $pl->changeClipLength($pos, $cueIn, $cueOut);
|
|
|
|
|
2011-01-17 19:55:43 +01:00
|
|
|
$this->view->response = $response;
|
|
|
|
return;
|
2011-01-17 01:31:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$cues = $pl->getCueInfo($pos);
|
|
|
|
|
2011-01-17 19:55:43 +01:00
|
|
|
$this->view->pos = $pos;
|
2011-01-17 01:31:10 +01:00
|
|
|
$this->view->cueIn = $cues[0];
|
|
|
|
$this->view->cueOut = $cues[1];
|
2011-02-08 00:44:42 +01:00
|
|
|
$this->view->origLength = $cues[2];
|
2011-01-17 01:31:10 +01:00
|
|
|
$this->view->html = $this->view->render('playlist/set-cue.phtml');
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function setFadeAction()
|
|
|
|
{
|
2011-02-08 22:10:48 +01:00
|
|
|
$request = $this->getRequest();
|
2010-12-22 18:42:46 +01:00
|
|
|
$pos = $this->_getParam('pos');
|
|
|
|
$pl = $this->getPlaylist();
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2011-01-17 01:31:10 +01:00
|
|
|
if($request->isPost()) {
|
|
|
|
$fadeIn = $this->_getParam('fadeIn', null);
|
|
|
|
$fadeOut = $this->_getParam('fadeOut', null);
|
|
|
|
|
|
|
|
$response = $pl->changeFadeInfo($pos, $fadeIn, $fadeOut);
|
|
|
|
|
2011-01-17 19:55:43 +01:00
|
|
|
$this->view->response = $response;
|
|
|
|
return;
|
2011-01-17 01:31:10 +01:00
|
|
|
}
|
|
|
|
|
2011-02-08 00:44:42 +01:00
|
|
|
$this->view->pos = intval($pos);
|
2011-01-17 19:55:43 +01:00
|
|
|
|
2011-02-08 00:44:42 +01:00
|
|
|
$fades = $pl->getFadeInfo($pos+1);
|
2011-01-17 01:31:10 +01:00
|
|
|
$this->view->fadeIn = $fades[0];
|
|
|
|
|
2011-02-08 00:44:42 +01:00
|
|
|
$fades = $pl->getFadeInfo($pos);
|
2011-01-17 01:31:10 +01:00
|
|
|
$this->view->fadeOut = $fades[1];
|
|
|
|
$this->view->html = $this->view->render('playlist/set-fade.phtml');
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function deleteAction()
|
|
|
|
{
|
|
|
|
$id = $this->_getParam('id', null);
|
2010-12-30 00:43:17 +01:00
|
|
|
$pl = Playlist::Recall($id);
|
2010-12-22 18:42:46 +01:00
|
|
|
|
2010-12-30 00:43:17 +01:00
|
|
|
if ($pl !== FALSE) {
|
2010-12-07 20:19:27 +01:00
|
|
|
|
|
|
|
Playlist::Delete($id);
|
2010-12-30 00:43:17 +01:00
|
|
|
|
|
|
|
$pl_sess = $this->pl_sess;
|
|
|
|
|
|
|
|
if($pl_sess->id === $id){
|
|
|
|
unset($pl_sess->id);
|
|
|
|
}
|
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 deleteActiveAction()
|
2011-02-08 22:10:48 +01:00
|
|
|
{
|
|
|
|
$pl = $this->getPlaylist();
|
2010-12-22 19:05:32 +01:00
|
|
|
Playlist::Delete($pl->getId());
|
|
|
|
|
|
|
|
$pl_sess = $this->pl_sess;
|
2010-12-22 18:42:46 +01:00
|
|
|
unset($pl_sess->id);
|
2010-12-22 19:05:32 +01:00
|
|
|
|
2011-01-16 21:35:00 +01:00
|
|
|
$this->view->html = $this->view->render('playlist/index.phtml');
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
2010-12-22 18:42:46 +01:00
|
|
|
public function closeAction()
|
2010-12-07 20:19:27 +01:00
|
|
|
{
|
2011-02-08 22:10:48 +01:00
|
|
|
$pl = $this->getPlaylist();
|
2010-12-22 18:42:46 +01:00
|
|
|
$this->closePlaylist($pl);
|
|
|
|
|
2011-02-08 22:10:48 +01:00
|
|
|
$this->view->html = $this->view->render('playlist/index.phtml');
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
2011-02-08 22:10:48 +01:00
|
|
|
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-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-12-22 18:42:46 +01:00
|
|
|
|
|
|
|
|
2011-02-08 22:10:48 +01:00
|
|
|
|
|
|
|
|
2010-12-07 20:19:27 +01:00
|
|
|
|
|
|
|
|
|
|
|
|