CC-84: Smart Playlists
- save playlist type to db - on edit type is loaded
This commit is contained in:
parent
fc09baacd7
commit
a4ba776b0f
|
@ -96,14 +96,25 @@ class Application_Form_SmartPlaylistCriteria extends Zend_Form_SubForm
|
|||
'criteriasLength' => count($criteriaOptions)))
|
||||
));
|
||||
|
||||
// load type
|
||||
$c = new Criteria();
|
||||
$c->add(CcPlaylistPeer::ID, $p_playlistId);
|
||||
$out = CcPlaylistPeer::doSelect($c);
|
||||
|
||||
if ($out[0]->getDbType() == "static") {
|
||||
$playlistType = 0;
|
||||
} else {
|
||||
$playlistType = 1;
|
||||
}
|
||||
|
||||
$spType = new Zend_Form_Element_Radio('sp_type');
|
||||
$spType->setLabel('Set smart playlist type:');
|
||||
$spType->setDecorators(array('viewHelper'));
|
||||
$spType->setMultiOptions(array(
|
||||
'static' => 'Static',
|
||||
'dynamic' => 'Dynamic'
|
||||
));
|
||||
$spType->setValue('Static');
|
||||
$spType->setLabel('Set smart playlist type:')
|
||||
->setDecorators(array('viewHelper'))
|
||||
->setMultiOptions(array(
|
||||
'static' => 'Static',
|
||||
'dynamic' => 'Dynamic'
|
||||
))
|
||||
->setValue($playlistType);
|
||||
$this->addElement($spType);
|
||||
|
||||
// load criteria from db
|
||||
|
|
|
@ -874,6 +874,14 @@ class Application_Model_Playlist {
|
|||
$result = 0;
|
||||
$errors = array();
|
||||
$error = array();
|
||||
|
||||
// saving dynamic/static flag
|
||||
$playlistType = $data['etc']['sp_type'] == 0 ? 'static':'dynamic';
|
||||
$playlistCrit = new Criteria();
|
||||
$playlistCrit->add(CcPlaylistPeer::ID, $p_playlistId);
|
||||
$playlistCrit->add(CcPlaylistPeer::TYPE, $playlistType);
|
||||
CcPlaylistPeer::doUpdate($playlistCrit);
|
||||
|
||||
if ($data['etc']['sp_limit_options'] == 'hours') {
|
||||
$multiplier = 60;
|
||||
}
|
||||
|
@ -967,13 +975,13 @@ class Application_Model_Playlist {
|
|||
* tracks.
|
||||
* @param array $p_criteria
|
||||
*/
|
||||
public static function generateSmartPlaylist($p_criteria, $p_playlistId)
|
||||
public static function generateSmartPlaylist($p_criteria, $p_playlistId, $returnList=false)
|
||||
{
|
||||
$result = self::saveSmartPlaylistCriteria($p_criteria, $p_playlistId);
|
||||
if ($result['result'] != 0) {
|
||||
return $result;
|
||||
} else {
|
||||
$info = self::getListofFilesMeetCriteria($p_playlistId);
|
||||
/*$info = self::getListofFilesMeetCriteria($p_playlistId);
|
||||
$files = $info['files'];
|
||||
$limit = $info['limit'];
|
||||
// construct ids of track candidates
|
||||
|
@ -989,12 +997,35 @@ class Application_Model_Playlist {
|
|||
if ( !is_null($limit['items']) && $limit['items'] == count($insertList)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
$insertList = self::getListOfFilesUnderLimit($p_playlistId);
|
||||
$playlist = new self($p_playlistId);
|
||||
$playlist->addAudioClips(array_keys($insertList));
|
||||
return array("result"=>0, "ids"=>array_keys($insertList));
|
||||
}
|
||||
}
|
||||
|
||||
public static function getListOfFilesUnderLimit($p_playlistId)
|
||||
{
|
||||
$info = self::getListofFilesMeetCriteria($p_playlistId);
|
||||
$files = $info['files'];
|
||||
$limit = $info['limit'];
|
||||
// construct ids of track candidates
|
||||
self::deleteAllFilesFromPlaylist($p_playlistId);
|
||||
$insertList = array();
|
||||
$totalTime = 0;
|
||||
while ($totalTime < $limit['time'] && !empty($files)) {
|
||||
$key = array_rand($files);
|
||||
$insertList[$key] = $files[$key];
|
||||
$totalTime += $files[$key];
|
||||
unset($files[$key]);
|
||||
if ( !is_null($limit['items']) && $limit['items'] == count($insertList)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $insertList;
|
||||
}
|
||||
|
||||
// this function return list of propel object
|
||||
private static function getListofFilesMeetCriteria($p_playlistId)
|
||||
{
|
||||
|
|
|
@ -148,31 +148,46 @@ class Application_Model_Scheduler {
|
|||
}
|
||||
}
|
||||
else if ($type === "playlist") {
|
||||
|
||||
$contents = CcPlaylistcontentsQuery::create()
|
||||
->orderByDbPosition()
|
||||
->filterByDbPlaylistId($id)
|
||||
->find($this->con);
|
||||
|
||||
// find if the playslit is static or dynamic
|
||||
$c = new Criteria();
|
||||
$c->add(CcPlaylistPeer::ID, $id);
|
||||
$pl = CcPlaylistPeer::doSelect($c);
|
||||
$playlistType = $pl->getDbType();
|
||||
|
||||
if ($playlistType == "static") {
|
||||
$contents = CcPlaylistcontentsQuery::create()
|
||||
->orderByDbPosition()
|
||||
->filterByDbPlaylistId($id)
|
||||
->find($this->con);
|
||||
} else {
|
||||
$contents = Application_Model_Playlist::getListOfFilesUnderLimit($id);
|
||||
}
|
||||
|
||||
if (is_null($contents)) {
|
||||
throw new Exception("A selected Playlist does not exist!");
|
||||
}
|
||||
|
||||
foreach ($contents as $plItem) {
|
||||
|
||||
$file = $plItem->getCcFiles($this->con);
|
||||
if (isset($file) && $file->getDbFileExists()) {
|
||||
|
||||
$data = $this->fileInfo;
|
||||
$data["id"] = $plItem->getDbFileId();
|
||||
$data["cliplength"] = $plItem->getDbCliplength();
|
||||
$data["cuein"] = $plItem->getDbCuein();
|
||||
$data["cueout"] = $plItem->getDbCueout();
|
||||
$data["fadein"] = $plItem->getDbFadein();
|
||||
$data["fadeout"] = $plItem->getDbFadeout();
|
||||
|
||||
$files[] = $data;
|
||||
$data = $this->fileInfo;
|
||||
if ($playlistType == "static"){
|
||||
$file = $plItem->getCcFiles($this->con);
|
||||
if (isset($file) && $file->getDbFileExists()) {
|
||||
$data["id"] = $plItem->getDbFileId();
|
||||
$data["cliplength"] = $plItem->getDbCliplength();
|
||||
$data["cuein"] = $plItem->getDbCuein();
|
||||
$data["cueout"] = $plItem->getDbCueout();
|
||||
$data["fadein"] = $plItem->getDbFadein();
|
||||
$data["fadeout"] = $plItem->getDbFadeout();
|
||||
}
|
||||
} else {
|
||||
// on dynamic playslsit, $plItem is id of files
|
||||
$file = Application_Model_StoredFile::Recall($plItem);
|
||||
if (isset($file) && $file->getDbFileExists()) {
|
||||
$data["id"] = $plItem;
|
||||
}
|
||||
}
|
||||
$files[] = $data;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
$(document).ready(function() {
|
||||
setSmartPlaylistEvents();
|
||||
var form = $('#smart-playlist-form');
|
||||
appendAddButton(form);
|
||||
/*var form = $('#smart-playlist-form');
|
||||
appendAddButton(form);*/
|
||||
});
|
||||
|
||||
function setSmartPlaylistEvents() {
|
||||
|
@ -158,7 +158,8 @@ function setSmartPlaylistEvents() {
|
|||
disableAndHideExtraField(criteria_value, index_num);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
appendAddButton(form);
|
||||
}
|
||||
|
||||
function enableAndShowExtraField(valEle, index) {
|
||||
|
@ -222,7 +223,6 @@ function staticCallback(data) {
|
|||
});
|
||||
} else {
|
||||
AIRTIME.playlist.fnOpenPlaylist(json);
|
||||
var form = $('#smart-playlist-form');
|
||||
form.find('.success').text('Smart playlist generated');
|
||||
form.find('.success').show();
|
||||
form.find('#smart_playlist_options').removeClass("closed");
|
||||
|
|
Loading…
Reference in New Issue