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->length = $formatter->format();
$this->view->obj = $obj; $this->view->obj = $obj;
Logging::log($obj->getContents());
$this->view->html = $this->view->render('playlist/update.phtml'); $this->view->html = $this->view->render('playlist/update.phtml');
$this->view->name = $obj->getName(); $this->view->name = $obj->getName();
$this->view->description = $obj->getDescription(); $this->view->description = $obj->getDescription();
@ -297,23 +298,31 @@ 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');
// this is the obj type of destination
$obj_type = $this->_getParam('obj_type'); $obj_type = $this->_getParam('obj_type');
try { try {
$obj = $this->getPlaylist($obj_type); $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); $obj->addAudioClips($ids, $afterItem, $addType);
$this->createUpdateResponse($obj);
} else { } else {
throw new PlaylistDyanmicException; throw new PlaylistDyanmicException;
} }
} catch (PlaylistOutDatedException $e) { $this->createUpdateResponse($obj);
$this->playlistOutdated($pl, $e); }
} catch (PlaylistNotFoundException $e) { catch (PlaylistOutDatedException $e) {
$this->playlistNotFound(); $this->playlistOutdated($e);
} catch (PlaylistDyanmicException $e) { }
$this->playlistDynamic($pl); catch (PlaylistNotFoundException $e) {
} catch (Exception $e) { $this->playlistNotFound($obj_type);
}
catch (PlaylistDyanmicException $e) {
$this->playlistDynamic($obj);
}
catch (Exception $e) {
$this->playlistUnknownError($e); $this->playlistUnknownError($e);
} }
} }

View file

@ -174,11 +174,11 @@ class Application_Model_Playlist
$sql = <<<"EOT" $sql = <<<"EOT"
((SELECT pc.id as id, pc.type, pc.position, pc.cliplength as length, pc.cuein, pc.cueout, pc.fadein, pc.fadeout, ((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 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 UNION ALL
(SELECT pc.id as id, pc.type, pc.position, pc.cliplength as length, pc.cuein, pc.cueout, pc.fadein, pc.fadeout, (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 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; EOT;
Logging::debug($sql); Logging::debug($sql);
$con = Propel::getConnection(); $con = Propel::getConnection();
@ -280,22 +280,33 @@ EOT;
*/ */
private function buildEntry($p_item, $pos) 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 = $this->plItem;
$entry["id"] = $file->getDbId(); $entry["id"] = $obj->getDbId();
$entry["pos"] = $pos; $entry["pos"] = $pos;
$entry["cliplength"] = $file->getDbLength(); $entry["cliplength"] = $obj->getDbLength();
$entry["cueout"] = $file->getDbLength(); $entry["cueout"] = $obj->getDbLength();
}
return $entry; return $entry;
} else { } 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); $stream = CcWebstreamQuery::create()->findPK($p_item, $this->con);
@ -310,7 +321,7 @@ EOT;
} else { } else {
throw new Exception("trying to add a stream that does not exist."); throw new Exception("trying to add a stream that does not exist.");
} }
} }*/
/* /*
* @param array $p_items * @param array $p_items
@ -369,19 +380,8 @@ EOT;
Logging::log("at position {$pos}"); Logging::log("at position {$pos}");
foreach ($p_items as $ac) { foreach ($p_items as $ac) {
list($item, $type) = $ac; $res = $this->insertPlaylistElement($this->buildEntry($ac, $pos), 0);
if ($type == "audioclip") {
$res = $this->insertPlaylistElement($this->buildEntry($item, $pos), 0);
$pos = $pos + 1; $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}"); Logging::log("Adding audio file {$ac}");
} }

View file

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

View file

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

View file

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