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');
|
2012-02-03 18:15:10 +01:00
|
|
|
$ajaxContext->addActionContext('add-items', 'json')
|
|
|
|
->addActionContext('move-item', 'json')
|
2012-01-08 05:37:37 +01:00
|
|
|
->addActionContext('delete-item', 'json')
|
|
|
|
->addActionContext('set-fade', 'json')
|
|
|
|
->addActionContext('set-cue', 'json')
|
|
|
|
->addActionContext('new', 'json')
|
|
|
|
->addActionContext('edit', 'json')
|
|
|
|
->addActionContext('delete', 'json')
|
2011-02-08 22:10:48 +01:00
|
|
|
->addActionContext('set-playlist-fades', 'json')
|
2011-05-17 23:30:17 +02:00
|
|
|
->addActionContext('set-playlist-name', 'json')
|
2012-01-08 05:37:37 +01:00
|
|
|
->addActionContext('set-playlist-description', '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()
|
|
|
|
{
|
2012-02-04 00:12:06 +01:00
|
|
|
$pl = null;
|
2010-12-22 18:42:46 +01:00
|
|
|
|
2012-02-04 00:12:06 +01:00
|
|
|
if (isset($this->pl_sess->id)) {
|
|
|
|
$pl = new Application_Model_Playlist($this->pl_sess->id);
|
2011-02-08 22:10:48 +01:00
|
|
|
}
|
2012-02-04 00:12:06 +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)
|
|
|
|
{
|
2012-02-04 00:12:06 +01:00
|
|
|
$this->pl_sess->id = intval($pl_id);
|
2011-02-08 22:10:48 +01:00
|
|
|
}
|
2010-12-30 19:32:59 +01:00
|
|
|
|
2012-02-03 18:15:10 +01:00
|
|
|
private function createUpdateResponse($pl)
|
2010-12-22 18:42:46 +01:00
|
|
|
{
|
2012-02-03 18:15:10 +01:00
|
|
|
$this->view->pl = $pl;
|
|
|
|
$this->view->html = $this->view->render('playlist/update.phtml');
|
|
|
|
$this->view->name = $pl->getName();
|
|
|
|
$this->view->length = $pl->getLength();
|
|
|
|
$this->view->description = $pl->getDescription();
|
2010-12-22 18:42:46 +01:00
|
|
|
|
2012-02-03 18:15:10 +01:00
|
|
|
unset($this->view->pl);
|
|
|
|
}
|
2010-12-22 18:42:46 +01:00
|
|
|
|
2012-02-03 18:15:10 +01:00
|
|
|
private function createFullResponse($pl = null)
|
|
|
|
{
|
|
|
|
if (isset($pl)) {
|
|
|
|
$this->view->pl = $pl;
|
2012-02-04 00:12:06 +01:00
|
|
|
$this->view->id = $pl->getId();
|
2012-02-03 18:15:10 +01:00
|
|
|
$this->view->html = $this->view->render('playlist/index.phtml');
|
|
|
|
unset($this->view->pl);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$this->view->html = $this->view->render('playlist/index.phtml');
|
|
|
|
}
|
2010-12-22 18:42:46 +01:00
|
|
|
}
|
|
|
|
|
2010-12-07 20:19:27 +01:00
|
|
|
public function indexAction()
|
|
|
|
{
|
2011-04-18 17:02:09 +02:00
|
|
|
$request = $this->getRequest();
|
|
|
|
$baseUrl = $request->getBaseUrl();
|
|
|
|
|
|
|
|
$this->view->headScript()->appendFile($baseUrl.'/js/airtime/library/spl.js','text/javascript');
|
|
|
|
$this->view->headLink()->appendStylesheet($baseUrl.'/css/playlist_builder.css');
|
2011-01-16 21:35:00 +01:00
|
|
|
|
2011-03-31 20:40:55 +02:00
|
|
|
$this->_helper->viewRenderer->setResponseSegment('spl');
|
2012-02-04 00:12:06 +01:00
|
|
|
|
|
|
|
try {
|
|
|
|
$pl = $this->getPlaylist();
|
|
|
|
|
|
|
|
if (isset($pl)) {
|
|
|
|
$this->view->pl = $pl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (PlaylistNotFoundException $e) {
|
|
|
|
Logging::log("Playlist not found");
|
|
|
|
$this->changePlaylist(null);
|
|
|
|
}
|
|
|
|
catch (Exception $e) {
|
|
|
|
Logging::log("{$e->getMessage()}");
|
|
|
|
}
|
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();
|
|
|
|
|
2011-09-22 18:24:17 +02:00
|
|
|
$pl = new Application_Model_Playlist();
|
2012-02-04 00:12:06 +01:00
|
|
|
$pl->setName("Untitled Playlist");
|
2010-12-07 20:19:27 +01:00
|
|
|
$pl->setPLMetaData('dc:creator', $userInfo->login);
|
|
|
|
|
2011-03-31 20:40:55 +02:00
|
|
|
$this->changePlaylist($pl->getId());
|
2012-02-03 18:15:10 +01:00
|
|
|
$this->createFullResponse($pl);
|
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);
|
2011-03-31 20:40:55 +02:00
|
|
|
|
2012-02-04 00:12:06 +01:00
|
|
|
if (!is_null($pl_id)) {
|
2011-03-31 20:40:55 +02:00
|
|
|
$this->changePlaylist($pl_id);
|
2010-12-30 19:32:59 +01:00
|
|
|
}
|
2011-03-31 20:40:55 +02:00
|
|
|
|
2012-02-04 00:12:06 +01:00
|
|
|
try {
|
|
|
|
$pl = $this->getPlaylist();
|
|
|
|
}
|
|
|
|
catch (PlaylistNotFoundException $e) {
|
|
|
|
Logging::log("Playlist {$pl_id} not found");
|
|
|
|
$this->changePlaylist(null);
|
|
|
|
}
|
|
|
|
catch (Exception $e) {
|
|
|
|
Logging::log("{$e->getFile()}");
|
|
|
|
Logging::log("{$e->getLine()}");
|
|
|
|
Logging::log("{$e->getMessage()}");
|
|
|
|
$this->changePlaylist(null);
|
|
|
|
}
|
2011-03-31 20:40:55 +02:00
|
|
|
|
2012-02-03 18:15:10 +01:00
|
|
|
$this->createFullResponse($pl);
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
2012-02-04 00:12:06 +01:00
|
|
|
public function deleteAction()
|
2011-02-08 22:10:48 +01:00
|
|
|
{
|
2012-02-04 00:12:06 +01:00
|
|
|
$ids = $this->_getParam('ids');
|
|
|
|
$ids = (!is_array($ids)) ? array($ids) : $ids;
|
|
|
|
$pl = null;
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2012-02-04 00:12:06 +01:00
|
|
|
try {
|
2011-03-31 20:40:55 +02:00
|
|
|
|
2012-02-04 00:12:06 +01:00
|
|
|
Logging::log("Currently active playlist {$this->pl_sess->id}");
|
|
|
|
if (in_array($this->pl_sess->id, $ids)) {
|
|
|
|
Logging::log("Deleting currently active playlist");
|
|
|
|
$this->changePlaylist(null);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$pl = $this->getPlaylist();
|
|
|
|
Logging::log("Not deleting currently active playlist");
|
2011-11-10 21:35:27 +01:00
|
|
|
}
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2012-02-04 00:12:06 +01:00
|
|
|
Application_Model_Playlist::DeletePlaylists($ids);
|
|
|
|
}
|
|
|
|
catch(PlaylistNotFoundException $e) {
|
|
|
|
Logging::log("Playlist not found");
|
|
|
|
$this->changePlaylist(null);
|
|
|
|
$pl = null;
|
|
|
|
}
|
|
|
|
catch(Exception $e) {
|
|
|
|
Logging::log("{$e->getFile()}");
|
|
|
|
Logging::log("{$e->getLine()}");
|
|
|
|
Logging::log("{$e->getMessage()}");
|
|
|
|
}
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2012-02-04 00:12:06 +01:00
|
|
|
$this->createFullResponse($pl);
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
2012-02-04 00:12:06 +01:00
|
|
|
public function addItemsAction()
|
2010-12-07 20:19:27 +01:00
|
|
|
{
|
2012-02-04 00:12:06 +01:00
|
|
|
$ids = $this->_getParam('ids');
|
|
|
|
$ids = (!is_array($ids)) ? array($ids) : $ids;
|
|
|
|
$afterItem = $this->_getParam('afterItem', null);
|
2011-03-31 20:40:55 +02:00
|
|
|
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2012-02-04 00:12:06 +01:00
|
|
|
try {
|
|
|
|
$pl = $this->getPlaylist();
|
|
|
|
$pl->addAudioClips($ids, $afterItem);
|
|
|
|
}
|
|
|
|
catch (PlaylistNotFoundException $e) {
|
|
|
|
Logging::log("Playlist {$pl_id} not found");
|
|
|
|
$this->changePlaylist(null);
|
|
|
|
}
|
|
|
|
catch (Exception $e) {
|
|
|
|
Logging::log("{$e->getFile()}");
|
|
|
|
Logging::log("{$e->getLine()}");
|
|
|
|
Logging::log("{$e->getMessage()}");
|
|
|
|
}
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2012-02-04 00:12:06 +01:00
|
|
|
$this->createUpdateResponse($pl);
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
2012-02-04 00:12:06 +01:00
|
|
|
public function moveItemAction()
|
2010-12-07 20:19:27 +01:00
|
|
|
{
|
2012-02-04 00:12:06 +01:00
|
|
|
$ids = $this->_getParam('ids');
|
|
|
|
$ids = (!is_array($ids)) ? array($ids) : $ids;
|
|
|
|
$afterItem = $this->_getParam('afterItem', null);
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2012-02-04 00:12:06 +01:00
|
|
|
try {
|
|
|
|
$pl = $this->getPlaylist();
|
|
|
|
$pl->moveAudioClips($ids, $afterItem);
|
|
|
|
}
|
|
|
|
catch (PlaylistNotFoundException $e) {
|
|
|
|
Logging::log("Playlist {$pl_id} not found");
|
|
|
|
$this->changePlaylist(null);
|
|
|
|
}
|
|
|
|
catch (Exception $e) {
|
|
|
|
Logging::log("{$e->getFile()}");
|
|
|
|
Logging::log("{$e->getLine()}");
|
|
|
|
Logging::log("{$e->getMessage()}");
|
2011-11-10 21:35:27 +01:00
|
|
|
}
|
2010-12-21 22:45:36 +01:00
|
|
|
|
2012-02-03 18:15:10 +01:00
|
|
|
$this->createUpdateResponse($pl);
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
2012-02-04 00:12:06 +01:00
|
|
|
public function deleteItemsAction()
|
2012-01-08 05:37:37 +01:00
|
|
|
{
|
|
|
|
$ids = $this->_getParam('ids');
|
2012-02-04 00:12:06 +01:00
|
|
|
$ids = (!is_array($ids)) ? array($ids) : $ids;
|
2012-01-08 05:37:37 +01:00
|
|
|
|
2012-02-04 00:12:06 +01:00
|
|
|
try {
|
2012-01-08 05:37:37 +01:00
|
|
|
$pl = $this->getPlaylist();
|
2012-02-04 00:12:06 +01:00
|
|
|
$pl->delAudioClips($ids);
|
2012-01-08 05:37:37 +01:00
|
|
|
}
|
2012-02-04 00:12:06 +01:00
|
|
|
catch (PlaylistNotFoundException $e) {
|
|
|
|
Logging::log("Playlist {$pl_id} not found");
|
|
|
|
$this->changePlaylist(null);
|
2012-02-03 18:15:10 +01:00
|
|
|
}
|
2012-02-04 00:12:06 +01:00
|
|
|
catch (Exception $e) {
|
|
|
|
Logging::log("{$e->getFile()}");
|
|
|
|
Logging::log("{$e->getLine()}");
|
|
|
|
Logging::log("{$e->getMessage()}");
|
2012-01-08 05:37:37 +01:00
|
|
|
}
|
2012-02-03 18:15:10 +01:00
|
|
|
|
2012-02-04 00:12:06 +01:00
|
|
|
$this->createUpdateResponse($pl);
|
2012-01-08 05:37:37 +01:00
|
|
|
}
|
2012-02-03 18:15:10 +01:00
|
|
|
|
2010-12-07 20:19:27 +01:00
|
|
|
public function setCueAction()
|
|
|
|
{
|
2010-12-22 18:42:46 +01:00
|
|
|
$pos = $this->_getParam('pos');
|
|
|
|
$pl = $this->getPlaylist();
|
2011-11-29 15:30:05 +01:00
|
|
|
if ($pl === false){
|
2011-11-10 21:35:27 +01:00
|
|
|
$this->view->playlist_error = true;
|
|
|
|
return false;
|
|
|
|
}
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2011-11-29 15:30:05 +01:00
|
|
|
$cueIn = $this->_getParam('cueIn', null);
|
|
|
|
$cueOut = $this->_getParam('cueOut', null);
|
2011-01-17 01:31:10 +01:00
|
|
|
|
2011-11-29 15:30:05 +01:00
|
|
|
$response = $pl->changeClipLength($pos, $cueIn, $cueOut);
|
2011-01-17 01:31:10 +01:00
|
|
|
|
2011-11-29 15:30:05 +01:00
|
|
|
$this->view->response = $response;
|
2011-01-17 01:31:10 +01:00
|
|
|
|
2011-11-29 15:30:05 +01:00
|
|
|
if(!isset($response["error"])) {
|
2012-02-03 18:15:10 +01:00
|
|
|
$this->createUpdateResponse($pl);
|
2011-11-29 15:30:05 +01:00
|
|
|
}
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function setFadeAction()
|
|
|
|
{
|
2010-12-22 18:42:46 +01:00
|
|
|
$pos = $this->_getParam('pos');
|
|
|
|
$pl = $this->getPlaylist();
|
2011-11-10 21:35:27 +01:00
|
|
|
if($pl === false){
|
|
|
|
$this->view->playlist_error = true;
|
|
|
|
return false;
|
|
|
|
}
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2011-11-29 15:30:05 +01:00
|
|
|
$fadeIn = $this->_getParam('fadeIn', null);
|
|
|
|
$fadeOut = $this->_getParam('fadeOut', null);
|
2011-01-17 01:31:10 +01:00
|
|
|
|
2011-11-29 15:30:05 +01:00
|
|
|
$response = $pl->changeFadeInfo($pos, $fadeIn, $fadeOut);
|
2011-01-17 01:31:10 +01:00
|
|
|
|
2011-11-29 15:30:05 +01:00
|
|
|
$this->view->response = $response;
|
2011-01-17 19:55:43 +01:00
|
|
|
|
2011-11-29 15:30:05 +01:00
|
|
|
if(!isset($response["error"])) {
|
2012-02-03 18:15:10 +01:00
|
|
|
$this->createUpdateResponse($pl);
|
2011-11-10 21:35:27 +01:00
|
|
|
}
|
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();
|
2011-11-10 21:35:27 +01:00
|
|
|
if($pl === false){
|
|
|
|
$this->view->playlist_error = true;
|
|
|
|
return false;
|
|
|
|
}
|
2011-02-08 22:10:48 +01:00
|
|
|
|
|
|
|
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];
|
|
|
|
}
|
|
|
|
|
2011-05-17 23:30:17 +02:00
|
|
|
public function setPlaylistNameAction()
|
|
|
|
{
|
|
|
|
$name = $this->_getParam('name', 'Unknown Playlist');
|
|
|
|
|
|
|
|
$pl = $this->getPlaylist();
|
2011-11-10 21:35:27 +01:00
|
|
|
if($pl === false){
|
|
|
|
$this->view->playlist_error = true;
|
|
|
|
return false;
|
|
|
|
}
|
2011-05-17 23:30:17 +02:00
|
|
|
$pl->setName($name);
|
|
|
|
|
|
|
|
$this->view->playlistName = $name;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setPlaylistDescriptionAction()
|
|
|
|
{
|
|
|
|
$description = $this->_getParam('description', false);
|
|
|
|
$pl = $this->getPlaylist();
|
2011-11-10 21:35:27 +01:00
|
|
|
if($pl === false){
|
|
|
|
$this->view->playlist_error = true;
|
|
|
|
return false;
|
|
|
|
}
|
2011-05-17 23:30:17 +02:00
|
|
|
|
|
|
|
if($description != false) {
|
|
|
|
$pl->setDescription($description);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$description = $pl->getDescription();
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->view->playlistDescription = $description;
|
|
|
|
}
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|