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)))
|
'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 = new Zend_Form_Element_Radio('sp_type');
|
||||||
$spType->setLabel('Set smart playlist type:');
|
$spType->setLabel('Set smart playlist type:')
|
||||||
$spType->setDecorators(array('viewHelper'));
|
->setDecorators(array('viewHelper'))
|
||||||
$spType->setMultiOptions(array(
|
->setMultiOptions(array(
|
||||||
'static' => 'Static',
|
'static' => 'Static',
|
||||||
'dynamic' => 'Dynamic'
|
'dynamic' => 'Dynamic'
|
||||||
));
|
))
|
||||||
$spType->setValue('Static');
|
->setValue($playlistType);
|
||||||
$this->addElement($spType);
|
$this->addElement($spType);
|
||||||
|
|
||||||
// load criteria from db
|
// load criteria from db
|
||||||
|
|
|
@ -874,6 +874,14 @@ class Application_Model_Playlist {
|
||||||
$result = 0;
|
$result = 0;
|
||||||
$errors = array();
|
$errors = array();
|
||||||
$error = 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') {
|
if ($data['etc']['sp_limit_options'] == 'hours') {
|
||||||
$multiplier = 60;
|
$multiplier = 60;
|
||||||
}
|
}
|
||||||
|
@ -967,13 +975,13 @@ class Application_Model_Playlist {
|
||||||
* tracks.
|
* tracks.
|
||||||
* @param array $p_criteria
|
* @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);
|
$result = self::saveSmartPlaylistCriteria($p_criteria, $p_playlistId);
|
||||||
if ($result['result'] != 0) {
|
if ($result['result'] != 0) {
|
||||||
return $result;
|
return $result;
|
||||||
} else {
|
} else {
|
||||||
$info = self::getListofFilesMeetCriteria($p_playlistId);
|
/*$info = self::getListofFilesMeetCriteria($p_playlistId);
|
||||||
$files = $info['files'];
|
$files = $info['files'];
|
||||||
$limit = $info['limit'];
|
$limit = $info['limit'];
|
||||||
// construct ids of track candidates
|
// construct ids of track candidates
|
||||||
|
@ -989,12 +997,35 @@ class Application_Model_Playlist {
|
||||||
if ( !is_null($limit['items']) && $limit['items'] == count($insertList)) {
|
if ( !is_null($limit['items']) && $limit['items'] == count($insertList)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
$insertList = self::getListOfFilesUnderLimit($p_playlistId);
|
||||||
|
$playlist = new self($p_playlistId);
|
||||||
$playlist->addAudioClips(array_keys($insertList));
|
$playlist->addAudioClips(array_keys($insertList));
|
||||||
return array("result"=>0, "ids"=>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
|
// this function return list of propel object
|
||||||
private static function getListofFilesMeetCriteria($p_playlistId)
|
private static function getListofFilesMeetCriteria($p_playlistId)
|
||||||
{
|
{
|
||||||
|
|
|
@ -148,31 +148,46 @@ class Application_Model_Scheduler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ($type === "playlist") {
|
else if ($type === "playlist") {
|
||||||
|
|
||||||
$contents = CcPlaylistcontentsQuery::create()
|
// find if the playslit is static or dynamic
|
||||||
->orderByDbPosition()
|
$c = new Criteria();
|
||||||
->filterByDbPlaylistId($id)
|
$c->add(CcPlaylistPeer::ID, $id);
|
||||||
->find($this->con);
|
$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)) {
|
if (is_null($contents)) {
|
||||||
throw new Exception("A selected Playlist does not exist!");
|
throw new Exception("A selected Playlist does not exist!");
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($contents as $plItem) {
|
foreach ($contents as $plItem) {
|
||||||
|
$data = $this->fileInfo;
|
||||||
$file = $plItem->getCcFiles($this->con);
|
if ($playlistType == "static"){
|
||||||
if (isset($file) && $file->getDbFileExists()) {
|
$file = $plItem->getCcFiles($this->con);
|
||||||
|
if (isset($file) && $file->getDbFileExists()) {
|
||||||
$data = $this->fileInfo;
|
$data["id"] = $plItem->getDbFileId();
|
||||||
$data["id"] = $plItem->getDbFileId();
|
$data["cliplength"] = $plItem->getDbCliplength();
|
||||||
$data["cliplength"] = $plItem->getDbCliplength();
|
$data["cuein"] = $plItem->getDbCuein();
|
||||||
$data["cuein"] = $plItem->getDbCuein();
|
$data["cueout"] = $plItem->getDbCueout();
|
||||||
$data["cueout"] = $plItem->getDbCueout();
|
$data["fadein"] = $plItem->getDbFadein();
|
||||||
$data["fadein"] = $plItem->getDbFadein();
|
$data["fadeout"] = $plItem->getDbFadeout();
|
||||||
$data["fadeout"] = $plItem->getDbFadeout();
|
}
|
||||||
|
} else {
|
||||||
$files[] = $data;
|
// 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() {
|
$(document).ready(function() {
|
||||||
setSmartPlaylistEvents();
|
setSmartPlaylistEvents();
|
||||||
var form = $('#smart-playlist-form');
|
/*var form = $('#smart-playlist-form');
|
||||||
appendAddButton(form);
|
appendAddButton(form);*/
|
||||||
});
|
});
|
||||||
|
|
||||||
function setSmartPlaylistEvents() {
|
function setSmartPlaylistEvents() {
|
||||||
|
@ -158,7 +158,8 @@ function setSmartPlaylistEvents() {
|
||||||
disableAndHideExtraField(criteria_value, index_num);
|
disableAndHideExtraField(criteria_value, index_num);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
appendAddButton(form);
|
||||||
}
|
}
|
||||||
|
|
||||||
function enableAndShowExtraField(valEle, index) {
|
function enableAndShowExtraField(valEle, index) {
|
||||||
|
@ -222,7 +223,6 @@ function staticCallback(data) {
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
AIRTIME.playlist.fnOpenPlaylist(json);
|
AIRTIME.playlist.fnOpenPlaylist(json);
|
||||||
var form = $('#smart-playlist-form');
|
|
||||||
form.find('.success').text('Smart playlist generated');
|
form.find('.success').text('Smart playlist generated');
|
||||||
form.find('.success').show();
|
form.find('.success').show();
|
||||||
form.find('#smart_playlist_options').removeClass("closed");
|
form.find('#smart_playlist_options').removeClass("closed");
|
||||||
|
|
Loading…
Reference in New Issue