CC-84: Smart Playlists

- changed playlist controller to also handle Blocks
- created new view for smart blocks
This commit is contained in:
denise 2012-07-25 11:00:46 -04:00
parent c79110644d
commit 722e470f6f
11 changed files with 349 additions and 184 deletions

View file

@ -36,7 +36,9 @@ define('UI_MDATA_VALUE_FORMAT_FILE', 'File');
define('UI_MDATA_VALUE_FORMAT_STREAM', 'live stream'); define('UI_MDATA_VALUE_FORMAT_STREAM', 'live stream');
// Session Keys // Session Keys
define('UI_PLAYLIST_SESSNAME', 'PLAYLIST'); define('UI_PLAYLISTCONTROLLER_OBJ_SESSNAME', 'PLAYLISTCONTROLLER_OBJ');
/*define('UI_PLAYLIST_SESSNAME', 'PLAYLIST');
define('UI_BLOCK_SESSNAME', 'BLOCK');*/
// Soundcloud contants // Soundcloud contants

View file

@ -7,7 +7,7 @@ require_once 'formatters/BitrateFormatter.php';
class LibraryController extends Zend_Controller_Action class LibraryController extends Zend_Controller_Action
{ {
protected $pl_sess = null; protected $obj_sess = null;
protected $search_sess = null; protected $search_sess = null;
public function init() public function init()
@ -23,7 +23,7 @@ class LibraryController extends Zend_Controller_Action
->addActionContext('set-num-entries', 'json') ->addActionContext('set-num-entries', 'json')
->initContext(); ->initContext();
$this->pl_sess = new Zend_Session_Namespace(UI_PLAYLIST_SESSNAME); $this->obj_sess = new Zend_Session_Namespace(UI_PLAYLISTCONTROLLER_OBJ_SESSNAME);
$this->search_sess = new Zend_Session_Namespace("search"); $this->search_sess = new Zend_Session_Namespace("search");
} }
@ -49,9 +49,9 @@ class LibraryController extends Zend_Controller_Action
$file = Application_Model_StoredFile::Recall($id); $file = Application_Model_StoredFile::Recall($id);
if (isset($this->pl_sess->id) && $screen == "playlist") { if (isset($this->obj_sess->id) && $screen == "playlist") {
// if the user is not admin or pm, check the creator and see if this person owns the playlist // if the user is not admin or pm, check the creator and see if this person owns the playlist
$playlist = new Application_Model_Playlist($this->pl_sess->id); $playlist = new Application_Model_Playlist($this->obj_sess->id);
if ($isAdminOrPM || $playlist->getCreatorId() == $user->getId()) { if ($isAdminOrPM || $playlist->getCreatorId() == $user->getId()) {
$menu["pl_add"] = array("name"=> "Add to Playlist", "icon" => "add-playlist", "icon" => "copy"); $menu["pl_add"] = array("name"=> "Add to Playlist", "icon" => "add-playlist", "icon" => "copy");
} }
@ -65,7 +65,7 @@ class LibraryController extends Zend_Controller_Action
$menu["download"] = array("name" => "Download", "icon" => "download", "url" => $url); $menu["download"] = array("name" => "Download", "icon" => "download", "url" => $url);
} elseif ($type === "playlist") { } elseif ($type === "playlist") {
$playlist = new Application_Model_Playlist($id); $playlist = new Application_Model_Playlist($id);
if ($this->pl_sess->id !== $id && $screen == "playlist") { if ($this->obj_sess->id !== $id && $screen == "playlist") {
if ($isAdminOrPM || $playlist->getCreatorId() == $user->getId()) { if ($isAdminOrPM || $playlist->getCreatorId() == $user->getId()) {
$menu["edit"] = array("name"=> "Edit", "icon" => "edit"); $menu["edit"] = array("name"=> "Edit", "icon" => "edit");
} }

View file

@ -2,7 +2,9 @@
class PlaylistController extends Zend_Controller_Action class PlaylistController extends Zend_Controller_Action
{ {
protected $pl_sess = null; /*protected $pl_sess = null;
protected $bl_sess = null;*/
protected $obj_sess = null;
public function init() public function init()
{ {
@ -25,78 +27,95 @@ class PlaylistController extends Zend_Controller_Action
->addActionContext('smart-playlist-criteria-save', 'json') ->addActionContext('smart-playlist-criteria-save', 'json')
->addActionContext('smart-playlist-generate', 'json') ->addActionContext('smart-playlist-generate', 'json')
->addActionContext('smart-playlist-shuffle', 'json') ->addActionContext('smart-playlist-shuffle', 'json')
->addActionContext('new-block', 'json')
->initContext(); ->initContext();
$this->pl_sess = new Zend_Session_Namespace(UI_PLAYLIST_SESSNAME); /*$this->pl_sess = new Zend_Session_Namespace(UI_PLAYLIST_SESSNAME);
$this->bl_sess = new Zend_Session_Namespace(UI_BLOCK_SESSNAME);*/
$this->obj_sess = new Zend_Session_Namespace(UI_PLAYLISTCONTROLLER_OBJ_SESSNAME);
} }
private function getPlaylist() private function getPlaylist($p_type)
{ {
$pl = null; $obj = null;
if (isset($this->pl_sess->id)) { $objInfo = $this->getObjInfo($p_type);
$pl = new Application_Model_Playlist($this->pl_sess->id);
if (isset($this->obj_sess->id)) {
$obj = new $objInfo['className']($this->obj_sess->id);
$modified = $this->_getParam('modified', null); $modified = $this->_getParam('modified', null);
if ($pl->getLastModified("U") !== $modified) { if ($obj->getLastModified("U") !== $modified) {
$this->createFullResponse($pl); $this->createFullResponse($obj);
throw new PlaylistOutDatedException("You are viewing an older version of {$pl->getName()}"); throw new PlaylistOutDatedException("You are viewing an older version of {$obj->getName()}");
} }
} }
return $pl; return $obj;
} }
private function changePlaylist($pl_id) private function changePlaylist($p_id, $p_type)
{ {
if (is_null($pl_id)) { if (is_null($p_id) || is_null($p_type)) {
unset($this->pl_sess->id); unset($this->obj_sess->id);
unset($this->obj_sess->type);
} else { } else {
$this->pl_sess->id = intval($pl_id); $this->obj_sess->id = intval($p_id);
$this->obj_sess->type = $p_type;
} }
} }
private function createUpdateResponse($pl) private function createUpdateResponse($obj)
{ {
$formatter = new LengthFormatter($pl->getLength()); $formatter = new LengthFormatter($obj->getLength());
$this->view->length = $formatter->format(); $this->view->length = $formatter->format();
$this->view->pl = $pl; $this->view->obj = $obj;
$this->view->html = $this->view->render('playlist/update.phtml'); $this->view->html = $this->view->render('playlist/update.phtml');
$this->view->name = $pl->getName(); $this->view->name = $obj->getName();
$this->view->description = $pl->getDescription(); $this->view->description = $obj->getDescription();
$this->view->modified = $pl->getLastModified("U"); $this->view->modified = $obj->getLastModified("U");
unset($this->view->pl); unset($this->view->obj);
} }
private function createFullResponse($pl = null, $isJson = false) private function createFullResponse($obj = null, $isJson = false)
{ {
if (isset($pl)) { $isBlock = false;
$formatter = new LengthFormatter($pl->getLength()); $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());
$this->view->length = $formatter->format(); $this->view->length = $formatter->format();
$form = new Application_Form_SmartPlaylistCriteria(); if ($isBlock) {
$form = new Application_Form_SmartBlockCriteria();
$form->removeDecorator('DtDdWrapper'); $form->removeDecorator('DtDdWrapper');
$form->startForm($pl->getId()); $form->startForm($obj->getId());
$this->view->form = $form; $this->view->form = $form;
$this->view->pl = $pl;
$this->view->id = $pl->getId();
if ($isJson){
return $this->view->render('playlist/playlist.phtml');
}else{
$this->view->html = $this->view->render('playlist/playlist.phtml');
} }
unset($this->view->pl);
if ($isBlock){
$this->view->obj = $obj;
$this->view->id = $obj->getId();
if ($isJson) {
return $this->view->render($viewPath);
} else {
$this->view->html = $this->view->render($viewPath);
}
}else{
$this->view->obj = $obj;
$this->view->id = $obj->getId();
$this->view->html = $this->view->render($viewPath);
unset($this->view->obj);
}
} }
else { else {
if ($isJson){ $this->view->html = $this->view->render($viewPath);
return $this->view->render('playlist/playlist.phtml');
}else{
$this->view->html = $this->view->render('playlist/playlist.phtml');
}
} }
} }
@ -105,23 +124,23 @@ class PlaylistController extends Zend_Controller_Action
$this->view->error = $e->getMessage(); $this->view->error = $e->getMessage();
} }
private function playlistDynamic($pl) private function playlistDynamic($obj)
{ {
$this->view->error = "You cannot add tracks to dynamic playlist."; $this->view->error = "You cannot add tracks to dynamic playlist.";
$this->createFullResponse($pl); $this->createFullResponse($obj);
} }
private function playlistNotFound() private function playlistNotFound($p_type)
{ {
$this->view->error = "Playlist not found"; $this->view->error = "{$p_type} not found";
Logging::log("Playlist not found"); Logging::log("{$p_type} not found");
$this->changePlaylist(null); $this->changePlaylist(null, $p_type);
$this->createFullResponse(null); $this->createFullResponse(null);
} }
private function playlistNoPermission(){ private function playlistNoPermission($p_type){
$this->view->error = "You don't have permission to delete selected playlist(s)."; $this->view->error = "You don't have permission to delete selected {$p_type}(s).";
} }
private function playlistUnknownError($e) private function playlistUnknownError($e)
@ -164,20 +183,21 @@ class PlaylistController extends Zend_Controller_Action
$this->view->headLink()->appendStylesheet($baseUrl.'/css/playlist_builder.css?'.$CC_CONFIG['airtime_version']); $this->view->headLink()->appendStylesheet($baseUrl.'/css/playlist_builder.css?'.$CC_CONFIG['airtime_version']);
try { try {
if (isset($this->pl_sess->id)) { if (isset($this->obj_sess->id)) {
$pl = new Application_Model_Playlist($this->pl_sess->id); $objInfo = $this->getObjInfo($this->obj_sess->type);
$obj = new $objInfo['className']($this->obj_sess->id);
$userInfo = Zend_Auth::getInstance()->getStorage()->read(); $userInfo = Zend_Auth::getInstance()->getStorage()->read();
$user = new Application_Model_User($userInfo->id); $user = new Application_Model_User($userInfo->id);
$isAdminOrPM = $user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER)); $isAdminOrPM = $user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER));
if($isAdminOrPM || $pl->getCreatorId() == $userInfo->id){ if($isAdminOrPM || $obj->getCreatorId() == $userInfo->id){
$this->view->pl = $pl; $this->view->obj = $obj;
$form = new Application_Form_SmartPlaylistCriteria(); //$form = new Application_Form_SmartBlockCriteria();
$form->startForm($this->pl_sess->id); //$form->startForm($this->pl_sess->id);
$this->view->form = $form; //$this->view->form = $form;
} }
$formatter = new LengthFormatter($pl->getLength()); $formatter = new LengthFormatter($obj->getLength());
$this->view->length = $formatter->format(); $this->view->length = $formatter->format();
} }
} catch (PlaylistNotFoundException $e) { } catch (PlaylistNotFoundException $e) {
@ -189,26 +209,45 @@ class PlaylistController extends Zend_Controller_Action
public function newAction() public function newAction()
{ {
$pl_sess = $this->pl_sess; //$pl_sess = $this->pl_sess;
$userInfo = Zend_Auth::getInstance()->getStorage()->read();
$type = $this->_getParam('type');
$objInfo = $this->getObjInfo($type);
$name = 'Untitled Playlist';
if ($type == 'block') {
$name = 'Untitled Smart Block';
}
$obj = new $objInfo['className']();
$obj->setName($name);
$obj->setMetaData('dc:creator', $userInfo->id);
$this->changePlaylist($obj->getId(), $type);
$this->createFullResponse($obj);
}
/*public function newBlockAction()
{
$bl_sess = $this->bl_sess;
$userInfo = Zend_Auth::getInstance()->getStorage()->read(); $userInfo = Zend_Auth::getInstance()->getStorage()->read();
$pl = new Application_Model_Playlist(); $bl = new Application_Model_Block();
$pl->setName("Untitled Playlist"); $bl->setName("Untitled Smart Block");
$pl->setPLMetaData('dc:creator', $userInfo->id); $bl->setBLMetaData('dc:creator', $userInfo->id);
$this->changePlaylist($pl->getId()); $this->changePlaylist($bl->getId(), 'block');
$this->createFullResponse($pl); $this->createFullResponse($bl);
} }*/
public function editAction() public function editAction()
{ {
$id = $this->_getParam('id', null); $id = $this->_getParam('id', null);
Logging::log("editing playlist {$id}"); Logging::log("editing playlist {$id}");
//$form = new Application_Form_SmartPlaylist();
if (!is_null($id)) { if (!is_null($id)) {
$this->changePlaylist($id); $this->changePlaylist($id, 'playlist');
} }
try { try {
@ -225,30 +264,37 @@ class PlaylistController extends Zend_Controller_Action
{ {
$ids = $this->_getParam('ids'); $ids = $this->_getParam('ids');
$ids = (!is_array($ids)) ? array($ids) : $ids; $ids = (!is_array($ids)) ? array($ids) : $ids;
$pl = null; $type = $this->_getParam('type');
$obj = null;
$objInfo = $this->getObjInfo($type);
$userInfo = Zend_Auth::getInstance()->getStorage()->read(); $userInfo = Zend_Auth::getInstance()->getStorage()->read();
$user = new Application_Model_User($userInfo->id); $user = new Application_Model_User($userInfo->id);
try { try {
Logging::log("Currently active playlist {$this->pl_sess->id}"); Logging::log("Currently active {$type} {$this->obj_sess->id}");
if (in_array($this->pl_sess->id, $ids)) { if (in_array($this->obj_sess->id, $ids)) {
Logging::log("Deleting currently active playlist"); Logging::log("Deleting currently active {$type}");
$this->changePlaylist(null); $this->changePlaylist(null, $type);
} else { } else {
Logging::log("Not deleting currently active playlist"); Logging::log("Not deleting currently active {$type}");
$pl = new Application_Model_Playlist($this->pl_sess->id); $obj = new $objInfo['className']($this->obj_sess->id);
} }
if (strcmp($objInfo['className'], 'Application_Model_Playlist')==0) {
Application_Model_Playlist::deletePlaylists($ids, $userInfo->id); Application_Model_Playlist::deletePlaylists($ids, $userInfo->id);
$this->createFullResponse($pl); } else {
Application_Model_Block::deleteBlocks($ids, $userInfo->id);
}
$this->createFullResponse($obj);
} }
catch (PlaylistNoPermissionException $e) { catch (PlaylistNoPermissionException $e) {
$this->playlistNoPermission(); $this->playlistNoPermission($type);
} }
catch (PlaylistNotFoundException $e) { catch (PlaylistNotFoundException $e) {
$this->playlistNotFound(); $this->playlistNotFound($type);
} catch (Exception $e) { } catch (Exception $e) {
$this->playlistUnknownError($e); $this->playlistUnknownError($e);
} }
@ -260,24 +306,25 @@ class PlaylistController extends Zend_Controller_Action
$ids = (!is_array($ids)) ? array($ids) : $ids; $ids = (!is_array($ids)) ? array($ids) : $ids;
$afterItem = $this->_getParam('afterItem', null); $afterItem = $this->_getParam('afterItem', null);
$addType = $this->_getParam('type', 'after'); $addType = $this->_getParam('type', 'after');
$obj_type = $this->_getParam('obj_type');
try { try {
$pl = $this->getPlaylist(); $obj = $this->getPlaylist($obj_type);
if ($pl->isStatic()) { if ($obj_type == 'playlist' || $obj->isStatic()) {
$pl->addAudioClips($ids, $afterItem, $addType); $obj->addAudioClips($ids, $afterItem, $addType);
$this->createUpdateResponse($pl); $this->createUpdateResponse($obj);
} else { } else {
throw new PlaylistDyanmicException; throw new PlaylistDyanmicException;
} }
} }
catch (PlaylistOutDatedException $e) { catch (PlaylistOutDatedException $e) {
$this->playlistOutdated($pl, $e); $this->playlistOutdated($obj, $e);
} }
catch (PlaylistNotFoundException $e) { catch (PlaylistNotFoundException $e) {
$this->playlistNotFound(); $this->playlistNotFound($obj_type);
} }
catch (PlaylistDyanmicException $e) { catch (PlaylistDyanmicException $e) {
$this->playlistDynamic($pl); $this->playlistDynamic($obj);
} }
catch (Exception $e) { catch (Exception $e) {
$this->playlistUnknownError($e); $this->playlistUnknownError($e);
@ -290,15 +337,16 @@ class PlaylistController extends Zend_Controller_Action
$ids = (!is_array($ids)) ? array($ids) : $ids; $ids = (!is_array($ids)) ? array($ids) : $ids;
$afterItem = $this->_getParam('afterItem', null); $afterItem = $this->_getParam('afterItem', null);
$modified = $this->_getParam('modified'); $modified = $this->_getParam('modified');
$type = $this->_getParam('obj_type');
try { try {
$pl = $this->getPlaylist(); $obj = $this->getPlaylist($type);
$pl->moveAudioClips($ids, $afterItem); $obj->moveAudioClips($ids, $afterItem);
$this->createUpdateResponse($pl); $this->createUpdateResponse($obj);
} catch (PlaylistOutDatedException $e) { } catch (PlaylistOutDatedException $e) {
$this->playlistOutdated($e); $this->playlistOutdated($e);
} catch (PlaylistNotFoundException $e) { } catch (PlaylistNotFoundException $e) {
$this->playlistNotFound(); $this->playlistNotFound($type);
} catch (Exception $e) { } catch (Exception $e) {
$this->playlistUnknownError($e); $this->playlistUnknownError($e);
} }
@ -309,15 +357,16 @@ class PlaylistController extends Zend_Controller_Action
$ids = $this->_getParam('ids'); $ids = $this->_getParam('ids');
$ids = (!is_array($ids)) ? array($ids) : $ids; $ids = (!is_array($ids)) ? array($ids) : $ids;
$modified = $this->_getParam('modified'); $modified = $this->_getParam('modified');
$type = $this->_getParam('obj_type');
try { try {
$pl = $this->getPlaylist(); $obj = $this->getPlaylist($type);
$pl->delAudioClips($ids); $obj->delAudioClips($ids);
$this->createUpdateResponse($pl); $this->createUpdateResponse($obj);
} catch (PlaylistOutDatedException $e) { } catch (PlaylistOutDatedException $e) {
$this->playlistOutdated($e); $this->playlistOutdated($e);
} catch (PlaylistNotFoundException $e) { } catch (PlaylistNotFoundException $e) {
$this->playlistNotFound(); $this->playlistNotFound($type);
} catch (Exception $e) { } catch (Exception $e) {
$this->playlistUnknownError($e); $this->playlistUnknownError($e);
} }
@ -328,21 +377,22 @@ class PlaylistController extends Zend_Controller_Action
$id = $this->_getParam('id'); $id = $this->_getParam('id');
$cueIn = $this->_getParam('cueIn', null); $cueIn = $this->_getParam('cueIn', null);
$cueOut = $this->_getParam('cueOut', null); $cueOut = $this->_getParam('cueOut', null);
$type = $this->_getParam('type');
try { try {
$pl = $this->getPlaylist(); $obj = $this->getPlaylist($type);
$response = $pl->changeClipLength($id, $cueIn, $cueOut); $response = $obj->changeClipLength($id, $cueIn, $cueOut);
if (!isset($response["error"])) { if (!isset($response["error"])) {
$this->view->response = $response; $this->view->response = $response;
$this->createUpdateResponse($pl); $this->createUpdateResponse($obj);
} else { } else {
$this->view->cue_error = $response["error"]; $this->view->cue_error = $response["error"];
} }
} catch (PlaylistOutDatedException $e) { } catch (PlaylistOutDatedException $e) {
$this->playlistOutdated($e); $this->playlistOutdated($e);
} catch (PlaylistNotFoundException $e) { } catch (PlaylistNotFoundException $e) {
$this->playlistNotFound(); $this->playlistNotFound($type);
} catch (Exception $e) { } catch (Exception $e) {
$this->playlistUnknownError($e); $this->playlistUnknownError($e);
} }
@ -353,13 +403,14 @@ class PlaylistController extends Zend_Controller_Action
$id = $this->_getParam('id'); $id = $this->_getParam('id');
$fadeIn = $this->_getParam('fadeIn', null); $fadeIn = $this->_getParam('fadeIn', null);
$fadeOut = $this->_getParam('fadeOut', null); $fadeOut = $this->_getParam('fadeOut', null);
$type = $this->_getParam('type');
try { try {
$pl = $this->getPlaylist(); $obj = $this->getPlaylist($type);
$response = $pl->changeFadeInfo($id, $fadeIn, $fadeOut); $response = $obj->changeFadeInfo($id, $fadeIn, $fadeOut);
if (!isset($response["error"])) { if (!isset($response["error"])) {
$this->createUpdateResponse($pl); $this->createUpdateResponse($obj);
$this->view->response = $response; $this->view->response = $response;
} else { } else {
$this->view->fade_error = $response["error"]; $this->view->fade_error = $response["error"];
@ -367,7 +418,7 @@ class PlaylistController extends Zend_Controller_Action
} catch (PlaylistOutDatedException $e) { } catch (PlaylistOutDatedException $e) {
$this->playlistOutdated($e); $this->playlistOutdated($e);
} catch (PlaylistNotFoundException $e) { } catch (PlaylistNotFoundException $e) {
$this->playlistNotFound(); $this->playlistNotFound($type);
} catch (Exception $e) { } catch (Exception $e) {
$this->playlistUnknownError($e); $this->playlistUnknownError($e);
} }
@ -375,17 +426,18 @@ class PlaylistController extends Zend_Controller_Action
public function getPlaylistFadesAction() public function getPlaylistFadesAction()
{ {
$type = $this->_getParam('type');
try { try {
$pl = $this->getPlaylist(); $obj = $this->getPlaylist($type);
$fades = $pl->getFadeInfo(0); $fades = $obj->getFadeInfo(0);
$this->view->fadeIn = $fades[0]; $this->view->fadeIn = $fades[0];
$fades = $pl->getFadeInfo($pl->getSize()-1); $fades = $obj->getFadeInfo($obj->getSize()-1);
$this->view->fadeOut = $fades[1]; $this->view->fadeOut = $fades[1];
} catch (PlaylistOutDatedException $e) { } catch (PlaylistOutDatedException $e) {
$this->playlistOutdated($e); $this->playlistOutdated($e);
} catch (PlaylistNotFoundException $e) { } catch (PlaylistNotFoundException $e) {
$this->playlistNotFound(); $this->playlistNotFound($type);
} catch (Exception $e) { } catch (Exception $e) {
$this->playlistUnknownError($e); $this->playlistUnknownError($e);
} }
@ -400,15 +452,16 @@ class PlaylistController extends Zend_Controller_Action
{ {
$fadeIn = $this->_getParam('fadeIn', null); $fadeIn = $this->_getParam('fadeIn', null);
$fadeOut = $this->_getParam('fadeOut', null); $fadeOut = $this->_getParam('fadeOut', null);
$type = $this->_getParam('type');
try { try {
$pl = $this->getPlaylist(); $obj = $this->getPlaylist($type);
$pl->setPlaylistfades($fadeIn, $fadeOut); $obj->setPlaylistfades($fadeIn, $fadeOut);
$this->view->modified = $pl->getLastModified("U"); $this->view->modified = $obj->getLastModified("U");
} catch (PlaylistOutDatedException $e) { } catch (PlaylistOutDatedException $e) {
$this->playlistOutdated($e); $this->playlistOutdated($e);
} catch (PlaylistNotFoundException $e) { } catch (PlaylistNotFoundException $e) {
$this->playlistNotFound(); $this->playlistNotFound($type);
} catch (Exception $e) { } catch (Exception $e) {
$this->playlistUnknownError($e); $this->playlistUnknownError($e);
} }
@ -417,16 +470,17 @@ class PlaylistController extends Zend_Controller_Action
public function setPlaylistNameAction() public function setPlaylistNameAction()
{ {
$name = $this->_getParam('name', 'Unknown Playlist'); $name = $this->_getParam('name', 'Unknown Playlist');
$type = $this->_getParam('type');
try { try {
$pl = $this->getPlaylist(); $obj = $this->getPlaylist($type);
$pl->setName($name); $obj->setName($name);
$this->view->playlistName = $name; $this->view->playlistName = $name;
$this->view->modified = $pl->getLastModified("U"); $this->view->modified = $obj->getLastModified("U");
} catch (PlaylistOutDatedException $e) { } catch (PlaylistOutDatedException $e) {
$this->playlistOutdated($e); $this->playlistOutdated($e);
} catch (PlaylistNotFoundException $e) { } catch (PlaylistNotFoundException $e) {
$this->playlistNotFound(); $this->playlistNotFound($type);
} catch (Exception $e) { } catch (Exception $e) {
$this->playlistUnknownError($e); $this->playlistUnknownError($e);
} }
@ -435,16 +489,17 @@ class PlaylistController extends Zend_Controller_Action
public function setPlaylistDescriptionAction() public function setPlaylistDescriptionAction()
{ {
$description = $this->_getParam('description', ""); $description = $this->_getParam('description', "");
$type = $this->_getParam('type');
try { try {
$pl = $this->getPlaylist(); $obj = $this->getPlaylist($type);
$pl->setDescription($description); $obj->setDescription($description);
$this->view->description = $pl->getDescription(); $this->view->description = $obj->getDescription();
$this->view->modified = $pl->getLastModified("U"); $this->view->modified = $obj->getLastModified("U");
} catch (PlaylistOutDatedException $e) { } catch (PlaylistOutDatedException $e) {
$this->playlistOutdated($e); $this->playlistOutdated($e);
} catch (PlaylistNotFoundException $e) { } catch (PlaylistNotFoundException $e) {
$this->playlistNotFound(); $this->playlistNotFound($type);
} catch (Exception $e) { } catch (Exception $e) {
$this->playlistUnknownError($e); $this->playlistUnknownError($e);
} }
@ -470,7 +525,7 @@ class PlaylistController extends Zend_Controller_Action
die(json_encode(array("result"=>0, "html"=>$this->createFullResponse($pl, true)))); die(json_encode(array("result"=>0, "html"=>$this->createFullResponse($pl, true))));
} }
catch (PlaylistNotFoundException $e) { catch (PlaylistNotFoundException $e) {
$this->playlistNotFound(); $this->playlistNotFound('block');
} }
catch (Exception $e) { catch (Exception $e) {
$this->playlistUnknownError($e); $this->playlistUnknownError($e);
@ -491,7 +546,7 @@ class PlaylistController extends Zend_Controller_Action
die(json_encode(array("result"=>0, "html"=>$this->createFullResponse($pl, true)))); die(json_encode(array("result"=>0, "html"=>$this->createFullResponse($pl, true))));
} }
catch (PlaylistNotFoundException $e) { catch (PlaylistNotFoundException $e) {
$this->playlistNotFound(); $this->playlistNotFound('block');
} }
catch (Exception $e) { catch (Exception $e) {
$this->playlistUnknownError($e); $this->playlistUnknownError($e);
@ -501,4 +556,17 @@ class PlaylistController extends Zend_Controller_Action
} }
} }
public function getObjInfo($p_type)
{
$info = array();
if (strcmp($p_type, 'playlist')==0) {
$info['className'] = 'Application_Model_Playlist';
} else {
$info['className'] = 'Application_Model_Block';
}
return $info;
}
} }

View file

@ -1,5 +1,5 @@
<?php <?php
class Application_Form_SmartPlaylistCriteria extends Zend_Form_SubForm class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm
{ {
public function init(){ public function init(){
@ -241,7 +241,7 @@ class Application_Form_SmartPlaylistCriteria extends Zend_Form_SubForm
$this->addElement($shuffle); $this->addElement($shuffle);
$this->setDecorators(array( $this->setDecorators(array(
array('ViewScript', array('viewScript' => 'form/smart-playlist-criteria.phtml', "openOption"=> $openSmartPlaylistOption, array('ViewScript', array('viewScript' => 'form/smart-block-criteria.phtml', "openOption"=> $openSmartPlaylistOption,
'criteriasLength' => count($criteriaOptions), 'poolCount' => $files['count'])) 'criteriasLength' => count($criteriaOptions), 'poolCount' => $files['count']))
)); ));
} }

View file

@ -765,7 +765,7 @@ class Application_Model_Playlist
return $md; return $md;
} }
public function getPLMetaData($category) public function getMetaData($category)
{ {
$cat = $this->categories[$category]; $cat = $this->categories[$category];
$method = 'get' . $cat; $method = 'get' . $cat;
@ -773,7 +773,7 @@ class Application_Model_Playlist
return $this->$method(); return $this->$method();
} }
public function setPLMetaData($category, $value) public function setMetaData($category, $value)
{ {
$cat = $this->categories[$category]; $cat = $this->categories[$category];

View file

@ -1,17 +1,18 @@
<button id="spl_new" class="ui-button ui-widget ui-state-default" role="button" aria-disabled="false">New</button> <button id="spl_new" class="ui-button ui-widget ui-state-default" role="button" aria-disabled="false">New</button>
<?php if (isset($this->pl)) : ?> <?php if (isset($this->obj)) : ?>
<button id="spl_delete" class="ui-button ui-widget ui-state-default" role="button" aria-disabled="false">Delete</button> <button id="spl_delete" class="ui-button ui-widget ui-state-default" role="button" aria-disabled="false">Delete</button>
<a href="#" id="spl_crossfade" class="ui-button ui-button-icon-only ui-widget ui-state-default crossfade-main-button"> <a href="#" id="spl_crossfade" class="ui-button ui-button-icon-only ui-widget ui-state-default crossfade-main-button">
<span class="ui-icon crossfade-main-icon"></span><span class="ui-button-text">Playlist crossfade</span> <span class="ui-icon crossfade-main-icon"></span><span class="ui-button-text">Playlist crossfade</span>
</a> </a>
<?php endif; ?> <?php endif; ?>
<?php if (isset($this->pl)) : ?> <?php if (isset($this->obj)) : ?>
<input id="pl_id" type="hidden" value="<?php echo $this->pl->getId(); ?>"></input> <input id="pl_id" type="hidden" value="<?php echo $this->obj->getId(); ?>"></input>
<input id="pl_lastMod" type="hidden" value="<?php echo $this->pl->getLastModified('U'); ?>"></input> <input id="pl_lastMod" type="hidden" value="<?php echo $this->obj->getLastModified('U'); ?>"></input>
<input id='obj_type' type='hidden' value='playlist'></input>
<div class="playlist_title"> <div class="playlist_title">
<h3 id="spl_name"> <h3 id="spl_name">
<a id="playlist_name_display" contenteditable="true"><?php echo $this->pl->getName(); ?></a> <a id="playlist_name_display" contenteditable="true"><?php echo $this->obj->getName(); ?></a>
</h3> </h3>
<h4 id="spl_length"><?php echo $this->length; ?></h4> <h4 id="spl_length"><?php echo $this->length; ?></h4>
</div> </div>
@ -21,7 +22,7 @@
<dl class="zend_form"> <dl class="zend_form">
<dt id="description-label"><label for="description">Description</label></dt> <dt id="description-label"><label for="description">Description</label></dt>
<dd id="description-element"> <dd id="description-element">
<textarea cols="80" rows="24" id="description" name="description"><?php echo $this->pl->getDescription(); ?></textarea> <textarea cols="80" rows="24" id="description" name="description"><?php echo $this->obj->getDescription(); ?></textarea>
</dd> </dd>
<dt id="submit-label" style="display: none;">&nbsp;</dt> <dt id="submit-label" style="display: none;">&nbsp;</dt>
<dd id="submit-element" class="buttons"> <dd id="submit-element" class="buttons">
@ -31,7 +32,7 @@
</dl> </dl>
</fieldset> </fieldset>
<?php echo $this->form; ?> <?php //echo $this->form; ?>
<div id="crossfade_main" class="crossfade-main clearfix" style="display:none;"> <div id="crossfade_main" class="crossfade-main clearfix" style="display:none;">
<span class="ui-icon ui-icon-closethick"></span> <span class="ui-icon ui-icon-closethick"></span>

View file

@ -0,0 +1,58 @@
<button id="spl_new" class="ui-button ui-widget ui-state-default" role="button" aria-disabled="false">New</button>
<?php if (isset($this->obj)) : ?>
<button id="spl_delete" class="ui-button ui-widget ui-state-default" role="button" aria-disabled="false">Delete</button>
<a href="#" id="spl_crossfade" class="ui-button ui-button-icon-only ui-widget ui-state-default crossfade-main-button">
<span class="ui-icon crossfade-main-icon"></span><span class="ui-button-text">Playlist crossfade</span>
</a>
<?php endif; ?>
<?php if (isset($this->obj)) : ?>
<input id="bl_id" type="hidden" value="<?php echo $this->obj->getId(); ?>"></input>
<input id="bl_lastMod" type="hidden" value="<?php echo $this->obj->getLastModified('U'); ?>"></input>
<input id='obj_type' type='hidden' value='block'></input>
<div class="playlist_title">
<h3 id="bl_name">
<a id="playlist_name_display" contenteditable="true"><?php echo $this->obj->getName(); ?></a>
</h3>
<h4 id="bl_length"><?php echo $this->length; ?></h4>
</div>
<fieldset class="toggle closed" id="fieldset-metadate_change">
<legend style="cursor: pointer;"><span class="ui-icon ui-icon-triangle-2-n-s"></span>View / edit description</legend>
<dl class="zend_form">
<dt id="description-label"><label for="description">Description</label></dt>
<dd id="description-element">
<textarea cols="80" rows="24" id="description" name="description"><?php echo $this->obj->getDescription(); ?></textarea>
</dd>
<dt id="submit-label" style="display: none;">&nbsp;</dt>
<dd id="submit-element" class="buttons">
<input class="ui-button ui-state-default" type="submit" value="Cancel" id="description_cancel" name="cancel">
<input class="ui-button ui-state-default" type="submit" value="Save" id="description_save" name="submit">
</dd>
</dl>
</fieldset>
<?php echo $this->form; ?>
<div id="crossfade_main" class="crossfade-main clearfix" style="display:none;">
<span class="ui-icon ui-icon-closethick"></span>
<dl id="spl_editor-main" class="inline-list">
<dt>Fade in (s):</dt>
<dd><span contenteditable="true" class="spl_text_input spl_main_fade_in">00</span></dd>
<dd class="edit-error"></dd>
<dt>Fade out (s):</dt>
<dd><span contenteditable="true" class="spl_text_input spl_main_fade_out">00</span></dd>
<dd class="edit-error"></dd>
</dl>
</div>
<div class="clear"></div>
<div class="" style="clear:both; float:none; width:100%;">
<ul id="spl_sortable">
<?php //echo $this->render('playlist/update.phtml') ?>
</ul>
</div>
<?php else : ?>
<div>No open smart block</div>
<?php endif; ?>

View file

@ -1,5 +1,5 @@
<?php <?php
$items = $this->pl->getContents(); $items = $this->obj->getContents();
if (count($items)) : ?> if (count($items)) : ?>
<?php $i = 0; ?> <?php $i = 0; ?>
<?php foreach($items as $item) : ?> <?php foreach($items as $item) : ?>

View file

@ -70,7 +70,8 @@ var AIRTIME = (function(AIRTIME){
cueIn = $.trim(span.text()), cueIn = $.trim(span.text()),
li = span.parents("li"), li = span.parents("li"),
unqid = li.attr("unqid"), unqid = li.attr("unqid"),
lastMod = getModified(); lastMod = getModified(),
type = $('#obj_type').val();
if (!isTimeValid(cueIn)){ if (!isTimeValid(cueIn)){
showError(span, "please put in a time '00:00:00 (.000000)'"); showError(span, "please put in a time '00:00:00 (.000000)'");
@ -78,7 +79,7 @@ var AIRTIME = (function(AIRTIME){
} }
$.post(url, $.post(url,
{format: "json", cueIn: cueIn, id: id, modified: lastMod}, {format: "json", cueIn: cueIn, id: id, modified: lastMod, type: type},
function(json){ function(json){
if (json.error !== undefined){ if (json.error !== undefined){
@ -108,7 +109,8 @@ var AIRTIME = (function(AIRTIME){
cueOut = $.trim(span.text()), cueOut = $.trim(span.text()),
li = span.parents("li"), li = span.parents("li"),
unqid = li.attr("unqid"), unqid = li.attr("unqid"),
lastMod = getModified(); lastMod = getModified(),
type = $('#obj_type').val();
if (!isTimeValid(cueOut)){ if (!isTimeValid(cueOut)){
showError(span, "please put in a time '00:00:00 (.000000)'"); showError(span, "please put in a time '00:00:00 (.000000)'");
@ -116,7 +118,7 @@ var AIRTIME = (function(AIRTIME){
} }
$.post(url, $.post(url,
{format: "json", cueOut: cueOut, id: id, modified: lastMod}, {format: "json", cueOut: cueOut, id: id, modified: lastMod, type: type},
function(json){ function(json){
if (json.error !== undefined){ if (json.error !== undefined){
@ -146,7 +148,8 @@ var AIRTIME = (function(AIRTIME){
fadeIn = $.trim(span.text()), fadeIn = $.trim(span.text()),
li = span.parents("li"), li = span.parents("li"),
unqid = li.attr("unqid"), unqid = li.attr("unqid"),
lastMod = getModified(); lastMod = getModified(),
type = $('#obj_type').val();
if (!isFadeValid(fadeIn)){ if (!isFadeValid(fadeIn)){
showError(span, "please put in a time in seconds '00 (.000000)'"); showError(span, "please put in a time in seconds '00 (.000000)'");
@ -154,7 +157,7 @@ var AIRTIME = (function(AIRTIME){
} }
$.post(url, $.post(url,
{format: "json", fadeIn: fadeIn, id: id, modified: lastMod}, {format: "json", fadeIn: fadeIn, id: id, modified: lastMod, type: type},
function(json){ function(json){
if (json.error !== undefined){ if (json.error !== undefined){
@ -183,7 +186,8 @@ var AIRTIME = (function(AIRTIME){
fadeOut = $.trim(span.text()), fadeOut = $.trim(span.text()),
li = span.parents("li"), li = span.parents("li"),
unqid = li.attr("unqid"), unqid = li.attr("unqid"),
lastMod = getModified(); lastMod = getModified(),
type = $('#obj_type').val();
if (!isFadeValid(fadeOut)){ if (!isFadeValid(fadeOut)){
showError(span, "please put in a time in seconds '00 (.000000)'"); showError(span, "please put in a time in seconds '00 (.000000)'");
@ -191,7 +195,7 @@ var AIRTIME = (function(AIRTIME){
} }
$.post(url, $.post(url,
{format: "json", fadeOut: fadeOut, id: id, modified: lastMod}, {format: "json", fadeOut: fadeOut, id: id, modified: lastMod, type: type},
function(json){ function(json){
if (json.error !== undefined){ if (json.error !== undefined){
@ -256,12 +260,13 @@ var AIRTIME = (function(AIRTIME){
function editName() { function editName() {
var nameElement = $(this), var nameElement = $(this),
lastMod = getModified(); lastMod = getModified(),
type = $('#obj_type').val();
url = '/Playlist/set-playlist-name'; url = '/Playlist/set-playlist-name';
$.post(url, $.post(url,
{format: "json", name: nameElement.text(), modified: lastMod}, {format: "json", name: nameElement.text(), modified: lastMod, type: type},
function(json){ function(json){
if (json.error !== undefined) { if (json.error !== undefined) {
@ -378,7 +383,8 @@ var AIRTIME = (function(AIRTIME){
//main playlist fades events //main playlist fades events
$pl.on("click", "#spl_crossfade", function() { $pl.on("click", "#spl_crossfade", function() {
var lastMod = getModified(); var lastMod = getModified(),
type = $('#obj_type');
if ($(this).hasClass("ui-state-active")) { if ($(this).hasClass("ui-state-active")) {
$(this).removeClass("ui-state-active"); $(this).removeClass("ui-state-active");
@ -390,7 +396,7 @@ var AIRTIME = (function(AIRTIME){
var url = '/Playlist/get-playlist-fades'; var url = '/Playlist/get-playlist-fades';
$.get(url, $.get(url,
{format: "json", modified: lastMod}, {format: "json", modified: lastMod, type: type},
function(json){ function(json){
if (json.error !== undefined){ if (json.error !== undefined){
playlistError(json); playlistError(json);
@ -416,7 +422,8 @@ var AIRTIME = (function(AIRTIME){
var url = "/Playlist/set-playlist-fades", var url = "/Playlist/set-playlist-fades",
span = $(this), span = $(this),
fadeIn = $.trim(span.text()), fadeIn = $.trim(span.text()),
lastMod = getModified(); lastMod = getModified(),
type = $('#obj_type').val();
if (!isFadeValid(fadeIn)){ if (!isFadeValid(fadeIn)){
showError(span, "please put in a time in seconds '00 (.000000)'"); showError(span, "please put in a time in seconds '00 (.000000)'");
@ -424,7 +431,7 @@ var AIRTIME = (function(AIRTIME){
} }
$.post(url, $.post(url,
{format: "json", fadeIn: fadeIn, modified: lastMod}, {format: "json", fadeIn: fadeIn, modified: lastMod, type: type},
function(json){ function(json){
hideError(span); hideError(span);
if (json.modified !== undefined) { if (json.modified !== undefined) {
@ -439,7 +446,8 @@ var AIRTIME = (function(AIRTIME){
var url = "/Playlist/set-playlist-fades", var url = "/Playlist/set-playlist-fades",
span = $(this), span = $(this),
fadeOut = $.trim(span.text()), fadeOut = $.trim(span.text()),
lastMod = getModified(); lastMod = getModified(),
type = $('#obj_type').val();
if (!isFadeValid(fadeOut)){ if (!isFadeValid(fadeOut)){
showError(span, "please put in a time in seconds '00 (.000000)'"); showError(span, "please put in a time in seconds '00 (.000000)'");
@ -447,7 +455,7 @@ var AIRTIME = (function(AIRTIME){
} }
$.post(url, $.post(url,
{format: "json", fadeOut: fadeOut, modified: lastMod}, {format: "json", fadeOut: fadeOut, modified: lastMod, type: type},
function(json){ function(json){
hideError(span); hideError(span);
if (json.modified !== undefined) { if (json.modified !== undefined) {
@ -485,12 +493,13 @@ var AIRTIME = (function(AIRTIME){
var textarea = $pl.find("#fieldset-metadate_change textarea"), var textarea = $pl.find("#fieldset-metadate_change textarea"),
description = textarea.val(), description = textarea.val(),
url, url,
lastMod = getModified();; lastMod = getModified(),
type = $('#obj_type').val();
url = '/Playlist/set-playlist-description'; url = '/Playlist/set-playlist-description';
$.post(url, $.post(url,
{format: "json", description: description, modified: lastMod}, {format: "json", description: description, modified: lastMod, type: type},
function(json){ function(json){
if (json.error !== undefined){ if (json.error !== undefined){
playlistError(json); playlistError(json);
@ -612,7 +621,20 @@ var AIRTIME = (function(AIRTIME){
stopAudioPreview(); stopAudioPreview();
$.post(url, $.post(url,
{format: "json"}, {format: "json", type: 'playlist'},
function(json){
openPlaylist(json);
redrawLib();
});
};
mod.fnNewBlock = function() {
var url = '/Playlist/new';
stopAudioPreview();
$.post(url,
{format: "json", type: 'block'},
function(json){ function(json){
openPlaylist(json); openPlaylist(json);
redrawLib(); redrawLib();
@ -637,10 +659,11 @@ var AIRTIME = (function(AIRTIME){
stopAudioPreview(); stopAudioPreview();
id = (plid === undefined) ? getId() : plid; id = (plid === undefined) ? getId() : plid;
lastMod = getModified(); lastMod = getModified();
type = $('#obj_type').val();
url = '/Playlist/delete'; url = '/Playlist/delete';
$.post(url, $.post(url,
{format: "json", ids: id, modified: lastMod}, {format: "json", ids: id, modified: lastMod, type: type},
function(json){ function(json){
openPlaylist(json); openPlaylist(json);
redrawLib(); redrawLib();
@ -690,13 +713,15 @@ var AIRTIME = (function(AIRTIME){
} }
function playlistRequest(sUrl, oData) { function playlistRequest(sUrl, oData) {
var lastMod; var lastMod,
obj_type = $('#obj_type').val();
mod.disableUI(); mod.disableUI();
lastMod = getModified(); lastMod = getModified();
oData["modified"] = lastMod; oData["modified"] = lastMod;
oData["obj_type"] = obj_type;
oData["format"] = "json"; oData["format"] = "json";
$.post( $.post(
@ -728,9 +753,18 @@ var AIRTIME = (function(AIRTIME){
}; };
mod.init = function() { mod.init = function() {
$.contextMenu({
selector: '#spl_new',
trigger: "left",
ignoreRightClick: true,
items: {
"sp": {name: "New Playlist", callback: AIRTIME.playlist.fnNew},
"sb": {name: "New Smart Block", callback: AIRTIME.playlist.fnNewBlock}
}
});
/*
$pl.delegate("#spl_new", $pl.delegate("#spl_new",
{"click": AIRTIME.playlist.fnNew}); {"click": AIRTIME.playlist.fnNew});*/
$pl.delegate("#spl_delete", {"click": function(ev){ $pl.delegate("#spl_delete", {"click": function(ev){
AIRTIME.playlist.fnDelete(); AIRTIME.playlist.fnDelete();

View file

@ -179,6 +179,7 @@ function setSmartPlaylistEvents() {
function setupUI() { function setupUI() {
var playlist_type = $('input:radio[name=sp_type]:checked').val(); var playlist_type = $('input:radio[name=sp_type]:checked').val();
if ($('#obj_type').val() == 'block') {
if (playlist_type == "0") { if (playlist_type == "0") {
$('button[id="generate_button"]').show(); $('button[id="generate_button"]').show();
$('button[id="shuffle_button"]').show(); $('button[id="shuffle_button"]').show();
@ -197,6 +198,7 @@ function setupUI() {
*/ */
$('#spl_sortable').hide(); $('#spl_sortable').hide();
} }
}
$(".playlist_type_help_icon").qtip({ $(".playlist_type_help_icon").qtip({
content: { content: {