CC-84: Smart Playlists

- merging code
This commit is contained in:
James 2012-07-26 16:16:07 -04:00
parent 8755500d30
commit 7cde4ba2ba
5 changed files with 54 additions and 48 deletions

View file

@ -70,6 +70,7 @@ class PlaylistController extends Zend_Controller_Action
$this->view->length = $formatter->format();
$this->view->obj = $obj;
Logging::log($obj->getContents());
$this->view->html = $this->view->render('playlist/update.phtml');
$this->view->name = $obj->getName();
$this->view->description = $obj->getDescription();
@ -297,23 +298,31 @@ class PlaylistController extends Zend_Controller_Action
$ids = (!is_array($ids)) ? array($ids) : $ids;
$afterItem = $this->_getParam('afterItem', null);
$addType = $this->_getParam('type', 'after');
// this is the obj type of destination
$obj_type = $this->_getParam('obj_type');
try {
$obj = $this->getPlaylist($obj_type);
if ($obj_type == 'playlist' || $obj->isStatic()) {
if ($obj_type == 'playlist') {
$obj->addAudioClips($ids, $afterItem, $addType);
} else if ($obj->isStatic()) {
// if the dest is a block object
$obj->addAudioClips($ids, $afterItem, $addType);
$this->createUpdateResponse($obj);
} else {
throw new PlaylistDyanmicException;
}
} catch (PlaylistOutDatedException $e) {
$this->playlistOutdated($pl, $e);
} catch (PlaylistNotFoundException $e) {
$this->playlistNotFound();
} catch (PlaylistDyanmicException $e) {
$this->playlistDynamic($pl);
} catch (Exception $e) {
$this->createUpdateResponse($obj);
}
catch (PlaylistOutDatedException $e) {
$this->playlistOutdated($e);
}
catch (PlaylistNotFoundException $e) {
$this->playlistNotFound($obj_type);
}
catch (PlaylistDyanmicException $e) {
$this->playlistDynamic($obj);
}
catch (Exception $e) {
$this->playlistUnknownError($e);
}
}

View file

