parent
1bb97c8603
commit
fc09baacd7
|
@ -70,7 +70,7 @@ class PlaylistController extends Zend_Controller_Action
|
||||||
unset($this->view->pl);
|
unset($this->view->pl);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function createFullResponse($pl = null)
|
private function createFullResponse($pl = null, $isJson = false)
|
||||||
{
|
{
|
||||||
if (isset($pl)) {
|
if (isset($pl)) {
|
||||||
$formatter = new LengthFormatter($pl->getLength());
|
$formatter = new LengthFormatter($pl->getLength());
|
||||||
|
@ -84,13 +84,21 @@ class PlaylistController extends Zend_Controller_Action
|
||||||
|
|
||||||
$this->view->pl = $pl;
|
$this->view->pl = $pl;
|
||||||
$this->view->id = $pl->getId();
|
$this->view->id = $pl->getId();
|
||||||
|
if ($isJson){
|
||||||
|
return $this->view->render('playlist/playlist.phtml');
|
||||||
|
}else{
|
||||||
$this->view->html = $this->view->render('playlist/playlist.phtml');
|
$this->view->html = $this->view->render('playlist/playlist.phtml');
|
||||||
|
}
|
||||||
unset($this->view->pl);
|
unset($this->view->pl);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
if ($isJson){
|
||||||
|
return $this->view->render('playlist/playlist.phtml');
|
||||||
|
}else{
|
||||||
$this->view->html = $this->view->render('playlist/playlist.phtml');
|
$this->view->html = $this->view->render('playlist/playlist.phtml');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private function playlistOutdated($pl, $e)
|
private function playlistOutdated($pl, $e)
|
||||||
{
|
{
|
||||||
|
@ -451,16 +459,42 @@ class PlaylistController extends Zend_Controller_Action
|
||||||
$params = $request->getPost();
|
$params = $request->getPost();
|
||||||
$result = Application_Model_Playlist::saveSmartPlaylistCriteria($params['data'], $params['pl_id']);
|
$result = Application_Model_Playlist::saveSmartPlaylistCriteria($params['data'], $params['pl_id']);
|
||||||
die(json_encode($result));
|
die(json_encode($result));
|
||||||
|
/*if ($result['result'] != 0) {
|
||||||
|
die(json_encode($result));
|
||||||
|
} else{
|
||||||
|
try {
|
||||||
|
$pl = new Application_Model_Playlist($params['pl_id']);
|
||||||
|
$this->createFullResponse($pl);
|
||||||
|
}
|
||||||
|
catch (PlaylistNotFoundException $e) {
|
||||||
|
$this->playlistNotFound();
|
||||||
|
}
|
||||||
|
catch (Exception $e) {
|
||||||
|
$this->playlistUnknownError($e);
|
||||||
|
}
|
||||||
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
public function smartPlaylistGenerateAction()
|
public function smartPlaylistGenerateAction()
|
||||||
{
|
{
|
||||||
$request = $this->getRequest();
|
$request = $this->getRequest();
|
||||||
$params = $request->getPost();
|
$params = $request->getPost();
|
||||||
Logging::log($params);
|
|
||||||
$result = Application_Model_Playlist::generateSmartPlaylist($params['data'], $params['pl_id']);
|
$result = Application_Model_Playlist::generateSmartPlaylist($params['data'], $params['pl_id']);
|
||||||
|
if ($result['result'] == 0) {
|
||||||
|
try {
|
||||||
|
$pl = new Application_Model_Playlist($params['pl_id']);
|
||||||
|
die(json_encode(array("result"=>0, "html"=>$this->createFullResponse($pl, true))));
|
||||||
|
}
|
||||||
|
catch (PlaylistNotFoundException $e) {
|
||||||
|
$this->playlistNotFound();
|
||||||
|
}
|
||||||
|
catch (Exception $e) {
|
||||||
|
$this->playlistUnknownError($e);
|
||||||
|
}
|
||||||
|
}else{
|
||||||
die(json_encode($result));
|
die(json_encode($result));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function smartPlaylistGetAction()
|
public function smartPlaylistGetAction()
|
||||||
{
|
{
|
||||||
|
|
|
@ -848,6 +848,15 @@ class Application_Model_Playlist {
|
||||||
CcPlaylistQuery::create()->findPKs($p_ids)->delete();
|
CcPlaylistQuery::create()->findPKs($p_ids)->delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete all files from playlist
|
||||||
|
* @param int $p_playlistId
|
||||||
|
*/
|
||||||
|
public static function deleteAllFilesFromPlaylist($p_playlistId)
|
||||||
|
{
|
||||||
|
CcPlaylistcontentsQuery::create()->findByDbPlaylistId($p_playlistId)->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// smart playlist functions start
|
// smart playlist functions start
|
||||||
/**
|
/**
|
||||||
|
@ -964,33 +973,79 @@ class Application_Model_Playlist {
|
||||||
if ($result['result'] != 0) {
|
if ($result['result'] != 0) {
|
||||||
return $result;
|
return $result;
|
||||||
} else {
|
} else {
|
||||||
//$data = self::organizeSmartPlyalistCriteria($p_criteria);
|
$info = self::getListofFilesMeetCriteria($p_playlistId);
|
||||||
$list = self::getListofFilesMeetCriteria($p_playlist_id);
|
$files = $info['files'];
|
||||||
return array("result"=>0);
|
$limit = $info['limit'];
|
||||||
|
// construct ids of track candidates
|
||||||
|
self::deleteAllFilesFromPlaylist($p_playlistId);
|
||||||
|
$playlist = new self($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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$playlist->addAudioClips(array_keys($insertList));
|
||||||
|
return array("result"=>0, "ids"=>array_keys($insertList));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// this function return list of propel object
|
// this function return list of propel object
|
||||||
private static function getListofFilesMeetCriteria($p_playlist_id)
|
private static function getListofFilesMeetCriteria($p_playlistId)
|
||||||
{
|
{
|
||||||
$c = new Criteria();
|
$c = new Criteria();
|
||||||
|
$c->add(CcPlaylistcriteriaPeer::PLAYLIST_ID, $p_playlistId);
|
||||||
|
$out = CcPlaylistcriteriaPeer::doSelect($c);
|
||||||
|
|
||||||
foreach ($p_data as $criteria) {
|
$storedCrit = array();
|
||||||
$spCriteria = self::$criteria2PeerMap[$criteria['sp_criteria_field']];
|
foreach ($out as $crit) {
|
||||||
$spCriteriaModifier = $criteria['sp_criteria_modifier'];
|
$criteria = $crit->getDbCriteria();
|
||||||
$spCriteriaValue = $criteria['sp_criteria_value'];
|
$modifier = $crit->getDbModifier();
|
||||||
|
$value = $crit->getDbValue();
|
||||||
|
$extra = $crit->getDbExtra();
|
||||||
|
|
||||||
|
if($criteria == "limit"){
|
||||||
|
$storedCrit["limit"] = array("value"=>$value, "modifier"=>$modifier);
|
||||||
|
}else{
|
||||||
|
$storedCrit["crit"][] = array("criteria"=>$criteria, "value"=>$value, "modifier"=>$modifier, "extra"=>$extra);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$ccFileCriteria = new Criteria();
|
||||||
|
foreach ($storedCrit["crit"] as $criteria) {
|
||||||
|
$spCriteria = self::$criteria2PeerMap[$criteria['criteria']];
|
||||||
|
$spCriteriaModifier = $criteria['modifier'];
|
||||||
|
$spCriteriaValue = $criteria['value'];
|
||||||
if ($spCriteriaModifier == "starts with") {
|
if ($spCriteriaModifier == "starts with") {
|
||||||
$spCriteriaValue = "$spCriteriaValue%";
|
$spCriteriaValue = "$spCriteriaValue%";
|
||||||
} else if ($spCriteriaModifier == "ends with") {
|
} else if ($spCriteriaModifier == "ends with") {
|
||||||
$spCriteriaValue = "%$spCriteriaValue";
|
$spCriteriaValue = "%$spCriteriaValue";
|
||||||
} else if ($spCriteriaModifier == "is in the range") {
|
} else if ($spCriteriaModifier == "is in the range") {
|
||||||
$spCriteriaValue = "$spCriteria > '$spCriteriaValue' AND $spCriteria < '$criteria[sp_criteria_extra]'";
|
$spCriteriaValue = "$spCriteria > '$spCriteriaValue' AND $spCriteria < '$criteria[extra]'";
|
||||||
}
|
}
|
||||||
$spCriteriaModifier = self::$modifier2CriteriaMap[$spCriteriaModifier];
|
$spCriteriaModifier = self::$modifier2CriteriaMap[$spCriteriaModifier];
|
||||||
$c->add($spCriteria, $spCriteriaValue, $spCriteriaModifier);
|
$ccFileCriteria->add($spCriteria, $spCriteriaValue, $spCriteriaModifier);
|
||||||
|
}
|
||||||
|
// construct limit restriction
|
||||||
|
$limits = array();
|
||||||
|
if ($storedCrit['limit']['modifier'] == "items") {
|
||||||
|
$limits['time'] = 1440 * 60;
|
||||||
|
$limits['items'] = $storedCrit['limit']['value'];
|
||||||
|
} else {
|
||||||
|
$limits['time'] = $storedCrit['limit']['modifier'] == "hours" ? intval($storedCrit['limit']['value']) * 60 * 60 : intval($storedCrit['limit']['value'] * 60);
|
||||||
|
$limits['items'] = null;
|
||||||
}
|
}
|
||||||
try{
|
try{
|
||||||
$out = CcFilesPeer::doSelect($c);
|
$out = CcFilesPeer::doSelect($ccFileCriteria);
|
||||||
|
$files = array();
|
||||||
|
foreach ($out as $file) {
|
||||||
|
$files[$file->getDbId()] = Application_Common_DateHelper::calculateLengthInSeconds($file->getDbLength());
|
||||||
|
}
|
||||||
|
return array("files"=>$files, "limit"=>$limits);
|
||||||
}catch(Exception $e){
|
}catch(Exception $e){
|
||||||
//Logging::log($e);
|
//Logging::log($e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -658,6 +658,10 @@ var AIRTIME = (function(AIRTIME){
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
mod.fnOpenPlaylist = function(json) {
|
||||||
|
openPlaylist(json);
|
||||||
|
};
|
||||||
|
|
||||||
mod.enableUI = function() {
|
mod.enableUI = function() {
|
||||||
|
|
||||||
$lib.unblock();
|
$lib.unblock();
|
||||||
|
|
|
@ -221,9 +221,11 @@ function staticCallback(data) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
AIRTIME.playlist.fnAddItems(json.ids, null, 'after');
|
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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue