parent
33e4d6154d
commit
2b2a1db055
|
@ -25,6 +25,7 @@ class PlaylistController extends Zend_Controller_Action
|
||||||
->addActionContext('smart-block-generate', 'json')
|
->addActionContext('smart-block-generate', 'json')
|
||||||
->addActionContext('smart-block-shuffle', 'json')
|
->addActionContext('smart-block-shuffle', 'json')
|
||||||
->addActionContext('get-block-info', 'json')
|
->addActionContext('get-block-info', 'json')
|
||||||
|
->addActionContext('shuffle', 'json')
|
||||||
->initContext();
|
->initContext();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -72,7 +73,6 @@ class PlaylistController extends Zend_Controller_Action
|
||||||
$isBlock = true;
|
$isBlock = true;
|
||||||
$viewPath = 'playlist/smart-block.phtml';
|
$viewPath = 'playlist/smart-block.phtml';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($obj)) {
|
if (isset($obj)) {
|
||||||
$formatter = new LengthFormatter($obj->getLength());
|
$formatter = new LengthFormatter($obj->getLength());
|
||||||
$this->view->length = $formatter->format();
|
$this->view->length = $formatter->format();
|
||||||
|
@ -94,7 +94,11 @@ class PlaylistController extends Zend_Controller_Action
|
||||||
} else {
|
} else {
|
||||||
$this->view->obj = $obj;
|
$this->view->obj = $obj;
|
||||||
$this->view->id = $obj->getId();
|
$this->view->id = $obj->getId();
|
||||||
$this->view->html = $this->view->render($viewPath);
|
if ($isJson) {
|
||||||
|
return $this->view->html = $this->view->render($viewPath);
|
||||||
|
} else {
|
||||||
|
$this->view->html = $this->view->render($viewPath);
|
||||||
|
}
|
||||||
unset($this->view->obj);
|
unset($this->view->obj);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -537,6 +541,26 @@ class PlaylistController extends Zend_Controller_Action
|
||||||
$this->playlistUnknownError($e);
|
$this->playlistUnknownError($e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function shuffleAction()
|
||||||
|
{
|
||||||
|
$request = $this->getRequest();
|
||||||
|
$params = $request->getPost();
|
||||||
|
try {
|
||||||
|
$pl = new Application_Model_Playlist($params['obj_id']);
|
||||||
|
$result = $pl->shuffle();
|
||||||
|
|
||||||
|
if ($result['result'] == 0) {
|
||||||
|
die(json_encode(array("result"=>0, "html"=>$this->createFullResponse($pl, true))));
|
||||||
|
} else {
|
||||||
|
die(json_encode($result));
|
||||||
|
}
|
||||||
|
} catch (PlaylistNotFoundException $e) {
|
||||||
|
$this->playlistNotFound('block', true);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$this->playlistUnknownError($e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function getBlockInfoAction()
|
public function getBlockInfoAction()
|
||||||
{
|
{
|
||||||
|
|
|
@ -387,8 +387,8 @@ SQL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($obj)) {
|
if (isset($obj)) {
|
||||||
if (($obj instanceof CcFiles && $obj->visible())
|
if (($obj instanceof CcFiles && $obj->visible())
|
||||||
|| $obj instanceof CcWebstream ||
|
|| $obj instanceof CcWebstream ||
|
||||||
$obj instanceof CcBlock) {
|
$obj instanceof CcBlock) {
|
||||||
|
|
||||||
$entry = $this->plItem;
|
$entry = $this->plItem;
|
||||||
|
@ -933,6 +933,29 @@ SQL;
|
||||||
{
|
{
|
||||||
CcPlaylistcontentsQuery::create()->findByDbPlaylistId($this->id)->delete();
|
CcPlaylistcontentsQuery::create()->findByDbPlaylistId($this->id)->delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function shuffle()
|
||||||
|
{
|
||||||
|
$sql = <<<SQL
|
||||||
|
SELECT max(position) from cc_playlistcontents WHERE playlist_id=:p1
|
||||||
|
SQL;
|
||||||
|
$out = Application_Common_Database::prepareAndExecute($sql, array("p1"=>$this->id));
|
||||||
|
$maxPosition = $out[0]['max'];
|
||||||
|
|
||||||
|
$map = range(0, $maxPosition);
|
||||||
|
shuffle($map);
|
||||||
|
|
||||||
|
$currentPos = implode(',', array_keys($map));
|
||||||
|
$sql = "UPDATE cc_playlistcontents SET position = CASE position ";
|
||||||
|
foreach ($map as $current => $after) {
|
||||||
|
$sql .= sprintf("WHEN %d THEN %d ", $current, $after);
|
||||||
|
}
|
||||||
|
$sql .= "END WHERE position IN ($currentPos) and playlist_id=:p1";
|
||||||
|
|
||||||
|
Application_Common_Database::prepareAndExecute($sql, array("p1"=>$this->id));
|
||||||
|
$result['result'] = 0;
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
} // class Playlist
|
} // class Playlist
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,9 @@ if (isset($this->obj)) {
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<?php if (isset($this->obj)) : ?>
|
<?php if (isset($this->obj)) : ?>
|
||||||
|
<div class='btn-group pull-right'>
|
||||||
|
<button class="btn btn-inverse" title='Shuffle playlist' type="button" id="playlist_shuffle_button">Shuffle</button>
|
||||||
|
</div>
|
||||||
<div class='btn-group pull-right'>
|
<div class='btn-group pull-right'>
|
||||||
<button class="btn btn-inverse" title='Save playlist' type="button" id="save_button">Save</button>
|
<button class="btn btn-inverse" title='Save playlist' type="button" id="save_button">Save</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -637,6 +637,26 @@ var AIRTIME = (function(AIRTIME){
|
||||||
$fs.addClass("closed");
|
$fs.addClass("closed");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
$pl.on("click", 'button[id="playlist_shuffle_button"]', function(){
|
||||||
|
obj_id = $('input[id="obj_id"]').val();
|
||||||
|
url = "/Playlist/shuffle";
|
||||||
|
enableLoadingIcon();
|
||||||
|
$.post(url, {format: "json", obj_id: obj_id}, function(data){
|
||||||
|
var json = $.parseJSON(data)
|
||||||
|
|
||||||
|
if (json.error !== undefined) {
|
||||||
|
alert(json.error);
|
||||||
|
}
|
||||||
|
AIRTIME.playlist.fnOpenPlaylist(json);
|
||||||
|
if (json.result == "0") {
|
||||||
|
$pl.find('.success').text('Playlist shuffled');
|
||||||
|
$pl.find('.success').show();
|
||||||
|
}
|
||||||
|
disableLoadingIcon();
|
||||||
|
});
|
||||||
|
})
|
||||||
|
|
||||||
$pl.on("click", "#webstream_save", function(){
|
$pl.on("click", "#webstream_save", function(){
|
||||||
//get all fields and POST to server
|
//get all fields and POST to server
|
||||||
|
|
|
@ -351,7 +351,7 @@ function setupUI() {
|
||||||
* It is only active if playlist is not empty
|
* It is only active if playlist is not empty
|
||||||
*/
|
*/
|
||||||
var plContents = $('#spl_sortable').children();
|
var plContents = $('#spl_sortable').children();
|
||||||
var shuffleButton = $('button[id="shuffle_button"]');
|
var shuffleButton = $('button[id="shuffle_button"], button[id="playlist_shuffle_button"]');
|
||||||
|
|
||||||
if (!plContents.hasClass('spl_empty')) {
|
if (!plContents.hasClass('spl_empty')) {
|
||||||
if (shuffleButton.hasClass('ui-state-disabled')) {
|
if (shuffleButton.hasClass('ui-state-disabled')) {
|
||||||
|
|
Loading…
Reference in New Issue