@ -174,11 +174,11 @@ class Application_Model_Playlist
$sql = <<<"EOT"
((SELECT pc.id as id, pc.type, pc.position, pc.cliplength as length, pc.cuein, pc.cueout, pc.fadein, pc.fadeout,
f.id as item_id, f.track_title, f.artist_name as creator, f.file_exists as exists, f.filepath as path FROM cc_playlistcontents AS pc
LEFT JOIN cc_files AS f ON pc.file_id=f.id WHERE pc.playlist_id = {$this->id} AND type = 0)
JOIN cc_files AS f ON pc.file_id=f.id WHERE pc.playlist_id = {$this->id} AND type = 0)
UNION ALL
(SELECT pc.id as id, pc.type, pc.position, pc.cliplength as length, pc.cuein, pc.cueout, pc.fadein, pc.fadeout,
ws.id as item_id, (ws.name || ': ' || ws.url) as title, ws.login as creator, 't'::boolean as exists, ws.url as path FROM cc_playlistcontents AS pc
LEFT JOIN cc_webstream AS ws on pc.file_id=ws.id WHERE pc.playlist_id = {$this->id} AND type = 1));
JOIN cc_webstream AS ws on pc.file_id=ws.id WHERE pc.playlist_id = {$this->id} AND type = 1));
EOT;
Logging::debug($sql);
$con = Propel::getConnection();
@ -280,22 +280,33 @@ EOT;
*/
private function buildEntry($p_item, $pos)
{
$file = CcFilesQuery::create()->findPK($p_item, $this->con);
$objType = $p_item[1];
$objId = $p_item[0];
if ($objType == 'audioclip') {
$obj = CcFilesQuery::create()->findPK($objId, $this->con);
} else if ($objType == "stream") {
$obj = CcWebstreamQuery::create()->findPK($objId, $this->con);
} else if ($objType == "block") {
$obj = CcBlockQuery::create()->findPK($objId, $this->con);
} else {
throw new Exception("Unknown file type");
}
if (isset($file) && $file->getDbFileExists()) {
if (isset($obj)) {
if (($obj instanceof CcFiles && $obj->getDbFileExists()) || $obj instanceof CcWebstream || $obj instanceof CcBlock) {
$entry = $this->plItem;
$entry["id"] = $file->getDbId();
$entry["id"] = $obj->getDbId();
$entry["pos"] = $pos;
$entry["cliplength"] = $file->getDbLength();
$entry["cueout"] = $file->getDbLength();
$entry["cliplength"] = $obj->getDbLength();
$entry["cueout"] = $obj->getDbLength();
}
return $entry;
} else {
throw new Exception("trying to add a file that does not exist.");
throw new Exception("trying to add a object that does not exist.");
}
}
private function buildStreamEntry($p_item, $pos)
/*private function buildStreamEntry($p_item, $pos)
{
$stream = CcWebstreamQuery::create()->findPK($p_item, $this->con);
@ -310,7 +321,7 @@ EOT;
} else {
throw new Exception("trying to add a stream that does not exist.");
}
}
}*/
/*
* @param array $p_items
@ -369,19 +380,8 @@ EOT;
Logging::log("at position {$pos}");
foreach ($p_items as $ac) {
list($item, $type) = $ac;
if ($type == "audioclip") {
$res = $this->insertPlaylistElement($this->buildEntry($item, $pos), 0);
$res = $this->insertPlaylistElement($this->buildEntry($ac, $pos), 0);
$pos = $pos + 1;
} else if ($type == "playlist") {
} else if ($type == "stream") {
$res = $this->insertPlaylistElement($this->buildStreamEntry($item, $pos), 1);
$pos = $pos + 1;
} else {
throw new Exception("Unknown file type");
}
Logging::log("Adding audio file {$ac}");
}

View file

@ -27,11 +27,12 @@ var AIRTIME = (function(AIRTIME){
mod.fnRowCallback = function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
var $nRow = $(nRow);
if (aData.ftype === "audioclip") {
$nRow.addClass("lib-audio");
} else if (aData.ftype === "stream"){
$nRow.addClass("lib-stream");
} else if (aData.ftype === "block") {
$nRow.addClass("lib-block");
} else {
$nRow.addClass("lib-pl");
}
@ -46,7 +47,7 @@ var AIRTIME = (function(AIRTIME){
mod.redrawChosen();
mod.checkToolBarIcons();
$('#library_display tr.lib-audio, tr.lib-stream, tr.lib-pl').draggable({
$('#library_display tr.lib-audio, tr.lib-stream, tr.lib-pl, tr.lib-block').draggable({
helper: function(){
var $el = $(this),
@ -89,14 +90,12 @@ var AIRTIME = (function(AIRTIME){
});
};
mod.dblClickAdd = function(id, type) {
mod.dblClickAdd = function(data, type) {
var i,
aMediaIds = [];
//process selected files/playlists.
if (type === "audioclip") {
aMediaIds.push(id);
}
aMediaIds.push(new Array(data.id, data.ftype));
AIRTIME.playlist.fnAddItems(aMediaIds, undefined, 'after');
};
@ -128,7 +127,7 @@ var AIRTIME = (function(AIRTIME){
//process selected files/playlists.
for (i = 0, length = aData.length; i < length; i++) {
temp = aData[i];
if (temp.ftype === "audioclip") {
if (temp.ftype === "audioclip" || temp.ftype === "block") {
aMediaIds.push(temp.id);
}
}

View file

@ -440,7 +440,7 @@ var AIRTIME = (function(AIRTIME) {
$tr = $(el).parent();
data = $tr.data("aData");
AIRTIME.library.dblClickAdd(data.id, data.ftype);
AIRTIME.library.dblClickAdd(data, data.ftype);
}
else
{

View file

@ -575,8 +575,7 @@ var AIRTIME = (function(AIRTIME){
aSelected = AIRTIME.library.getSelectedData();
for (i = 0, length = aSelected.length; i < length; i++) {
var type = aSelected[i].ftype;
aItems.push(new Array(aSelected[i].id, type));
aItems.push(new Array(aSelected[i].id, aSelected[i].ftype));
}
aReceiveItems = aItems;
@ -778,7 +777,6 @@ var AIRTIME = (function(AIRTIME){
mod.fnAddItems = function(aItems, iAfter, sAddType) {
var sUrl = "/playlist/add-items";
oData = {"aItems": aItems, "afterItem": iAfter, "type": sAddType};
playlistRequest(sUrl, oData);
};