diff --git a/airtime_mvc/application/Bootstrap.php b/airtime_mvc/application/Bootstrap.php index 04ac05feb..5ba9d7dd5 100644 --- a/airtime_mvc/application/Bootstrap.php +++ b/airtime_mvc/application/Bootstrap.php @@ -73,7 +73,7 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap //scripts for now playing bar $view->headScript()->appendFile($baseUrl.'/js/airtime/dashboard/helperfunctions.js','text/javascript'); - $view->headScript()->appendFile($baseUrl.'/js/airtime/dashboard/playlist.js','text/javascript'); + //$view->headScript()->appendFile($baseUrl.'/js/airtime/dashboard/playlist.js','text/javascript'); $view->headScript()->appendFile($baseUrl.'/js/airtime/dashboard/versiontooltip.js','text/javascript'); $view->headScript()->appendFile($baseUrl.'/js/airtime/common/common.js','text/javascript'); @@ -132,16 +132,6 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap 'controller' => 'auth', 'action' => 'password-change', ))); - - /* - $router->addRoute( - 'show-builder', - new Zend_Controller_Router_Route('show/builder/:show_instance_id/:user_id', array( - 'module' => 'default', - 'controller' => 'showbuilder', - 'action' => 'index', - ))); - */ } } diff --git a/airtime_mvc/application/controllers/LibraryController.php b/airtime_mvc/application/controllers/LibraryController.php index 97b5fbdff..da0f10e1b 100644 --- a/airtime_mvc/application/controllers/LibraryController.php +++ b/airtime_mvc/application/controllers/LibraryController.php @@ -134,43 +134,6 @@ class LibraryController extends Zend_Controller_Action } public function deleteAction() - { - $id = $this->_getParam('id'); - $userInfo = Zend_Auth::getInstance()->getStorage()->read(); - $user = new Application_Model_User($userInfo->id); - - if ($user->isAdmin()) { - - if (!is_null($id)) { - $file = Application_Model_StoredFile::Recall($id); - - if (PEAR::isError($file)) { - $this->view->message = $file->getMessage(); - return; - } - else if(is_null($file)) { - $this->view->message = "file doesn't exist"; - return; - } - - $res = $file->delete(); - - if (PEAR::isError($res)) { - $this->view->message = $res->getMessage(); - return; - } - else { - $res = settype($res, "integer"); - $data = array("filepath" => $file->getFilePath(), "delete" => $res); - Application_Model_RabbitMq::SendMessageToMediaMonitor("file_delete", $data); - } - } - - $this->view->id = $id; - } - } - - public function deleteGroupAction() { $ids = $this->_getParam('ids'); $userInfo = Zend_Auth::getInstance()->getStorage()->read(); diff --git a/airtime_mvc/application/controllers/PlaylistController.php b/airtime_mvc/application/controllers/PlaylistController.php index 7618d94c9..b005f709a 100644 --- a/airtime_mvc/application/controllers/PlaylistController.php +++ b/airtime_mvc/application/controllers/PlaylistController.php @@ -7,17 +7,14 @@ class PlaylistController extends Zend_Controller_Action public function init() { $ajaxContext = $this->_helper->getHelper('AjaxContext'); - $ajaxContext->addActionContext('add-item', 'json') + $ajaxContext->addActionContext('add-items', 'json') + ->addActionContext('add-item', 'json') + ->addActionContext('move-item', 'json') ->addActionContext('delete-item', 'json') - ->addActionContext('add-group', 'json') - ->addActionContext('delete-group', 'json') ->addActionContext('set-fade', 'json') ->addActionContext('set-cue', 'json') - ->addActionContext('move-item', 'json') - ->addActionContext('close', 'json') ->addActionContext('new', 'json') ->addActionContext('edit', 'json') - ->addActionContext('delete-active', 'json') ->addActionContext('delete', 'json') ->addActionContext('set-playlist-fades', 'json') ->addActionContext('set-playlist-name', 'json') @@ -48,33 +45,36 @@ class PlaylistController extends Zend_Controller_Action { $pl_sess = $this->pl_sess; - if(isset($pl_sess->id)) { - - $pl = Application_Model_Playlist::Recall($pl_sess->id); - if($pl !== FALSE) { - $this->closePlaylist($pl); - } - } - - $userInfo = Zend_Auth::getInstance()->getStorage()->read(); - $pl = Application_Model_Playlist::Recall($pl_id); if($pl === FALSE) { return FALSE; } - $pl->lock($userInfo->id); + $pl_sess->id = $pl_id; } - private function closePlaylist($pl) + private function createUpdateResponse($pl) { - $userInfo = Zend_Auth::getInstance()->getStorage()->read(); - $res = $pl->unlock($userInfo->id); + $this->view->pl = $pl; + $this->view->html = $this->view->render('playlist/update.phtml'); + $this->view->name = $pl->getName(); + $this->view->length = $pl->getLength(); + $this->view->description = $pl->getDescription(); - $pl_sess = $this->pl_sess; - unset($pl_sess->id); + unset($this->view->pl); + } - return $res; + private function createFullResponse($pl = null) + { + if (isset($pl)) { + $this->view->pl = $pl; + $this->view->pl_id = $pl->getId(); + $this->view->html = $this->view->render('playlist/index.phtml'); + unset($this->view->pl); + } + else { + $this->view->html = $this->view->render('playlist/index.phtml'); + } } public function indexAction() @@ -103,10 +103,7 @@ class PlaylistController extends Zend_Controller_Action $this->changePlaylist($pl->getId()); - $this->view->pl = $pl; - $this->view->pl_id = $pl->getId(); - $this->view->html = $this->view->render('playlist/index.phtml'); - unset($this->view->pl); + $this->createFullResponse($pl); } public function editAction() @@ -123,10 +120,7 @@ class PlaylistController extends Zend_Controller_Action return false; } - $this->view->pl = $pl; - $this->view->pl_id = $pl->getId(); - $this->view->html = $this->view->render('playlist/index.phtml'); - unset($this->view->pl); + $this->createFullResponse($pl); } public function addItemAction() @@ -147,13 +141,7 @@ class PlaylistController extends Zend_Controller_Action $this->view->message = $res->getMessage(); } - $this->view->pl = $pl; - $this->view->html = $this->view->render('playlist/update.phtml'); - $this->view->name = $pl->getName(); - $this->view->length = $pl->getLength(); - $this->view->description = $pl->getDescription(); - - unset($this->view->pl); + $this->createUpdateResponse($pl); return; } $this->view->message = "a file is not chosen"; @@ -172,13 +160,7 @@ class PlaylistController extends Zend_Controller_Action $pl->moveAudioClip($oldPos, $newPos); - $this->view->pl = $pl; - $this->view->html = $this->view->render('playlist/update.phtml'); - $this->view->name = $pl->getName(); - $this->view->length = $pl->getLength(); - $this->view->description = $pl->getDescription(); - - unset($this->view->pl); + $this->createUpdateResponse($pl); } public function deleteItemAction() @@ -202,16 +184,10 @@ class PlaylistController extends Zend_Controller_Action $pl->delAudioClip($pos); } - $this->view->pl = $pl; - $this->view->html = $this->view->render('playlist/update.phtml'); - $this->view->name = $pl->getName(); - $this->view->length = $pl->getLength(); - $this->view->description = $pl->getDescription(); - - unset($this->view->pl); + $this->createUpdateResponse($pl); } - public function addGroupAction() + public function addItemsAction() { $ids = $this->_getParam('ids'); $pos = $this->_getParam('pos', null); @@ -222,7 +198,7 @@ class PlaylistController extends Zend_Controller_Action $this->view->playlist_error = true; return false; } - + foreach ($ids as $key => $value) { $res = $pl->addAudioClip($value); if (PEAR::isError($res)) { @@ -231,20 +207,21 @@ class PlaylistController extends Zend_Controller_Action } } - $this->view->pl = $pl; - $this->view->html = $this->view->render('playlist/update.phtml'); - $this->view->name = $pl->getName(); - $this->view->length = $pl->getLength(); - $this->view->description = $pl->getDescription(); + $this->createUpdateResponse($pl); return; } $this->view->message = "a file is not chosen"; } - - public function deleteGroupAction() + + public function deleteAction() { - $ids = $this->_getParam('ids', null); - + $ids = $this->_getParam('ids', array()); + $active = $this->_getParam('active', false); + + if ($active === true) { + $ids = array_merge($ids, array($pl_sess->id)); + } + foreach ($ids as $key => $id) { $pl = Application_Model_Playlist::Recall($id); @@ -259,11 +236,10 @@ class PlaylistController extends Zend_Controller_Action return false; } } - - $this->view->ids = $ids; - $this->view->html = $this->view->render('playlist/index.phtml'); + + $this->createFullResponse(null); } - + public function setCueAction() { $pos = $this->_getParam('pos'); @@ -281,13 +257,7 @@ class PlaylistController extends Zend_Controller_Action $this->view->response = $response; if(!isset($response["error"])) { - $this->view->pl = $pl; - $this->view->html = $this->view->render('playlist/update.phtml'); - $this->view->name = $pl->getName(); - $this->view->length = $pl->getLength(); - $this->view->description = $pl->getDescription(); - - unset($this->view->pl); + $this->createUpdateResponse($pl); } } @@ -308,66 +278,10 @@ class PlaylistController extends Zend_Controller_Action $this->view->response = $response; if(!isset($response["error"])) { - $this->view->pl = $pl; - $this->view->html = $this->view->render('playlist/update.phtml'); - $this->view->name = $pl->getName(); - $this->view->length = $pl->getLength(); - $this->view->description = $pl->getDescription(); - - unset($this->view->pl); + $this->createUpdateResponse($pl); } } - public function deleteAction() - { - $id = $this->_getParam('id', null); - $pl = Application_Model_Playlist::Recall($id); - - if ($pl !== FALSE) { - - Application_Model_Playlist::Delete($id); - - $pl_sess = $this->pl_sess; - - if($pl_sess->id === $id){ - unset($pl_sess->id); - } - }else{ - $this->view->playlist_error = true; - return false; - } - - $this->view->id = $id; - $this->view->html = $this->view->render('playlist/index.phtml'); - } - - public function deleteActiveAction() - { - $pl = $this->getPlaylist(); - if($pl === false){ - $this->view->playlist_error = true; - return false; - } - Application_Model_Playlist::Delete($pl->getId()); - - $pl_sess = $this->pl_sess; - unset($pl_sess->id); - - $this->view->html = $this->view->render('playlist/index.phtml'); - } - - public function closeAction() - { - $pl = $this->getPlaylist(); - if($pl === false){ - $this->view->playlist_error = true; - return false; - } - $this->closePlaylist($pl); - - $this->view->html = $this->view->render('playlist/index.phtml'); - } - public function setPlaylistFadesAction() { $request = $this->getRequest(); diff --git a/airtime_mvc/application/models/Playlist.php b/airtime_mvc/application/models/Playlist.php index 98d6aaa06..a5b69a81a 100644 --- a/airtime_mvc/application/models/Playlist.php +++ b/airtime_mvc/application/models/Playlist.php @@ -1,361 +1,73 @@ "DbName", "dc:creator" => "DbCreator", "dc:description" => "DbDescription", "dcterms:extent" => "length"); - - - public function __construct() - { - - } - - /** -- * Convert playlist time value to float seconds -- * -- * @param string $plt -- * playlist time value (HH:mm:ss.dddddd) -- * @return int -- * seconds -- */ - public static function playlistTimeToSeconds($plt) - { - $arr = preg_split('/:/', $plt); - if (isset($arr[2])) { - return (intval($arr[0])*60 + intval($arr[1]))*60 + floatval($arr[2]); - } - if (isset($arr[1])) { - return intval($arr[0])*60 + floatval($arr[1]); - } - return floatval($arr[0]); - } - - - /** -- * Convert float seconds value to playlist time format -- * -- * @param float $seconds -- * @return string -- * time in playlist time format (HH:mm:ss.d) -- */ - public static function secondsToPlaylistTime($p_seconds) - { - $seconds = $p_seconds; - $rounded = round($seconds, 1); - $info = explode('.', $rounded); - $seconds = $info[0]; - if(!isset($info[1])){ - $milliStr = 0; - }else{ - $milliStr = $info[1]; - } - $hours = floor($seconds / 3600); - $seconds -= $hours * 3600; - $minutes = floor($seconds / 60); - $seconds -= $minutes * 60; - - $res = sprintf("%02d:%02d:%02d.%s", $hours, $minutes, $seconds, $milliStr); - - return $res; - } - - - public static function Delete($id) - { - $pl = CcPlaylistQuery::create()->findPK($id); - if($pl === NULL) - return FALSE; - - $pl->delete(); - return TRUE; - } - - public static function deleteAll() - { - global $CC_CONFIG, $CC_DBC; - $sql = 'DELETE FROM '.$CC_CONFIG["playListTable"]; - $CC_DBC->query($sql); - } - - public static function getPlaylistCount(){ - global $CC_CONFIG, $CC_DBC; - $sql = 'SELECT count(*) as cnt FROM '.$CC_CONFIG["playListTable"]; - return $CC_DBC->GetOne($sql); - } - - /** - * Delete the file from all playlists. - * @param string $p_fileId - */ - public static function DeleteFileFromAllPlaylists($p_fileId) - { - CcPlaylistcontentsQuery::create()->filterByDbFileId($p_fileId)->delete(); - } - - - public static function findPlaylistByName($p_name) - { - $res = CcPlaylistQuery::create()->findByDbName($p_name); - return $res; - } - - /** - * Fetch instance of Playlist object.
- * - * @param string $id - * DB id of file - * @return Playlist|FALSE - * Return FALSE if the object doesnt exist in the DB. - */ - public static function Recall($id) { - - $pl = CcPlaylistQuery::create()->findPK($id); - if($pl === NULL) - return FALSE; - - $storedPlaylist = new Application_Model_Playlist(); - $storedPlaylist->id = $id; - $storedPlaylist->name = $pl->getDbName(); - $storedPlaylist->state = $pl->getDbState(); - $storedPlaylist->currentlyaccessing = $pl->getDbCurrentlyaccessing(); - $storedPlaylist->editedby = $pl->getDbEditedby(); - $storedPlaylist->mtime = $pl->getDbMtime(); - - return $storedPlaylist; - } - - /** - * Rename stored virtual playlist - * - * @param string $p_newname - * @return TRUE|PEAR_Error - */ - public function setName($p_newname) - { - $pl = CcPlaylistQuery::create()->findPK($this->id); - - if($pl === NULL) - return FALSE; - - $pl->setDbName($p_newname); - $pl->setDbMtime(new DateTime("now"), new DateTimeZone("UTC")); - $pl->save(); - - $this->name = $p_newname; - return TRUE; - } - - /** - * Get mnemonic playlist name - * - * @param string $p_gunid - * global unique id of playlist - * @return string - */ - public function getName($id=NULL) - { - if (is_null($id)) { - return $this->name; - } - $pl = CcPlaylistQuery::create()->findPK($id); - if ($pl === NULL) - return FALSE; - - return $pl->getDbName(); - } - - public function setDescription($p_description) - { - $pl = CcPlaylistQuery::create()->findPK($this->id); - - if($pl === NULL) - return FALSE; - - $pl->setDbDescription($p_description); - $pl->setDbMtime(new DateTime("now"), new DateTimeZone("UTC")); - $pl->save(); - - //$this->name = $p_newname; - return TRUE; - } - - public function getDescription() - { - $pl = CcPlaylistQuery::create()->findPK($this->id); - if ($pl === NULL) - return FALSE; - - return $pl->getDbDescription(); - } - /** - * Set state of virtual playlist - * - * @param string $p_state - * 'empty'|'incomplete'|'ready'|'edited' - * @param int $p_editedby - * user id | 'NULL' for clear editedBy field - * @return TRUE|PEAR_Error + * info needed to insert a new playlist element. */ - public function setState($p_state, $p_editedby=NULL) + private $plItem = array( + "id" => "", + "pos" => "", + "cliplength" => "", + "cuein" => "00:00:00", + "cueout" => "00:00:00", + "fadein" => "00:00:00", + "fadeout" => "00:00:00", + ); + + //using propel's phpNames. + private $categories = array( + "dc:title" => "DbName", + "dc:creator" => "DbCreator", + "dc:description" => "DbDescription", + "dcterms:extent" => "length" + ); + + + public function __construct($id=null, $con=null) { - $pl = CcPlaylistQuery::create()->findPK($this->id); - - if($pl === NULL) - return FALSE; - - $pl->setDbState($p_state); - $pl->setDbMtime(new DateTime("now"), new DateTimeZone("UTC")); - - $eb = (!is_null($p_editedby) ? $p_editedby : NULL); - $pl->setDbEditedby($eb); - - $pl->save(); - - $this->state = $p_state; - $this->editedby = $p_editedby; - return TRUE; - } - - /** - * Get storage-internal file state - * - * @param string $p_gunid - * global unique id of file - * @return string - * see install() - */ - public function getState($id=NULL) - { - if (is_null($id)) { - return $this->state; + if (isset($id)) { + $this->pl = CcPlaylistQuery::create()->findPK($id); + } + else { + $this->pl = new CcPlaylist(); + $this->pl->setDbUtime(new DateTime("now"), new DateTimeZone("UTC")); } - $pl = CcPlaylistQuery::create()->findPK($id); - if($pl === NULL) - return FALSE; + $this->plItem["fadein"] = Application_Model_Preference::GetDefaultFade(); + $this->plItem["fadeout"] = Application_Model_Preference::GetDefaultFade(); - return $pl->getDbState(); - } - - /** - * Returns true if virtual file is currently in use.
- * Static or dynamic call is possible. - * - * @param string $p_gunid - * optional (for static call), global unique id - * @return boolean|PEAR_Error - */ - public function isAccessed($id=NULL) - { - if (is_null($id)) { - return ($this->currentlyaccessing > 0); - } - - $pl = CcPlaylistQuery::create()->findPK($id); - if (is_null($pl)) { - return PEAR::raiseError( - "StoredPlaylist::isAccessed: invalid id ($id)", - GBERR_FOBJNEX - ); - } - - return ($pl->getDbCurrentlyaccessing() > 0); + $this->id = $this->pl->getDbId(); + $this->con = isset($con) ? $con : Propel::getConnection(CcPlaylistPeer::DATABASE_NAME); } /** - * Returns id of user editing playlist - * - * @param string $p_playlistId - * playlist global unique ID - * @return int id of user editing playlist - */ - public function isEdited() { - - if($this->state === 'edited') { - return $this->editedby; - } - return FALSE; - } - -/** - * Set playlist edit flag - * - * @param string $p_playlistId - * Playlist unique ID - * @param boolean $p_val - * Set/clear of edit flag - * @param string $p_sessid - * Session id - * @param int $p_subjid - * Subject id (if sessid is not specified) - * @return boolean - * TRUE on success. - */ - - public function setEditFlag($p_subjid, $p_val=TRUE) { - - if ($p_val) { - $r = $this->setState('edited', $p_subjid); - } else { - $r = $this->setState('ready'); - } - if ($r === FALSE) { - return FALSE; - } - return TRUE; - } - - /** * Return local ID of virtual file. * * @return int @@ -364,28 +76,43 @@ class Application_Model_Playlist { return $this->id; } - private function getNextPos() { + /** + * Rename stored virtual playlist + * + * @param string $p_newname + */ + public function setName($p_newname) + { + $this->pl->setDbName($p_newname); + $this->pl->setDbMtime(new DateTime("now"), new DateTimeZone("UTC")); + $this->pl->save($this->con); + } - $res = CcPlaylistQuery::create() - ->findPK($this->id) - ->computeLastPosition(); + /** + * Get mnemonic playlist name + * + * @return string + */ + public function getName() + { + return $this->pl->getDbName(); + } - if(is_null($res)) - return 0; + public function setDescription($p_description) + { + $this->pl->setDbDescription($p_description); + $this->pl->setDbMtime(new DateTime("now"), new DateTimeZone("UTC")); + $this->pl->save($this->con); + } - return $res + 1; + public function getDescription() + { + return $this->pl->getDbDescription(); } public function getSize() { - $res = CcPlaylistQuery::create() - ->findPK($this->id) - ->computeLastPosition(); - - if(is_null($res)) - return 0; - - return $res; + return $this->pl->countCcPlaylistcontentss(); } /** @@ -398,7 +125,7 @@ class Application_Model_Playlist { ->joinWith('CcFiles') ->orderByDbPosition() ->filterByDbPlaylistId($this->id) - ->find(); + ->find($this->con); $i = 0; $offset = 0; @@ -415,191 +142,167 @@ class Application_Model_Playlist { return $files; } + //TODO make another aggregate column for playlist length. public function getLength() { + /* $res = CcPlaylistQuery::create() ->findPK($this->id) ->computeLength(); - if(is_null($res)) - return '00:00:00'; - - // calling two functions to format time to 1 decimal place - $sec = Application_Model_Playlist::playlistTimeToSeconds($res); - $res = Application_Model_Playlist::secondsToPlaylistTime($sec); - return $res; - } - - /** - * Create instance of a Playlist object. - * - * @param string $p_fname - * Name of the playlist - * @return Playlist - */ - public function create($p_fname=NULL) - { - $this->name = !empty($p_fname) ? $p_fname : date("H:i:s"); - - $pl = new CcPlaylist(); - $pl->setDbName($this->name); - $pl->setDbState("incomplete"); - $pl->setDbMtime(new DateTime("now"), new DateTimeZone("UTC")); - $pl->setDbUtime(new DateTime("now"), new DateTimeZone("UTC")); - $pl->save(); - - $this->id = $pl->getDbId(); - $this->setState('ready'); - - return $this; - } - - /** - * Lock playlist for edit - * - * @param int $subjid - * local subject (user) id - * @param boolean $val - * if false do unlock - * @return boolean - * previous state or error object - */ - public function lock($subjid, $val=TRUE) - { - if ($val && $this->isEdited() !== FALSE) { - return PEAR::raiseError( - 'Application_Model_Playlist::lock: playlist already locked' - ); + if (is_null($res)) { + $res = '00:00:00'; } - $r = $this->setEditFlag($subjid, $val); - return $r; + */ + + return '00:00:00'; } - /** - * Unlock playlist - * - * @return boolean - * previous state or error object - */ - public function unlock($subjid) + private function insertPlaylistElement($info) { - $r = $this->lock($subjid, FALSE); - return $r; + $row = new CcPlaylistcontents(); + $row->setDbPlaylistId($this->id); + $row->setDbFileId($info["id"]); + $row->setDbPosition($info["pos"]); + $row->setDbCliplength($info["cliplength"]); + $row->setDbCuein($info["cuein"]); + $row->setDbCueout($info["cueout"]); + $row->setDbFadein($info["fadein"]); + $row->setDbFadeout($info["fadeout"]); + $row->save($this->con); } + /* + * + */ + private function buildEntry($p_item, $pos) + { + $file = CcFilesQuery::create()->findPK($p_item["id"], $this->con); + + $entry = $this->plItem; + $entry["id"] = $file->getDbId(); + $entry["pos"] = $pos; + $entry["cliplength"] = $file->getDbLength(); + + return $entry; + } + + /* + * @param array $p_items + * an array of audioclips to add to the playlist + * @param int|null $p_afterItem + * item which to add the new items after in the playlist, null if added to the end. + */ + public function addAudioClips($p_items, $p_afterItem=NULL) + { + $this->con->beginTransaction(); + $contentsToUpdate = array(); + + try { + + if (isset($p_afterItem)) { + $afterItem = CcPlaylistcontentsQuery::create()->findPK($p_afterItem); + + $contentsToUpdate = CcPlaylistcontentsQuery::create() + ->filterByDbPlaylistId($this->id) + ->orderByDbPosition() + ->find(); + + $pos = $afterItem->getDbPosition() + 1; + } + else { + $pos = $this->getSize(); + } + + foreach($p_items as $ac) { + + $res = $this->insertPlaylistElement($this->buildEntry($ac), $pos); + $pos = $pos + 1; + } + + //reset the positions of the remaining items. + for ($i = 0; $i < count($contentsToUpdate); $i++) { + $contents[$i]->setDbPosition($pos); + $contents[$i]->save($this->con); + $pos = $pos + 1; + } + + $pl->setDbMtime(new DateTime("now"), new DateTimeZone("UTC")); + $pl->save($this->con); + + $this->con->commit(); + } + catch (Exception $e) { + $this->con->rollback(); + throw $e; + } + } /** - * Add audio clip to the playlist + * Move audioClip to the new position in the playlist * - * @param string $p_id - * local ID of added file - * @param string $p_position - * optional, Which position in the playlist to insert the audio clip - * @param string $p_fadeIn - * optional, in time format hh:mm:ss.ssssss - total duration - * @param string $p_fadeOut - * optional, in time format hh:mm:ss.ssssss - total duration - * @param string $p_clipLength - * optional length in in time format hh:mm:ss.ssssss - - * for webstream (or for overrule length of audioclip) - * @return true|PEAR_Error - * TRUE on success + * @param array $selectedItems + * array of unique ids of the selected items + * @param int $afterItem + * unique id of the item to move the clip after */ - public function addAudioClip($p_mediaId, $p_position=NULL, $p_fadeIn=NULL, $p_fadeOut=NULL, $p_clipLength=NULL, $p_cuein=NULL, $p_cueout=NULL) + public function moveAudioClip($selectedItems, $afterItem) { - //get audio clip. - $media = Application_Model_StoredFile::Recall($p_mediaId); - if (is_null($media) || PEAR::isError($media)) { - return $media; + $this->con->beginTransaction(); + + try { + + $this->con->commit(); + } + catch (Exception $e) { + $this->con->rollback(); + throw $e; } - $metadata = $media->getMetadata(); - $length = $metadata['MDATA_KEY_DURATION']; - if (!is_null($p_clipLength)) { - $length = $p_clipLength; - } - - // insert at end of playlist. - if (is_null($p_position)) - $p_position = $this->getNextPos(); - - // insert default values if parameter was empty - $p_cuein = !is_null($p_cuein) ? $p_cuein : '00:00:00.000000'; - $p_cueout = !is_null($p_cueout) ? $p_cueout : $length; - - $con = Propel::getConnection(CcPlaylistPeer::DATABASE_NAME); - $sql = "SELECT INTERVAL '{$p_cueout}' - INTERVAL '{$p_cuein}'"; - $r = $con->query($sql); - $p_cliplength = $r->fetchColumn(0); - - $res = $this->insertPlaylistElement($this->id, $p_mediaId, $p_position, $p_cliplength, $p_cuein, $p_cueout, $p_fadeIn, $p_fadeOut); - - $pl = CcPlaylistQuery::create()->findPK($this->id); - $pl->setDbMtime(new DateTime("now"), new DateTimeZone("UTC")); - $pl->save(); - - return TRUE; + $this->pl = CcPlaylistQuery::create()->findPK($this->id); + $this->pl->setDbMtime(new DateTime("now"), new DateTimeZone("UTC")); + $this->pl->save($this->con); } - /** * Remove audioClip from playlist * - * @param int $position - * position of audioclip in the playlist. - * @return boolean + * @param array $p_items + * array of unique item ids to remove from the playlist.. */ - public function delAudioClip($pos) + public function delAudioClips($p_items) { - if($pos < 0 || $pos >= $this->getNextPos()) - return FALSE; + $this->con->beginTransaction(); - $row = CcPlaylistcontentsQuery::create() - ->filterByDbPlaylistId($this->id) - ->filterByDbPosition($pos) - ->findOne(); + try { - if(is_null($row)) - return FALSE; + CcPlaylistcontentsQuery::create() + ->findPKs($p_items) + ->delete(); - $row->delete(); - - $pl = CcPlaylistQuery::create()->findPK($this->id); - $pl->setDbMtime(new DateTime("now"), new DateTimeZone("UTC")); - $pl->save(); - - return $row; + $contents = CcPlaylistcontentsQuery::create() + ->filterByDbPlaylistId($this->id) + ->orderByDbPosition() + ->find(); + + //reset the positions of the remaining items. + for ($i = 0; $i < count($contents); $i++) { + $contents[$i]->setDbPosition($i); + $contents[$i]->save($this->con); + } + + $this->pl->setDbMtime(new DateTime("now"), new DateTimeZone("UTC")); + $this->pl->save($this->con); + + $this->con->commit(); + } + catch (Exception $e) { + $this->con->rollback(); + throw $e; + } } - /** - * Move audioClip to the new position in the playlist - * - * @param int $oldPos - * old positioin in playlist - * @param int $newPos - * new position in playlist - * @return mixed - */ - public function moveAudioClip($oldPos, $newPos) - { - if($newPos < 0 || $newPos >= $this->getNextPos() || $oldPos < 0 || $oldPos >= $this->getNextPos()) - return FALSE; - - $row = $this->delAudioClip($oldPos); - if($row === FALSE) - return FALSE; - - $res = $this->addAudioClip($row->getDbFileId(), $newPos, $row->getDbFadein(), $row->getDbFadeout(), $row->getDbCliplength(), $row->getDbCuein(), $row->getDbCueout()); - if($res !== TRUE) - return FALSE; - - $pl = CcPlaylistQuery::create()->findPK($this->id); - $pl->setDbMtime(new DateTime("now"), new DateTimeZone("UTC")); - $pl->save(); - - return TRUE; - } public function getFadeInfo($pos) { @@ -823,26 +526,6 @@ class Application_Model_Playlist { "fadeIn"=>$fadeIn, "fadeOut"=>$fadeOut); } - /** - * Find info about clip at specified offset in playlist. - * - * @param string $offset - * current playtime (hh:mm:ss.ssssss) - * @param int $distance - * 0=current clip; 1=next clip ... - * @return array of matching clip info: - * - */ - public function getPlaylistClipAtPosition($pos) - { - - } - public function getAllPLMetaData() { $categories = $this->categories; @@ -887,129 +570,69 @@ class Application_Model_Playlist { return TRUE; } - /** - * Return array with gunids of all sub-playlists and clips used in - * the playlist - * - * @return array with hash elements: - * gunid - global id - * type - playlist | audioClip - */ - public function export() - { - - } /** - * Export playlist as simplified SMIL XML file. - * - * @param boolean $toString - * if false don't real export, - * return misc info about playlist only - * @return string - * XML string or hasharray with misc info - */ - public function outputToSmil($toString=TRUE) +- * Convert playlist time value to float seconds +- * +- * @param string $plt +- * playlist time value (HH:mm:ss.dddddd) +- * @return int +- * seconds +- */ + public static function playlistTimeToSeconds($plt) { - - } - - - /** - * Export playlist as M3U file. - * - * @param boolean $toString - * if false don't real export, - * return misc info about playlist only - * @return string|array - * M3U string or hasharray with misc info - */ - public function outputToM3u($toString=TRUE) - { - - } - - - /** - * Export playlist as RSS XML file - * - * @param boolean $toString - * if false don't really export, - * return misc info about playlist only - * @return mixed - * XML string or hasharray with misc info - */ - public function outputToRss($toString=TRUE) - { - - } - - - /** - * Insert a new playlist element. - * - * @param int $plId - * id of Playlist - * @param int $fileId - * id of File - * @param string $offset - * relative offset in extent format - * @param string $clipstart - * audioClip clipstart in extent format - * @param string $clipEnd - * audioClip clipEnd in extent format - * @param string $clipLength - * audioClip playlength in extent format (?) - * @param string $acGunid - * audioClip gunid - * @param string $acLen - * audioClip length in extent format - * @param string $acTit - * audioClip title - * @param string $fadeIn - * fadeIn value in ss.ssssss or extent format - * @param string $fadeOut - * fadeOut value in ss.ssssss or extent format - - * @return array with fields: - * - */ - private function insertPlaylistElement($plId, $fileId, $pos, $clipLength, $cuein, $cueout, $fadeIn=NULL, $fadeOut=NULL) - { - $defaultFade = Application_Model_Preference::GetDefaultFade(); - - if(is_null($fadeIn)) { - if($defaultFade != "") - $fadeIn = $defaultFade; - else - $fadeIn = '00:00:00.000'; + $arr = preg_split('/:/', $plt); + if (isset($arr[2])) { + return (intval($arr[0])*60 + intval($arr[1]))*60 + floatval($arr[2]); } - if(is_null($fadeOut)) { - if($defaultFade != "") - $fadeOut = $defaultFade; - else - $fadeOut = '00:00:00.000'; + if (isset($arr[1])) { + return intval($arr[0])*60 + floatval($arr[1]); } - - $row = new CcPlaylistcontents(); - $row->setDbPlaylistId($plId); - $row->setDbFileId($fileId); - $row->setDbPosition($pos); - $row->save(); - - $row->setDbCliplength($clipLength); - $row->setDbCuein($cuein); - $row->setDbCueout($cueout); - $row->setDbFadein($fadeIn); - $row->setDbFadeout($fadeOut); + return floatval($arr[0]); + } - return TRUE; + /** +- * Convert float seconds value to playlist time format +- * +- * @param float $seconds +- * @return string +- * time in playlist time format (HH:mm:ss.d) +- */ + public static function secondsToPlaylistTime($p_seconds) + { + $seconds = $p_seconds; + $rounded = round($seconds, 1); + $info = explode('.', $rounded); + $seconds = $info[0]; + if(!isset($info[1])){ + $milliStr = 0; + }else{ + $milliStr = $info[1]; + } + $hours = floor($seconds / 3600); + $seconds -= $hours * 3600; + $minutes = floor($seconds / 60); + $seconds -= $minutes * 60; + + $res = sprintf("%02d:%02d:%02d.%s", $hours, $minutes, $seconds, $milliStr); + + return $res; + } + + public static function getPlaylistCount(){ + global $CC_CONFIG, $CC_DBC; + $sql = 'SELECT count(*) as cnt FROM '.$CC_CONFIG["playListTable"]; + return $CC_DBC->GetOne($sql); + } + + /** + * Delete the file from all playlists. + * @param string $p_fileId + */ + public static function DeleteFileFromAllPlaylists($p_fileId) + { + CcPlaylistcontentsQuery::create()->filterByDbFileId($p_fileId)->delete(); } } // class Playlist diff --git a/airtime_mvc/application/models/Scheduler.php b/airtime_mvc/application/models/Scheduler.php index 76a86e596..555641ef9 100644 --- a/airtime_mvc/application/models/Scheduler.php +++ b/airtime_mvc/application/models/Scheduler.php @@ -83,6 +83,7 @@ class Application_Model_Scheduler { $id = intval($schedule["id"]); Logging::log("scheduling after scheduled item: ".$id); + Logging::log("in show: ".intval($schedule["instance"])); if ($id !== 0) { $schedItem = CcScheduleQuery::create()->findPK($id, $this->con); diff --git a/airtime_mvc/application/models/StoredFile.php b/airtime_mvc/application/models/StoredFile.php index afe7d1489..1023c5af1 100644 --- a/airtime_mvc/application/models/StoredFile.php +++ b/airtime_mvc/application/models/StoredFile.php @@ -825,7 +825,7 @@ class Application_Model_StoredFile { $sql = $selectorRows." FROM ".$fromTable." ORDER BY ".$orderby." OFFSET ".$data["iDisplayStart"]." LIMIT ".$data["iDisplayLength"]; } - Logging::log($sql); + //Logging::log($sql); $results = $CC_DBC->getAll($sql); diff --git a/airtime_mvc/application/models/airtime/CcPlaylist.php b/airtime_mvc/application/models/airtime/CcPlaylist.php index 0d3cff401..a5766df63 100644 --- a/airtime_mvc/application/models/airtime/CcPlaylist.php +++ b/airtime_mvc/application/models/airtime/CcPlaylist.php @@ -5,7 +5,7 @@ /** * Skeleton subclass for representing a row from the 'cc_playlist' table. * - * + * * * You should add additional methods to this class to meet the * application requirements. This class will only be generated as @@ -16,33 +16,4 @@ class CcPlaylist extends BaseCcPlaylist { - public function computeLastPosition() - { - $con = Propel::getConnection(CcPlaylistPeer::DATABASE_NAME); - - $sql = 'SELECT MAX('.CcPlaylistcontentsPeer::POSITION.') AS pos' - . ' FROM ' .CcPlaylistcontentsPeer::TABLE_NAME - . ' WHERE ' .CcPlaylistcontentsPeer::PLAYLIST_ID. ' = :p1'; - - $stmt = $con->prepare($sql); - $stmt->bindValue(':p1', $this->getDbId()); - $stmt->execute(); - return $stmt->fetchColumn(); - } - - public function computeLength() - { - $con = Propel::getConnection(CcPlaylistPeer::DATABASE_NAME); - - $sql = 'SELECT SUM('.CcPlaylistcontentsPeer::CLIPLENGTH.') AS length' - . ' FROM ' .CcPlaylistcontentsPeer::TABLE_NAME - . ' WHERE ' .CcPlaylistcontentsPeer::PLAYLIST_ID. ' = :p1'; - - $stmt = $con->prepare($sql); - $stmt->bindValue(':p1', $this->getDbId()); - $stmt->execute(); - return $stmt->fetchColumn(); - } - - } // CcPlaylist diff --git a/airtime_mvc/application/models/airtime/CcPlaylistcontents.php b/airtime_mvc/application/models/airtime/CcPlaylistcontents.php index 1b6417a66..d71f66595 100644 --- a/airtime_mvc/application/models/airtime/CcPlaylistcontents.php +++ b/airtime_mvc/application/models/airtime/CcPlaylistcontents.php @@ -5,7 +5,7 @@ require_once('Common.php'); /** * Skeleton subclass for representing a row from the 'cc_playlistcontents' table. * - * + * * * You should add additional methods to this class to meet the * application requirements. This class will only be generated as @@ -15,67 +15,5 @@ require_once('Common.php'); */ class CcPlaylistcontents extends BaseCcPlaylistcontents { - public function getDbFadein() - { - return $this->fadein; - } - - public function setDbFadein($time) - { - $this->fadein = $time; - //$this->modifiedColumns[] = CcPlaylistcontentsPeer::FADEIN; - Common::setTimeInSub($this, 'FADEIN', $time); - } - - public function getDbFadeout() - { - return $this->fadeout; - } - - public function setDbFadeout($time) - { - $this->fadeout = $time; - //$this->modifiedColumns[] = CcPlaylistcontentsPeer::FADEOUT; - Common::setTimeInSub($this, 'FADEOUT', $time); - } - - public function getDbCuein() - { - return $this->cuein; - } - - public function setDbCuein($time) - { - $this->cuein = $time; - //$this->modifiedColumns[] = CcPlaylistcontentsPeer::CUEIN; - Common::setTimeInSub($this, 'CUEIN', $time); - } - - public function getDbCueout() - { - return $this->cueout; - } - - public function setDbCueout($time) - { - $this->cueout = $time; - //$this->modifiedColumns[] = CcPlaylistcontentsPeer::CUEOUT; - Common::setTimeInSub($this, 'CUEOUT', $time); - } - - public function getDbCliplength() - { - return $this->cliplength; - } - - public function setDbCliplength($time) - { - $this->cliplength = $time; - //$this->modifiedColumns[] = CcPlaylistcontentsPeer::CLIPLENGTH; - Common::setTimeInSub($this, 'CLIPLENGTH', $time); - } - - - } // CcPlaylistcontents diff --git a/airtime_mvc/build/sql/triggers.sql b/airtime_mvc/build/sql/triggers.sql index ea9993f9e..2736bbfde 100644 --- a/airtime_mvc/build/sql/triggers.sql +++ b/airtime_mvc/build/sql/triggers.sql @@ -3,15 +3,18 @@ ---------------------------------------------------------------------------------- DROP FUNCTION calculate_position() CASCADE; +/* remove this trigger for group adds/delete */ + +/* CREATE FUNCTION calculate_position() RETURNS trigger AS ' BEGIN IF(TG_OP=''INSERT'') THEN - UPDATE cc_playlistcontents SET position = (position + 1) + UPDATE cc_playlistcontents SET position = (position + 1) WHERE (playlist_id = new.playlist_id AND position >= new.position AND id != new.id); END IF; IF(TG_OP=''DELETE'') THEN - UPDATE cc_playlistcontents SET position = (position - 1) + UPDATE cc_playlistcontents SET position = (position - 1) WHERE (playlist_id = old.playlist_id AND position > old.position); END IF; RETURN NULL; @@ -21,4 +24,5 @@ CREATE FUNCTION calculate_position() RETURNS trigger AS CREATE TRIGGER calculate_position AFTER INSERT OR DELETE ON cc_playlistcontents FOR EACH ROW EXECUTE PROCEDURE calculate_position(); +*/ diff --git a/airtime_mvc/public/js/airtime/library/spl.js b/airtime_mvc/public/js/airtime/library/spl.js index 1e73592b3..f6e83a930 100644 --- a/airtime_mvc/public/js/airtime/library/spl.js +++ b/airtime_mvc/public/js/airtime/library/spl.js @@ -332,9 +332,9 @@ function deleteSPL() { stopAudioPreview(); - url = '/Playlist/delete-active/format/json'; + url = '/Playlist/delete'; - $.post(url, function(json){ + $.post(url, {"format": "json", "active": true}, function(json){ if(json.playlist_error == true){ alertPlaylistErrorAndReload(); } @@ -351,7 +351,8 @@ function openDiffSPL(json) { } $("#side_playlist") .empty() - .append(json.html); + .append(json.html) + .data("id", json.pl_id); currentlyOpenedSplId = json.pl_id; setUpSPL();