From 46fdf56b708bc05e8af02c4b56ac040135d6f66e Mon Sep 17 00:00:00 2001 From: Naomi Aro Date: Sat, 4 Feb 2012 15:52:31 +0100 Subject: [PATCH] CC-3174 : showbuilder refactoring playlist to work with group add/delete by resource id and using transactions. --- .../controllers/PlaylistController.php | 9 +- .../application/layouts/scripts/builder.phtml | 2 +- airtime_mvc/application/models/Playlist.php | 55 +- .../application/models/airtime/CcPlaylist.php | 61 ++ .../views/scripts/playlist/index.phtml | 6 +- .../views/scripts/playlist/update.phtml | 2 +- .../library/events/library_playlistbuilder.js | 2 +- .../library/events/library_showbuilder.js | 1 + airtime_mvc/public/js/airtime/library/spl.js | 737 ++++++++---------- .../public/js/airtime/showbuilder/builder.js | 5 +- 10 files changed, 471 insertions(+), 409 deletions(-) diff --git a/airtime_mvc/application/controllers/PlaylistController.php b/airtime_mvc/application/controllers/PlaylistController.php index fa2918d32..c508f5037 100644 --- a/airtime_mvc/application/controllers/PlaylistController.php +++ b/airtime_mvc/application/controllers/PlaylistController.php @@ -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(); diff --git a/airtime_mvc/application/layouts/scripts/builder.phtml b/airtime_mvc/application/layouts/scripts/builder.phtml index abf2ad41f..3efba392c 100644 --- a/airtime_mvc/application/layouts/scripts/builder.phtml +++ b/airtime_mvc/application/layouts/scripts/builder.phtml @@ -22,7 +22,7 @@
layout()->library ?>
-
layout()->builder ?>
+
layout()->builder ?>
diff --git a/airtime_mvc/application/models/Playlist.php b/airtime_mvc/application/models/Playlist.php index 027ac163c..2023da474 100644 --- a/airtime_mvc/application/models/Playlist.php +++ b/airtime_mvc/application/models/Playlist.php @@ -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) { diff --git a/airtime_mvc/application/models/airtime/CcPlaylist.php b/airtime_mvc/application/models/airtime/CcPlaylist.php index a5766df63..c7303e8b1 100644 --- a/airtime_mvc/application/models/airtime/CcPlaylist.php +++ b/airtime_mvc/application/models/airtime/CcPlaylist.php @@ -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 diff --git a/airtime_mvc/application/views/scripts/playlist/index.phtml b/airtime_mvc/application/views/scripts/playlist/index.phtml index 134cfa047..4fc1912bb 100644 --- a/airtime_mvc/application/views/scripts/playlist/index.phtml +++ b/airtime_mvc/application/views/scripts/playlist/index.phtml @@ -1,12 +1,14 @@ - + pl)) : ?> - + Playlist crossfade pl)) : ?> + +

pl->getName(); ?> diff --git a/airtime_mvc/application/views/scripts/playlist/update.phtml b/airtime_mvc/application/views/scripts/playlist/update.phtml index b8a99fabf..464f6a58a 100644 --- a/airtime_mvc/application/views/scripts/playlist/update.phtml +++ b/airtime_mvc/application/views/scripts/playlist/update.phtml @@ -25,7 +25,7 @@ if (count($items)) : ?> ?>
- + " class="ui-icon ui-icon-closethick">