Merge branch 'devel' of dev.sourcefabric.org:airtime into devel

This commit is contained in:
denise 2012-11-20 11:17:03 -05:00
commit e0b19cc2d1
35 changed files with 760 additions and 315 deletions

View file

@ -25,6 +25,7 @@ class PlaylistController extends Zend_Controller_Action
->addActionContext('smart-block-generate', 'json')
->addActionContext('smart-block-shuffle', 'json')
->addActionContext('get-block-info', 'json')
->addActionContext('shuffle', 'json')
->initContext();
}
@ -72,7 +73,6 @@ class PlaylistController extends Zend_Controller_Action
$isBlock = true;
$viewPath = 'playlist/smart-block.phtml';
}
if (isset($obj)) {
$formatter = new LengthFormatter($obj->getLength());
$this->view->length = $formatter->format();
@ -94,7 +94,11 @@ class PlaylistController extends Zend_Controller_Action
} else {
$this->view->obj = $obj;
$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);
}
} else {
@ -537,6 +541,26 @@ class PlaylistController extends Zend_Controller_Action
$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()
{

View file

@ -387,8 +387,8 @@ SQL;
}
if (isset($obj)) {
if (($obj instanceof CcFiles && $obj->visible())
|| $obj instanceof CcWebstream ||
if (($obj instanceof CcFiles && $obj->visible())
|| $obj instanceof CcWebstream ||
$obj instanceof CcBlock) {
$entry = $this->plItem;
@ -933,6 +933,29 @@ SQL;
{
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

View file

@ -16,6 +16,9 @@ if (isset($this->obj)) {
</ul>
</div>
<?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'>
<button class="btn btn-inverse" title='Save playlist' type="button" id="save_button">Save</button>
</div>