CC-3174 : showbuilder

refactoring playlist to work with group add/delete by resource id and using transactions.
This commit is contained in:
Naomi Aro 2012-02-04 15:52:31 +01:00
parent bdc9707052
commit 46fdf56b70
10 changed files with 471 additions and 409 deletions

View file

@ -8,8 +8,8 @@ class PlaylistController extends Zend_Controller_Action
{
$ajaxContext = $this->_helper->getHelper('AjaxContext');
$ajaxContext->addActionContext('add-items', 'json')
->addActionContext('move-item', 'json')
->addActionContext('delete-item', 'json')
->addActionContext('move-items', 'json')
->addActionContext('delete-items', 'json')
->addActionContext('set-fade', 'json')
->addActionContext('set-cue', 'json')
->addActionContext('new', 'json')
@ -165,7 +165,7 @@ class PlaylistController extends Zend_Controller_Action
$ids = $this->_getParam('ids');
$ids = (!is_array($ids)) ? array($ids) : $ids;
$afterItem = $this->_getParam('afterItem', null);
//$afterItem = (!is_numeric($afterItem)) ? null : intval($afterItem);
try {
$pl = $this->getPlaylist();
@ -184,11 +184,12 @@ class PlaylistController extends Zend_Controller_Action
$this->createUpdateResponse($pl);
}
public function moveItemAction()
public function moveItemsAction()
{
$ids = $this->_getParam('ids');
$ids = (!is_array($ids)) ? array($ids) : $ids;
$afterItem = $this->_getParam('afterItem', null);
//$afterItem = (!is_numeric($afterItem)) ? null : intval($afterItem);
try {
$pl = $this->getPlaylist();

View file

@ -22,7 +22,7 @@
<div class="wrapper">
<!--Set to z-index 254 to make it lower than the top-panel and the ZFDebug info bar, but higher than the side-playlist-->
<div id="library_content" class="tabs ui-widget ui-widget-content block-shadow alpha-block padded" style="z-index:254"><?php echo $this->layout()->library ?></div>
<div id="show_builder" style="width:600px;" class="ui-widget ui-widget-content block-shadow omega-block padded"><?php echo $this->layout()->builder ?></div>
<div id="show_builder" class="ui-widget ui-widget-content block-shadow omega-block padded"><?php echo $this->layout()->builder ?></div>
</div>
</body>
</html>

View file

@ -119,7 +119,11 @@ class Application_Model_Playlist {
return $this->pl->getDbDescription();
}
public function getSize() {
public function getLastModified($format = null) {
return $this->pl->getDbMtime($format);
}
public function getSize() {
return $this->pl->countCcPlaylistcontentss();
}
@ -274,6 +278,55 @@ class Application_Model_Playlist {
try {
$contentsToMove = CcPlaylistcontentsQuery::create()
->filterByDbId($p_items, Criteria::IN)
->orderByDbPosition()
->find($this->con);
$otherContent = CcPlaylistcontentsQuery::create()
->filterByDbId($p_items, Criteria::NOT_IN)
->filterByDbPlaylistId($this->id)
->orderByDbPosition()
->find($this->con);
$pos = 0;
//moving items to beginning of the playlist.
if (is_null($p_afterItem)) {
Logging::log("moving items to beginning of playlist");
foreach ($contentsToMove as $item) {
Logging::log("item {$item->getDbId()} to pos {$pos}");
$item->setDbPosition($pos);
$item->save($this->con);
$pos = $pos + 1;
}
foreach ($otherContent as $item) {
Logging::log("item {$item->getDbId()} to pos {$pos}");
$item->setDbPosition($pos);
$item->save($this->con);
$pos = $pos + 1;
}
}
else {
Logging::log("moving items after {$p_afterItem}");
foreach ($otherContent as $item) {
Logging::log("item {$item->getDbId()} to pos {$pos}");
$item->setDbPosition($pos);
$item->save($this->con);
$pos = $pos + 1;
if ($item->getDbId() == $p_afterItem) {
foreach ($contentsToMove as $move) {
Logging::log("item {$move->getDbId()} to pos {$pos}");
$move->setDbPosition($pos);
$move->save($this->con);
$pos = $pos + 1;
}
}
}
}
$this->con->commit();
}
catch (Exception $e) {

View file

@ -15,5 +15,66 @@
*/
class CcPlaylist extends BaseCcPlaylist {
/**
* Get the [optionally formatted] temporal [utime] column value.
*
*
* @param string $format The date/time format string (either date()-style or strftime()-style).
* If format is NULL, then the raw DateTime object will be returned.
* @return mixed Formatted date/time value as string or DateTime object (if format is NULL), NULL if column is NULL
* @throws PropelException - if unable to parse/validate the date/time value.
*/
public function getDbUtime($format = 'Y-m-d H:i:s')
{
if ($this->utime === null) {
return null;
}
try {
$dt = new DateTime($this->utime, new DateTimeZone("UTC"));
} catch (Exception $x) {
throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->utime, true), $x);
}
if ($format === null) {
// Because propel.useDateTimeClass is TRUE, we return a DateTime object.
return $dt;
} elseif (strpos($format, '%') !== false) {
return strftime($format, $dt->format('U'));
} else {
return $dt->format($format);
}
}
/**
* Get the [optionally formatted] temporal [mtime] column value.
*
*
* @param string $format The date/time format string (either date()-style or strftime()-style).
* If format is NULL, then the raw DateTime object will be returned.
* @return mixed Formatted date/time value as string or DateTime object (if format is NULL), NULL if column is NULL
* @throws PropelException - if unable to parse/validate the date/time value.
*/
public function getDbMtime($format = 'Y-m-d H:i:s')
{
if ($this->mtime === null) {
return null;
}
try {
$dt = new DateTime($this->mtime, new DateTimeZone("UTC"));
} catch (Exception $x) {
throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->mtime, true), $x);
}
if ($format === null) {
// Because propel.useDateTimeClass is TRUE, we return a DateTime object.
return $dt;
} elseif (strpos($format, '%') !== false) {
return strftime($format, $dt->format('U'));
} else {
return $dt->format($format);
}
}
} // CcPlaylist

View file

@ -1,12 +1,14 @@
<button id="spl_new" class="ui-button" role="button" aria-disabled="false">New</button>
<button id="spl_new" class="ui-button ui-widget ui-state-default" role="button" aria-disabled="false">New</button>
<?php if (isset($this->pl)) : ?>
<button id="spl_delete" class="ui-button" role="button" aria-disabled="false">Delete</button>
<button id="spl_delete" class="ui-button ui-widget ui-state-default" role="button" aria-disabled="false">Delete</button>
<a href="#" id="spl_crossfade" class="ui-button ui-button-icon-only ui-widget ui-state-default crossfade-main-button">
<span class="ui-icon crossfade-main-icon"></span><span class="ui-button-text">Playlist crossfade</span>
</a>
<?php endif; ?>
<?php if (isset($this->pl)) : ?>
<input id="pl_id" type="hidden" value="<?php echo $this->pl->getId(); ?>"></input>
<input id="pl_lastMod" type="hidden" value="<?php echo $this->pl->getLastModified('U'); ?>"></input>
<div class="playlist_title">
<h3 id="spl_name">
<a id="playlist_name_display"><?php echo $this->pl->getName(); ?></a>

View file

@ -25,7 +25,7 @@ if (count($items)) : ?>
?>
<div id="fade_<?php echo $i ?>" class="spl_fade_control ui-state-default"></div>
<?php endif; ?>
<span class="ui-icon ui-icon-closethick"></span>
<span id="remove_<?php echo $item["id"] ?>" class="ui-icon ui-icon-closethick"></span>
</div>
<div id="cues_<?php echo $i ?>" class="cue-edit clearfix" style="display: none">