CC-3174 : showbuilder

refactoring playlists for the group add/delete
This commit is contained in:
Naomi Aro 2012-02-03 18:15:10 +01:00
parent 3b172f9c0c
commit 0afa904ffe
10 changed files with 320 additions and 915 deletions

View File

@ -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',
)));
*/
}
}

View File

@ -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();

View File

@ -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);
@ -231,19 +207,20 @@ 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);
@ -260,8 +237,7 @@ class PlaylistController extends Zend_Controller_Action
}
}
$this->view->ids = $ids;
$this->view->html = $this->view->render('playlist/index.phtml');
$this->createFullResponse(null);
}
public function setCueAction()
@ -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();

View File

@ -1,358 +1,70 @@
<?php
define('INDCH', ' ');
/**
* remark: dcterms:extent format: hh:mm:ss.ssssss
*
* @package Airtime
* @subpackage StorageServer
* @copyright 2010 Sourcefabric O.P.S.
* @license http://www.gnu.org/licenses/gpl.txt
*/
class Application_Model_Playlist {
// *** Variable stored in the database ***
/**
* propel connection object.
*/
private $con;
/**
* @var int
* unique id for the playlist.
*/
private $id;
/**
* @var string
* propel object for this playlist.
*/
private $name;
private $pl;
/**
* Can be 'ready', 'edited', 'incomplete'.
*
* @var string
*/
private $state;
/**
* @var int
*/
private $currentlyaccessing;
/**
* @var int
*/
private $editedby;
/**
* @var timestamp
*/
private $mtime;
/**
* @var MetaData
* MetaData
*/
public $md;
//using propel's phpNames.
private $categories = array("dc:title" => "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
* info needed to insert a new playlist element.
*/
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.<br>
*
* @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
*/
public function setState($p_state, $p_editedby=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;
}
$pl = CcPlaylistQuery::create()->findPK($id);
if($pl === NULL)
return FALSE;
return $pl->getDbState();
}
/**
* Returns true if virtual file is currently in use.<br>
* 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
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)
{
if (isset($id)) {
$this->pl = CcPlaylistQuery::create()->findPK($id);
}
else {
$this->pl = new CcPlaylist();
$this->pl->setDbUtime(new DateTime("now"), new DateTimeZone("UTC"));
}
return ($pl->getDbCurrentlyaccessing() > 0);
}
$this->plItem["fadein"] = Application_Model_Preference::GetDefaultFade();
$this->plItem["fadeout"] = Application_Model_Preference::GetDefaultFade();
/**
* 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;
$this->id = $this->pl->getDbId();
$this->con = isset($con) ? $con : Propel::getConnection(CcPlaylistPeer::DATABASE_NAME);
}
/**
@ -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))
if (is_null($res)) {
$res = '00:00:00';
}
*/
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)
private function insertPlaylistElement($info)
{
$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;
$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);
}
/**
* 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)
private function buildEntry($p_item, $pos)
{
if ($val && $this->isEdited() !== FALSE) {
return PEAR::raiseError(
'Application_Model_Playlist::lock: playlist already locked'
);
}
$r = $this->setEditFlag($subjid, $val);
return $r;
$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;
}
/**
* Unlock playlist
*
* @return boolean
* previous state or error object
/*
* @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 unlock($subjid)
public function addAudioClips($p_items, $p_afterItem=NULL)
{
$r = $this->lock($subjid, FALSE);
return $r;
}
$this->con->beginTransaction();
$contentsToUpdate = array();
try {
/**
* Add audio clip to 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
*/
public function addAudioClip($p_mediaId, $p_position=NULL, $p_fadeIn=NULL, $p_fadeOut=NULL, $p_clipLength=NULL, $p_cuein=NULL, $p_cueout=NULL)
{
//get audio clip.
$media = Application_Model_StoredFile::Recall($p_mediaId);
if (is_null($media) || PEAR::isError($media)) {
return $media;
}
if (isset($p_afterItem)) {
$afterItem = CcPlaylistcontentsQuery::create()->findPK($p_afterItem);
$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;
}
/**
* Remove audioClip from playlist
*
* @param int $position
* position of audioclip in the playlist.
* @return boolean
*/
public function delAudioClip($pos)
{
if($pos < 0 || $pos >= $this->getNextPos())
return FALSE;
$row = CcPlaylistcontentsQuery::create()
$contentsToUpdate = CcPlaylistcontentsQuery::create()
->filterByDbPlaylistId($this->id)
->filterByDbPosition($pos)
->findOne();
->orderByDbPosition()
->find();
if(is_null($row))
return FALSE;
$pos = $afterItem->getDbPosition() + 1;
}
else {
$pos = $this->getSize();
}
$row->delete();
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 = CcPlaylistQuery::create()->findPK($this->id);
$pl->setDbMtime(new DateTime("now"), new DateTimeZone("UTC"));
$pl->save();
$pl->save($this->con);
return $row;
$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
* @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 moveAudioClip($oldPos, $newPos)
public function moveAudioClip($selectedItems, $afterItem)
{
if($newPos < 0 || $newPos >= $this->getNextPos() || $oldPos < 0 || $oldPos >= $this->getNextPos())
return FALSE;
$this->con->beginTransaction();
$row = $this->delAudioClip($oldPos);
if($row === FALSE)
return FALSE;
try {
$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;
$this->con->commit();
}
catch (Exception $e) {
$this->con->rollback();
throw $e;
}
$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 array $p_items
* array of unique item ids to remove from the playlist..
*/
public function delAudioClips($p_items)
{
$this->con->beginTransaction();
try {
CcPlaylistcontentsQuery::create()
->findPKs($p_items)
->delete();
$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;
}
}
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:
* <ul>
* <li>gunid string, global unique id of clip</li>
* <li>elapsed string, already played time of clip</li>
* <li>remaining string, remaining time of clip</li>
* <li>duration string, total playlength of clip </li>
* </ul>
*/
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()
{
/**
- * 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]);
}
/**
* 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)
{
if (isset($arr[1])) {
return intval($arr[0])*60 + floatval($arr[1]);
}
return floatval($arr[0]);
}
/**
* 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)
- * 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);
}
/**
* 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
* Delete the file from all playlists.
* @param string $p_fileId
*/
public function outputToRss($toString=TRUE)
public static function DeleteFileFromAllPlaylists($p_fileId)
{
}
/**
* 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:
* <ul>
* <li>plElId int - record id of playlistElement</li>
* <li>plElGunid string - gl.unique id of playlistElement</li>
* <li>fadeInId int - record id</li>
* <li>fadeOutId int - record id</li>
* </ul>
*/
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';
}
if(is_null($fadeOut)) {
if($defaultFade != "")
$fadeOut = $defaultFade;
else
$fadeOut = '00:00:00.000';
}
$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 TRUE;
CcPlaylistcontentsQuery::create()->filterByDbFileId($p_fileId)->delete();
}
} // class Playlist

View File

@ -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);

View File

@ -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);

View File

@ -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

View File

@ -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

View File

@ -3,6 +3,9 @@
----------------------------------------------------------------------------------
DROP FUNCTION calculate_position() CASCADE;
/* remove this trigger for group adds/delete */
/*
CREATE FUNCTION calculate_position() RETURNS trigger AS
'
BEGIN
@ -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();
*/

View File

@ -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();