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);
if (isset($file) && $file->getDbFileExists()) {
$entry = $this->plItem;
$entry["id"] = $file->getDbId();
$entry["pos"] = $pos;
$entry["cliplength"] = $file->getDbLength();
$entry["cueout"] = $file->getDbLength();
$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($obj)) {
if (($obj instanceof CcFiles && $obj->getDbFileExists()) || $obj instanceof CcWebstream || $obj instanceof CcBlock) {
$entry = $this->plItem;
$entry["id"] = $obj->getDbId();
$entry["pos"] = $pos;
$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);
$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");
}
$res = $this->insertPlaylistElement($this->buildEntry($ac, $pos), 0);
$pos = $pos + 1;
Logging::log("Adding audio file {$ac}");
}