2010-12-07 20:19:27 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class PlaylistController extends Zend_Controller_Action
|
|
|
|
{
|
2012-07-25 17:00:46 +02:00
|
|
|
protected $obj_sess = null;
|
2010-12-07 20:19:27 +01:00
|
|
|
|
|
|
|
public function init()
|
|
|
|
{
|
|
|
|
$ajaxContext = $this->_helper->getHelper('AjaxContext');
|
2012-02-03 18:15:10 +01:00
|
|
|
$ajaxContext->addActionContext('add-items', 'json')
|
2012-02-04 15:52:31 +01:00
|
|
|
->addActionContext('move-items', 'json')
|
|
|
|
->addActionContext('delete-items', 'json')
|
2012-01-08 05:37:37 +01:00
|
|
|
->addActionContext('set-fade', 'json')
|
|
|
|
->addActionContext('set-cue', 'json')
|
|
|
|
->addActionContext('new', 'json')
|
|
|
|
->addActionContext('edit', 'json')
|
|
|
|
->addActionContext('delete', 'json')
|
2012-02-25 00:24:24 +01:00
|
|
|
->addActionContext('play', 'json')
|
2011-02-08 22:10:48 +01:00
|
|
|
->addActionContext('set-playlist-fades', 'json')
|
2012-02-05 23:38:12 +01:00
|
|
|
->addActionContext('get-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')
|
2012-03-10 00:47:08 +01:00
|
|
|
->addActionContext('playlist-preview', 'json')
|
|
|
|
->addActionContext('get-playlist', 'json')
|
2012-08-09 23:23:52 +02:00
|
|
|
->addActionContext('save', 'json')
|
2012-07-25 18:44:37 +02:00
|
|
|
->addActionContext('smart-block-generate', 'json')
|
|
|
|
->addActionContext('smart-block-shuffle', 'json')
|
2012-07-30 23:18:33 +02:00
|
|
|
->addActionContext('get-block-info', 'json')
|
2010-12-07 20:19:27 +01:00
|
|
|
->initContext();
|
|
|
|
|
2012-07-25 17:00:46 +02:00
|
|
|
$this->obj_sess = new Zend_Session_Namespace(UI_PLAYLISTCONTROLLER_OBJ_SESSNAME);
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
2012-07-25 17:00:46 +02:00
|
|
|
private function getPlaylist($p_type)
|
2011-02-08 22:10:48 +01:00
|
|
|
{
|
2012-07-25 17:00:46 +02:00
|
|
|
$obj = null;
|
2012-08-21 22:54:14 +02:00
|
|
|
$objInfo = Application_Model_Library::getObjInfo($p_type);
|
2010-12-22 18:42:46 +01:00
|
|
|
|
2012-07-25 17:00:46 +02:00
|
|
|
if (isset($this->obj_sess->id)) {
|
|
|
|
$obj = new $objInfo['className']($this->obj_sess->id);
|
2012-02-20 18:24:04 +01:00
|
|
|
|
|
|
|
$modified = $this->_getParam('modified', null);
|
2012-07-25 17:00:46 +02:00
|
|
|
if ($obj->getLastModified("U") !== $modified) {
|
|
|
|
$this->createFullResponse($obj);
|
|
|
|
throw new PlaylistOutDatedException("You are viewing an older version of {$obj->getName()}");
|
2012-02-20 18:24:04 +01:00
|
|
|
}
|
2011-02-08 22:10:48 +01:00
|
|
|
}
|
2012-07-16 03:17:13 +02:00
|
|
|
|
2012-07-25 17:00:46 +02:00
|
|
|
return $obj;
|
2011-02-08 22:10:48 +01:00
|
|
|
}
|
2010-12-30 19:32:59 +01:00
|
|
|
|
|
|
|
|
2012-07-25 17:00:46 +02:00
|
|
|
private function createUpdateResponse($obj)
|
2010-12-22 18:42:46 +01:00
|
|
|
{
|
2012-07-25 17:00:46 +02:00
|
|
|
$formatter = new LengthFormatter($obj->getLength());
|
2012-02-24 15:07:04 +01:00
|
|
|
$this->view->length = $formatter->format();
|
|
|
|
|
2012-07-25 17:00:46 +02:00
|
|
|
$this->view->obj = $obj;
|
2012-08-08 21:29:09 +02:00
|
|
|
$this->view->contents = $obj->getContents();
|
2012-02-03 18:15:10 +01:00
|
|
|
$this->view->html = $this->view->render('playlist/update.phtml');
|
2012-07-25 17:00:46 +02:00
|
|
|
$this->view->name = $obj->getName();
|
|
|
|
$this->view->description = $obj->getDescription();
|
|
|
|
$this->view->modified = $obj->getLastModified("U");
|
2010-12-22 18:42:46 +01:00
|
|
|
|
2012-07-25 17:00:46 +02:00
|
|
|
unset($this->view->obj);
|
2012-02-03 18:15:10 +01:00
|
|
|
}
|
2010-12-22 18:42:46 +01:00
|
|
|
|
2012-07-25 17:00:46 +02:00
|
|
|
private function createFullResponse($obj = null, $isJson = false)
|
2012-02-03 18:15:10 +01:00
|
|
|
{
|
2012-07-25 17:00:46 +02:00
|
|
|
$isBlock = false;
|
|
|
|
$viewPath = 'playlist/playlist.phtml';
|
|
|
|
if ($obj instanceof Application_Model_Block) {
|
|
|
|
$isBlock = true;
|
|
|
|
$viewPath = 'playlist/smart-block.phtml';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($obj)) {
|
|
|
|
$formatter = new LengthFormatter($obj->getLength());
|
2012-02-24 15:07:04 +01:00
|
|
|
$this->view->length = $formatter->format();
|
2012-07-10 21:25:29 +02:00
|
|
|
|
2012-07-25 17:00:46 +02:00
|
|
|
if ($isBlock) {
|
|
|
|
$form = new Application_Form_SmartBlockCriteria();
|
|
|
|
$form->removeDecorator('DtDdWrapper');
|
|
|
|
$form->startForm($obj->getId());
|
2012-08-15 17:36:41 +02:00
|
|
|
|
2012-07-25 17:00:46 +02:00
|
|
|
$this->view->form = $form;
|
|
|
|
$this->view->obj = $obj;
|
|
|
|
$this->view->id = $obj->getId();
|
|
|
|
if ($isJson) {
|
|
|
|
return $this->view->render($viewPath);
|
|
|
|
} else {
|
|
|
|
$this->view->html = $this->view->render($viewPath);
|
|
|
|
}
|
2012-08-21 16:50:24 +02:00
|
|
|
} else {
|
2012-07-25 17:00:46 +02:00
|
|
|
$this->view->obj = $obj;
|
|
|
|
$this->view->id = $obj->getId();
|
|
|
|
$this->view->html = $this->view->render($viewPath);
|
|
|
|
unset($this->view->obj);
|
2012-07-16 23:18:37 +02:00
|
|
|
}
|
2012-08-21 16:50:24 +02:00
|
|
|
} else {
|
2012-07-25 17:00:46 +02:00
|
|
|
$this->view->html = $this->view->render($viewPath);
|
2012-02-03 18:15:10 +01:00
|
|
|
}
|
2010-12-22 18:42:46 +01:00
|
|
|
}
|
|
|
|
|
2012-07-10 22:41:30 +02:00
|
|
|
private function playlistOutdated($e)
|
2012-02-20 18:24:04 +01:00
|
|
|
{
|
|
|
|
$this->view->error = $e->getMessage();
|
|
|
|
}
|
|
|
|
|
2012-07-30 23:18:33 +02:00
|
|
|
private function blockDynamic($obj)
|
2012-07-18 17:52:09 +02:00
|
|
|
{
|
2012-08-02 17:52:11 +02:00
|
|
|
$this->view->error = "You cannot add tracks to dynamic blocks.";
|
2012-07-25 17:00:46 +02:00
|
|
|
$this->createFullResponse($obj);
|
2012-07-18 17:52:09 +02:00
|
|
|
}
|
|
|
|
|
2012-07-25 17:00:46 +02:00
|
|
|
private function playlistNotFound($p_type)
|
2012-02-20 18:24:04 +01:00
|
|
|
{
|
2012-07-25 17:00:46 +02:00
|
|
|
$this->view->error = "{$p_type} not found";
|
2012-02-20 18:24:04 +01:00
|
|
|
|
2012-07-25 17:00:46 +02:00
|
|
|
Logging::log("{$p_type} not found");
|
2012-08-21 22:54:14 +02:00
|
|
|
Application_Model_Library::changePlaylist(null, $p_type);
|
2012-02-20 18:24:04 +01:00
|
|
|
$this->createFullResponse(null);
|
|
|
|
}
|
2012-07-10 23:09:21 +02:00
|
|
|
|
2012-08-21 16:50:24 +02:00
|
|
|
private function playlistNoPermission($p_type)
|
|
|
|
{
|
2012-07-25 17:00:46 +02:00
|
|
|
$this->view->error = "You don't have permission to delete selected {$p_type}(s).";
|
2012-08-21 21:42:44 +02:00
|
|
|
$this->changePlaylist(null, $p_type);
|
|
|
|
$this->createFullResponse(null);
|
2012-07-10 23:09:21 +02:00
|
|
|
}
|
2012-02-20 18:24:04 +01:00
|
|
|
|
|
|
|
private function playlistUnknownError($e)
|
|
|
|
{
|
|
|
|
$this->view->error = "Something went wrong.";
|
|
|
|
|
|
|
|
Logging::log("{$e->getFile()}");
|
|
|
|
Logging::log("{$e->getLine()}");
|
|
|
|
Logging::log("{$e->getMessage()}");
|
|
|
|
}
|
2012-08-02 17:52:11 +02:00
|
|
|
|
2012-08-21 16:50:24 +02:00
|
|
|
private function wrongTypeToBlock($obj)
|
|
|
|
{
|
2012-08-20 23:17:48 +02:00
|
|
|
$this->view->error = "You can only add tracks to smart block.";
|
2012-08-02 17:52:11 +02:00
|
|
|
$this->createFullResponse($obj);
|
|
|
|
}
|
2012-08-17 21:56:16 +02:00
|
|
|
|
2012-08-21 16:50:24 +02:00
|
|
|
private function wrongTypeToPlaylist($obj)
|
|
|
|
{
|
2012-08-20 23:17:48 +02:00
|
|
|
$this->view->error = "You can only add tracks and smart blocks to playlists.";
|
2012-08-17 21:56:16 +02:00
|
|
|
$this->createFullResponse($obj);
|
|
|
|
}
|
2012-02-20 18:24:04 +01:00
|
|
|
|
2010-12-07 20:19:27 +01:00
|
|
|
public function newAction()
|
2012-08-08 21:29:09 +02:00
|
|
|
{
|
2012-07-25 17:00:46 +02:00
|
|
|
//$pl_sess = $this->pl_sess;
|
2012-07-11 00:53:06 +02:00
|
|
|
$userInfo = Zend_Auth::getInstance()->getStorage()->read();
|
2012-07-25 17:00:46 +02:00
|
|
|
$type = $this->_getParam('type');
|
|
|
|
|
2012-08-21 22:54:14 +02:00
|
|
|
$objInfo = Application_Model_Library::getObjInfo($type);
|
2012-07-25 17:00:46 +02:00
|
|
|
|
|
|
|
$name = 'Untitled Playlist';
|
|
|
|
if ($type == 'block') {
|
2012-08-20 23:17:48 +02:00
|
|
|
$name = 'Untitled Smart Block';
|
2012-07-25 17:00:46 +02:00
|
|
|
}
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2012-07-25 17:00:46 +02:00
|
|
|
$obj = new $objInfo['className']();
|
|
|
|
$obj->setName($name);
|
2012-08-21 22:54:14 +02:00
|
|
|
$obj->setMetadata('dc:creator', $userInfo->id);
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2012-08-21 22:54:14 +02:00
|
|
|
Application_Model_Library::changePlaylist($obj->getId(), $type);
|
2012-07-25 17:00:46 +02:00
|
|
|
$this->createFullResponse($obj);
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
2012-07-25 17:00:46 +02:00
|
|
|
|
2010-12-07 20:19:27 +01:00
|
|
|
public function editAction()
|
|
|
|
{
|
2012-02-05 18:19:22 +01:00
|
|
|
$id = $this->_getParam('id', null);
|
2012-07-25 23:08:22 +02:00
|
|
|
$type = $this->_getParam('type');
|
2012-08-21 22:54:14 +02:00
|
|
|
$objInfo = Application_Model_Library::getObjInfo($type);
|
2012-07-25 23:08:22 +02:00
|
|
|
Logging::log("editing {$type} {$id}");
|
2011-03-31 20:40:55 +02:00
|
|
|
|
2012-07-11 00:53:06 +02:00
|
|
|
if (!is_null($id)) {
|
2012-08-21 22:54:14 +02:00
|
|
|
Application_Model_Library::changePlaylist($id, $type);
|
2012-07-11 00:53:06 +02:00
|
|
|
}
|
2011-03-31 20:40:55 +02:00
|
|
|
|
2012-07-11 00:53:06 +02:00
|
|
|
try {
|
2012-07-25 23:08:22 +02:00
|
|
|
$obj = new $objInfo['className']($id);
|
|
|
|
$this->createFullResponse($obj);
|
2012-07-16 03:17:13 +02:00
|
|
|
} catch (PlaylistNotFoundException $e) {
|
2012-07-11 00:53:06 +02:00
|
|
|
$this->playlistNotFound();
|
2012-07-16 03:17:13 +02:00
|
|
|
} catch (Exception $e) {
|
2012-07-11 00:53:06 +02:00
|
|
|
$this->playlistUnknownError($e);
|
|
|
|
}
|
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;
|
2012-07-25 17:00:46 +02:00
|
|
|
$type = $this->_getParam('type');
|
|
|
|
|
|
|
|
$obj = null;
|
|
|
|
|
2012-08-21 22:54:14 +02:00
|
|
|
$objInfo = Application_Model_Library::getObjInfo($type);
|
2012-08-21 00:29:57 +02:00
|
|
|
|
|
|
|
$userInfo = Zend_Auth::getInstance()->getStorage()->read();
|
2012-07-10 23:09:21 +02:00
|
|
|
$user = new Application_Model_User($userInfo->id);
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2012-02-04 00:12:06 +01:00
|
|
|
try {
|
2012-07-25 17:00:46 +02:00
|
|
|
Logging::log("Currently active {$type} {$this->obj_sess->id}");
|
|
|
|
if (in_array($this->obj_sess->id, $ids)) {
|
|
|
|
Logging::log("Deleting currently active {$type}");
|
2012-08-21 22:54:14 +02:00
|
|
|
Application_Model_Library::changePlaylist(null, $type);
|
2012-07-16 03:17:13 +02:00
|
|
|
} else {
|
2012-07-25 17:00:46 +02:00
|
|
|
Logging::log("Not deleting currently active {$type}");
|
|
|
|
$obj = new $objInfo['className']($this->obj_sess->id);
|
2011-11-10 21:35:27 +01:00
|
|
|
}
|
2012-08-21 16:50:24 +02:00
|
|
|
|
2012-07-25 17:00:46 +02:00
|
|
|
if (strcmp($objInfo['className'], 'Application_Model_Playlist')==0) {
|
|
|
|
Application_Model_Playlist::deletePlaylists($ids, $userInfo->id);
|
|
|
|
} else {
|
|
|
|
Application_Model_Block::deleteBlocks($ids, $userInfo->id);
|
|
|
|
}
|
|
|
|
$this->createFullResponse($obj);
|
2012-08-21 00:29:57 +02:00
|
|
|
} catch (PlaylistNoPermissionException $e) {
|
2012-07-25 17:00:46 +02:00
|
|
|
$this->playlistNoPermission($type);
|
2012-08-21 21:42:44 +02:00
|
|
|
} catch (BlockNoPermissionException $e) {
|
|
|
|
$this->playlistNoPermission($type);
|
2012-08-21 00:29:57 +02:00
|
|
|
} catch (PlaylistNotFoundException $e) {
|
2012-07-25 17:00:46 +02:00
|
|
|
$this->playlistNotFound($type);
|
2012-07-16 03:17:13 +02:00
|
|
|
} catch (Exception $e) {
|
2012-02-20 18:24:04 +01:00
|
|
|
$this->playlistUnknownError($e);
|
2012-02-04 00:12:06 +01:00
|
|
|
}
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
2012-07-11 00:53:06 +02:00
|
|
|
|
2012-02-04 00:12:06 +01:00
|
|
|
public function addItemsAction()
|
2010-12-07 20:19:27 +01:00
|
|
|
{
|
2012-07-26 20:41:09 +02:00
|
|
|
$ids = $this->_getParam('aItems', array());
|
|
|
|
$ids = (!is_array($ids)) ? array($ids) : $ids;
|
2012-07-11 00:53:06 +02:00
|
|
|
$afterItem = $this->_getParam('afterItem', null);
|
|
|
|
$addType = $this->_getParam('type', 'after');
|
2012-07-26 22:16:07 +02:00
|
|
|
// this is the obj type of destination
|
2012-07-25 17:00:46 +02:00
|
|
|
$obj_type = $this->_getParam('obj_type');
|
2012-07-18 17:52:09 +02:00
|
|
|
|
2012-02-04 00:12:06 +01:00
|
|
|
try {
|
2012-07-25 17:00:46 +02:00
|
|
|
$obj = $this->getPlaylist($obj_type);
|
2012-07-26 22:16:07 +02:00
|
|
|
if ($obj_type == 'playlist') {
|
2012-08-21 16:50:24 +02:00
|
|
|
foreach ($ids as $id) {
|
2012-08-17 21:56:16 +02:00
|
|
|
if (is_array($id) && isset($id[1])) {
|
|
|
|
if ($id[1] == 'playlist') {
|
|
|
|
throw new WrongTypeToPlaylistException;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-07-26 22:16:07 +02:00
|
|
|
$obj->addAudioClips($ids, $afterItem, $addType);
|
|
|
|
} else if ($obj->isStatic()) {
|
|
|
|
// if the dest is a block object
|
2012-08-02 17:52:11 +02:00
|
|
|
//check if any items are playlists
|
2012-08-21 16:50:24 +02:00
|
|
|
foreach ($ids as $id) {
|
2012-08-09 22:59:18 +02:00
|
|
|
if (is_array($id) && isset($id[1])) {
|
|
|
|
if ($id[1] != 'audioclip') {
|
|
|
|
throw new WrongTypeToBlockException;
|
|
|
|
}
|
2012-08-02 17:52:11 +02:00
|
|
|
}
|
|
|
|
}
|
2012-07-25 17:00:46 +02:00
|
|
|
$obj->addAudioClips($ids, $afterItem, $addType);
|
2012-07-18 17:52:09 +02:00
|
|
|
} else {
|
2012-08-09 22:59:18 +02:00
|
|
|
throw new BlockDynamicException;
|
2012-07-18 17:52:09 +02:00
|
|
|
}
|
2012-07-26 22:16:07 +02:00
|
|
|
$this->createUpdateResponse($obj);
|
2012-08-21 16:50:24 +02:00
|
|
|
} catch (PlaylistOutDatedException $e) {
|
2012-07-26 22:16:07 +02:00
|
|
|
$this->playlistOutdated($e);
|
2012-08-21 16:50:24 +02:00
|
|
|
} catch (PlaylistNotFoundException $e) {
|
2012-07-26 22:16:07 +02:00
|
|
|
$this->playlistNotFound($obj_type);
|
|
|
|
}
|
2012-08-09 22:59:18 +02:00
|
|
|
catch (WrongTypeToBlockException $e) {
|
|
|
|
$this->wrongTypeToBlock($obj);
|
|
|
|
}
|
2012-08-17 21:56:16 +02:00
|
|
|
catch (WrongTypeToPlaylistException $e) {
|
|
|
|
$this->wrongTypeToPlaylist($obj);
|
|
|
|
}
|
2012-08-09 22:59:18 +02:00
|
|
|
catch (BlockDynamicException $e) {
|
|
|
|
$this->blockDynamic($obj);
|
|
|
|
}
|
2012-07-26 22:16:07 +02:00
|
|
|
catch (Exception $e) {
|
2012-08-09 22:59:18 +02:00
|
|
|
$this->playlistUnknownError($e);
|
2012-02-04 00:12:06 +01:00
|
|
|
}
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
2012-02-04 15:52:31 +01:00
|
|
|
public function moveItemsAction()
|
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);
|
2012-02-20 18:24:04 +01:00
|
|
|
$modified = $this->_getParam('modified');
|
2012-07-25 17:00:46 +02:00
|
|
|
$type = $this->_getParam('obj_type');
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2012-02-04 00:12:06 +01:00
|
|
|
try {
|
2012-07-25 17:00:46 +02:00
|
|
|
$obj = $this->getPlaylist($type);
|
|
|
|
$obj->moveAudioClips($ids, $afterItem);
|
|
|
|
$this->createUpdateResponse($obj);
|
2012-07-16 03:17:13 +02:00
|
|
|
} catch (PlaylistOutDatedException $e) {
|
2012-07-10 22:41:30 +02:00
|
|
|
$this->playlistOutdated($e);
|
2012-07-16 03:17:13 +02:00
|
|
|
} catch (PlaylistNotFoundException $e) {
|
2012-07-25 17:00:46 +02:00
|
|
|
$this->playlistNotFound($type);
|
2012-07-16 03:17:13 +02:00
|
|
|
} catch (Exception $e) {
|
2012-02-20 18:24:04 +01:00
|
|
|
$this->playlistUnknownError($e);
|
2011-11-10 21:35:27 +01:00
|
|
|
}
|
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-02-20 18:24:04 +01:00
|
|
|
$modified = $this->_getParam('modified');
|
2012-07-25 17:00:46 +02:00
|
|
|
$type = $this->_getParam('obj_type');
|
2012-01-08 05:37:37 +01:00
|
|
|
|
2012-02-04 00:12:06 +01:00
|
|
|
try {
|
2012-07-25 17:00:46 +02:00
|
|
|
$obj = $this->getPlaylist($type);
|
|
|
|
$obj->delAudioClips($ids);
|
|
|
|
$this->createUpdateResponse($obj);
|
2012-07-16 03:17:13 +02:00
|
|
|
} catch (PlaylistOutDatedException $e) {
|
2012-07-10 22:41:30 +02:00
|
|
|
$this->playlistOutdated($e);
|
2012-07-16 03:17:13 +02:00
|
|
|
} catch (PlaylistNotFoundException $e) {
|
2012-07-25 17:00:46 +02:00
|
|
|
$this->playlistNotFound($type);
|
2012-07-16 03:17:13 +02:00
|
|
|
} catch (Exception $e) {
|
2012-02-20 18:24:04 +01:00
|
|
|
$this->playlistUnknownError($e);
|
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()
|
|
|
|
{
|
2012-07-11 00:53:06 +02:00
|
|
|
$id = $this->_getParam('id');
|
|
|
|
$cueIn = $this->_getParam('cueIn', null);
|
|
|
|
$cueOut = $this->_getParam('cueOut', null);
|
2012-07-25 17:00:46 +02:00
|
|
|
$type = $this->_getParam('type');
|
2011-01-17 01:31:10 +01:00
|
|
|
|
2012-02-04 19:27:26 +01:00
|
|
|
try {
|
2012-07-25 17:00:46 +02:00
|
|
|
$obj = $this->getPlaylist($type);
|
|
|
|
$response = $obj->changeClipLength($id, $cueIn, $cueOut);
|
2011-01-17 01:31:10 +01:00
|
|
|
|
2012-02-20 18:24:04 +01:00
|
|
|
if (!isset($response["error"])) {
|
|
|
|
$this->view->response = $response;
|
2012-07-25 17:00:46 +02:00
|
|
|
$this->createUpdateResponse($obj);
|
2012-07-16 03:17:13 +02:00
|
|
|
} else {
|
2012-02-20 18:24:04 +01:00
|
|
|
$this->view->cue_error = $response["error"];
|
|
|
|
}
|
2012-07-16 03:17:13 +02:00
|
|
|
} catch (PlaylistOutDatedException $e) {
|
2012-07-10 22:41:30 +02:00
|
|
|
$this->playlistOutdated($e);
|
2012-07-16 03:17:13 +02:00
|
|
|
} catch (PlaylistNotFoundException $e) {
|
2012-07-25 17:00:46 +02:00
|
|
|
$this->playlistNotFound($type);
|
2012-07-16 03:17:13 +02:00
|
|
|
} catch (Exception $e) {
|
2012-02-20 18:24:04 +01:00
|
|
|
$this->playlistUnknownError($e);
|
2012-02-04 19:27:26 +01:00
|
|
|
}
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function setFadeAction()
|
|
|
|
{
|
2012-07-11 00:53:06 +02:00
|
|
|
$id = $this->_getParam('id');
|
|
|
|
$fadeIn = $this->_getParam('fadeIn', null);
|
|
|
|
$fadeOut = $this->_getParam('fadeOut', null);
|
2012-07-25 17:00:46 +02:00
|
|
|
$type = $this->_getParam('type');
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2012-02-05 23:38:12 +01:00
|
|
|
try {
|
2012-07-25 17:00:46 +02:00
|
|
|
$obj = $this->getPlaylist($type);
|
|
|
|
$response = $obj->changeFadeInfo($id, $fadeIn, $fadeOut);
|
2011-01-17 19:55:43 +01:00
|
|
|
|
2012-02-05 23:38:12 +01:00
|
|
|
if (!isset($response["error"])) {
|
2012-07-25 17:00:46 +02:00
|
|
|
$this->createUpdateResponse($obj);
|
2012-02-20 18:24:04 +01:00
|
|
|
$this->view->response = $response;
|
2012-07-16 03:17:13 +02:00
|
|
|
} else {
|
2012-02-20 18:24:04 +01:00
|
|
|
$this->view->fade_error = $response["error"];
|
|
|
|
}
|
2012-07-16 03:17:13 +02:00
|
|
|
} catch (PlaylistOutDatedException $e) {
|
2012-07-10 22:41:30 +02:00
|
|
|
$this->playlistOutdated($e);
|
2012-07-16 03:17:13 +02:00
|
|
|
} catch (PlaylistNotFoundException $e) {
|
2012-07-25 17:00:46 +02:00
|
|
|
$this->playlistNotFound($type);
|
2012-07-16 03:17:13 +02:00
|
|
|
} catch (Exception $e) {
|
2012-02-20 18:24:04 +01:00
|
|
|
$this->playlistUnknownError($e);
|
2011-11-29 15:30:05 +01:00
|
|
|
}
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
2012-02-05 23:38:12 +01:00
|
|
|
public function getPlaylistFadesAction()
|
2010-12-07 20:19:27 +01:00
|
|
|
{
|
2012-07-25 17:00:46 +02:00
|
|
|
$type = $this->_getParam('type');
|
2012-02-05 23:38:12 +01:00
|
|
|
try {
|
2012-07-25 17:00:46 +02:00
|
|
|
$obj = $this->getPlaylist($type);
|
|
|
|
$fades = $obj->getFadeInfo(0);
|
2012-02-05 23:38:12 +01:00
|
|
|
$this->view->fadeIn = $fades[0];
|
2010-12-30 00:43:17 +01:00
|
|
|
|
2012-07-25 17:00:46 +02:00
|
|
|
$fades = $obj->getFadeInfo($obj->getSize()-1);
|
2012-02-05 23:38:12 +01:00
|
|
|
$this->view->fadeOut = $fades[1];
|
2012-07-16 03:17:13 +02:00
|
|
|
} catch (PlaylistOutDatedException $e) {
|
2012-07-10 22:41:30 +02:00
|
|
|
$this->playlistOutdated($e);
|
2012-07-16 03:17:13 +02:00
|
|
|
} catch (PlaylistNotFoundException $e) {
|
2012-07-25 17:00:46 +02:00
|
|
|
$this->playlistNotFound($type);
|
2012-07-16 03:17:13 +02:00
|
|
|
} catch (Exception $e) {
|
2012-02-20 18:24:04 +01:00
|
|
|
$this->playlistUnknownError($e);
|
2011-11-10 21:35:27 +01:00
|
|
|
}
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
2012-02-04 00:19:13 +01:00
|
|
|
/**
|
|
|
|
* The playlist fades are stored in the elements themselves.
|
|
|
|
* The fade in is set to the first elements fade in and
|
2012-03-19 14:09:05 +01:00
|
|
|
* the fade out is set to the last elements fade out.
|
2012-02-04 00:19:13 +01:00
|
|
|
**/
|
2011-02-08 22:10:48 +01:00
|
|
|
public function setPlaylistFadesAction()
|
|
|
|
{
|
2012-07-11 00:53:06 +02:00
|
|
|
$fadeIn = $this->_getParam('fadeIn', null);
|
|
|
|
$fadeOut = $this->_getParam('fadeOut', null);
|
2012-07-25 17:00:46 +02:00
|
|
|
$type = $this->_getParam('type');
|
2011-02-08 22:10:48 +01:00
|
|
|
|
2012-02-05 23:38:12 +01:00
|
|
|
try {
|
2012-07-25 17:00:46 +02:00
|
|
|
$obj = $this->getPlaylist($type);
|
2012-07-30 23:18:33 +02:00
|
|
|
$obj->setfades($fadeIn, $fadeOut);
|
2012-07-25 17:00:46 +02:00
|
|
|
$this->view->modified = $obj->getLastModified("U");
|
2012-07-16 03:17:13 +02:00
|
|
|
} catch (PlaylistOutDatedException $e) {
|
2012-07-10 22:41:30 +02:00
|
|
|
$this->playlistOutdated($e);
|
2012-07-16 03:17:13 +02:00
|
|
|
} catch (PlaylistNotFoundException $e) {
|
2012-07-25 17:00:46 +02:00
|
|
|
$this->playlistNotFound($type);
|
2012-07-16 03:17:13 +02:00
|
|
|
} catch (Exception $e) {
|
2012-02-20 18:24:04 +01:00
|
|
|
$this->playlistUnknownError($e);
|
2012-02-05 23:38:12 +01:00
|
|
|
}
|
2011-02-08 22:10:48 +01:00
|
|
|
}
|
|
|
|
|
2012-08-09 23:23:52 +02:00
|
|
|
public function setPlaylistNameDescAction()
|
2011-05-17 23:30:17 +02:00
|
|
|
{
|
|
|
|
$name = $this->_getParam('name', 'Unknown Playlist');
|
2012-08-09 23:23:52 +02:00
|
|
|
$description = $this->_getParam('description', "");
|
2012-07-25 17:00:46 +02:00
|
|
|
$type = $this->_getParam('type');
|
|
|
|
|
2012-02-20 18:24:04 +01:00
|
|
|
try {
|
2012-07-25 17:00:46 +02:00
|
|
|
$obj = $this->getPlaylist($type);
|
|
|
|
$obj->setName($name);
|
2012-08-09 23:23:52 +02:00
|
|
|
$obj->setDescription($description);
|
2012-08-16 22:00:59 +02:00
|
|
|
$this->view->description = $description;
|
2012-02-20 18:24:04 +01:00
|
|
|
$this->view->playlistName = $name;
|
2012-07-25 17:00:46 +02:00
|
|
|
$this->view->modified = $obj->getLastModified("U");
|
2012-07-16 03:17:13 +02:00
|
|
|
} catch (PlaylistOutDatedException $e) {
|
2012-07-10 22:41:30 +02:00
|
|
|
$this->playlistOutdated($e);
|
2012-07-16 03:17:13 +02:00
|
|
|
} catch (PlaylistNotFoundException $e) {
|
2012-07-25 17:00:46 +02:00
|
|
|
$this->playlistNotFound($type);
|
2012-07-16 03:17:13 +02:00
|
|
|
} catch (Exception $e) {
|
2012-02-20 18:24:04 +01:00
|
|
|
$this->playlistUnknownError($e);
|
2011-11-10 21:35:27 +01:00
|
|
|
}
|
2011-05-17 23:30:17 +02:00
|
|
|
}
|
2012-07-11 22:14:11 +02:00
|
|
|
|
2012-08-09 23:23:52 +02:00
|
|
|
public function saveAction()
|
2012-07-11 22:14:11 +02:00
|
|
|
{
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$params = $request->getPost();
|
2012-08-09 23:23:52 +02:00
|
|
|
$result = array();
|
|
|
|
|
|
|
|
$this->setPlaylistNameDescAction();
|
|
|
|
|
|
|
|
if ($params['type'] == 'block') {
|
2012-08-21 00:29:57 +02:00
|
|
|
$form = new Application_Form_SmartBlockCriteria();
|
2012-08-15 17:36:41 +02:00
|
|
|
$form->startForm($params['obj_id']);
|
2012-08-21 00:29:57 +02:00
|
|
|
$bl = new Application_Model_Block($params['obj_id']);
|
2012-08-15 17:36:41 +02:00
|
|
|
if ($form->isValid($params)) {
|
2012-08-16 21:40:36 +02:00
|
|
|
$bl->saveSmartBlockCriteria($params['data']);
|
2012-08-15 17:36:41 +02:00
|
|
|
$result['html'] = $this->createFullResponse($bl, true);
|
|
|
|
$result['result'] = 0;
|
|
|
|
} else {
|
2012-08-21 00:29:57 +02:00
|
|
|
$this->view->obj = $bl;
|
2012-08-15 17:36:41 +02:00
|
|
|
$this->view->id = $bl->getId();
|
|
|
|
$this->view->form = $form;
|
2012-08-21 00:29:57 +02:00
|
|
|
$viewPath = 'playlist/smart-block.phtml';
|
2012-08-15 17:36:41 +02:00
|
|
|
$result['html'] = $this->view->render($viewPath);
|
|
|
|
$result['result'] = 1;
|
|
|
|
}
|
2012-08-09 23:23:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$result["modified"] = $this->view->modified;
|
2012-07-12 23:58:44 +02:00
|
|
|
die(json_encode($result));
|
2012-07-11 22:14:11 +02:00
|
|
|
}
|
|
|
|
|
2012-08-21 00:29:57 +02:00
|
|
|
public function smartBlockGenerateAction()
|
|
|
|
{
|
|
|
|
$request = $this->getRequest();
|
2012-07-11 22:14:11 +02:00
|
|
|
$params = $request->getPost();
|
2012-08-21 00:29:57 +02:00
|
|
|
$form = new Application_Form_SmartBlockCriteria();
|
2012-08-15 17:36:41 +02:00
|
|
|
$form->startForm($params['obj_id']);
|
2012-07-25 18:44:37 +02:00
|
|
|
$bl = new Application_Model_Block($params['obj_id']);
|
2012-08-15 17:36:41 +02:00
|
|
|
if ($form->isValid($params)) {
|
|
|
|
$result = $bl->generateSmartBlock($params['data']);
|
2012-07-16 23:18:37 +02:00
|
|
|
try {
|
2012-07-25 18:44:37 +02:00
|
|
|
die(json_encode(array("result"=>0, "html"=>$this->createFullResponse($bl, true))));
|
2012-08-21 16:50:24 +02:00
|
|
|
} catch (PlaylistNotFoundException $e) {
|
2012-07-25 17:00:46 +02:00
|
|
|
$this->playlistNotFound('block');
|
2012-08-21 16:50:24 +02:00
|
|
|
} catch (Exception $e) {
|
2012-07-16 23:18:37 +02:00
|
|
|
$this->playlistUnknownError($e);
|
|
|
|
}
|
2012-08-21 16:50:24 +02:00
|
|
|
} else {
|
2012-08-21 00:29:57 +02:00
|
|
|
$this->view->obj = $bl;
|
|
|
|
$this->view->id = $bl->getId();
|
|
|
|
$this->view->form = $form;
|
|
|
|
$viewPath = 'playlist/smart-block.phtml';
|
2012-08-15 17:36:41 +02:00
|
|
|
$result['html'] = $this->view->render($viewPath);
|
|
|
|
$result['result'] = 1;
|
2012-07-16 23:18:37 +02:00
|
|
|
die(json_encode($result));
|
2012-08-21 00:29:57 +02:00
|
|
|
}
|
2012-07-12 23:58:44 +02:00
|
|
|
}
|
|
|
|
|
2012-07-25 18:44:37 +02:00
|
|
|
public function smartBlockShuffleAction()
|
2012-07-18 17:52:09 +02:00
|
|
|
{
|
2012-08-21 00:29:57 +02:00
|
|
|
$request = $this->getRequest();
|
2012-07-18 17:52:09 +02:00
|
|
|
$params = $request->getPost();
|
2012-08-10 17:56:01 +02:00
|
|
|
$bl = new Application_Model_Block($params['obj_id']);
|
2012-08-15 17:36:41 +02:00
|
|
|
$result = $bl->shuffleSmartBlock();
|
2012-08-21 00:29:57 +02:00
|
|
|
|
|
|
|
if ($result['result'] == 0) {
|
|
|
|
try {
|
|
|
|
die(json_encode(array("result"=>0, "html"=>$this->createFullResponse($bl, true))));
|
2012-08-21 16:50:24 +02:00
|
|
|
} catch (PlaylistNotFoundException $e) {
|
2012-08-21 00:29:57 +02:00
|
|
|
$this->playlistNotFound('block');
|
|
|
|
}
|
2012-08-21 16:50:24 +02:00
|
|
|
} else {
|
2012-08-21 00:29:57 +02:00
|
|
|
die(json_encode($result));
|
2012-07-18 17:52:09 +02:00
|
|
|
}
|
2012-07-11 22:14:11 +02:00
|
|
|
}
|
2012-07-24 18:12:47 +02:00
|
|
|
|
2012-08-21 16:50:24 +02:00
|
|
|
public function getBlockInfoAction()
|
|
|
|
{
|
2012-08-21 00:29:57 +02:00
|
|
|
$request = $this->getRequest();
|
2012-07-30 23:18:33 +02:00
|
|
|
$params = $request->getPost();
|
|
|
|
$bl = new Application_Model_Block($params['id']);
|
|
|
|
if ($bl->isStatic()) {
|
|
|
|
$out = $bl->getContents();
|
|
|
|
$out['isStatic'] = true;
|
|
|
|
} else {
|
2012-07-31 00:21:27 +02:00
|
|
|
$out = $bl->getCriteria();
|
2012-07-30 23:18:33 +02:00
|
|
|
$out['isStatic'] = false;
|
|
|
|
}
|
|
|
|
die(json_encode($out));
|
|
|
|
}
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
2012-08-09 22:59:18 +02:00
|
|
|
class WrongTypeToBlockException extends Exception {}
|
2012-08-17 21:56:16 +02:00
|
|
|
class WrongTypeToPlaylistException extends Exception {}
|
2012-08-09 22:59:18 +02:00
|
|
|
class BlockDynamicException extends Exception {}
|