2010-12-07 20:19:27 +01:00
|
|
|
<?php
|
|
|
|
|
2012-02-24 15:07:04 +01:00
|
|
|
require_once 'formatters/LengthFormatter.php';
|
|
|
|
|
2010-12-07 20:19:27 +01:00
|
|
|
/**
|
|
|
|
*
|
2011-01-05 18:19:58 +01:00
|
|
|
* @package Airtime
|
2010-12-07 20:19:27 +01:00
|
|
|
* @copyright 2010 Sourcefabric O.P.S.
|
|
|
|
* @license http://www.gnu.org/licenses/gpl.txt
|
|
|
|
*/
|
2012-08-21 22:54:14 +02:00
|
|
|
class Application_Model_Playlist implements Application_Model_LibraryEditable
|
2012-07-16 03:17:13 +02:00
|
|
|
{
|
2012-02-03 18:15:10 +01:00
|
|
|
/**
|
|
|
|
* propel connection object.
|
|
|
|
*/
|
|
|
|
private $con;
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2012-02-03 18:15:10 +01:00
|
|
|
/**
|
|
|
|
* unique id for the playlist.
|
|
|
|
*/
|
|
|
|
private $id;
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2012-07-11 00:51:32 +02:00
|
|
|
/**
|
2012-02-03 18:15:10 +01:00
|
|
|
* propel object for this playlist.
|
|
|
|
*/
|
2012-07-11 00:51:32 +02:00
|
|
|
private $pl;
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2012-07-11 00:51:32 +02:00
|
|
|
/**
|
2012-02-03 18:15:10 +01:00
|
|
|
* info needed to insert a new playlist element.
|
|
|
|
*/
|
2012-07-11 00:51:32 +02:00
|
|
|
private $plItem = array(
|
2012-02-03 18:15:10 +01:00
|
|
|
"id" => "",
|
2012-07-11 00:51:32 +02:00
|
|
|
"pos" => "",
|
2012-02-03 18:15:10 +01:00
|
|
|
"cliplength" => "",
|
|
|
|
"cuein" => "00:00:00",
|
|
|
|
"cueout" => "00:00:00",
|
2012-02-06 18:46:53 +01:00
|
|
|
"fadein" => "0.0",
|
|
|
|
"fadeout" => "0.0",
|
2012-02-03 18:15:10 +01:00
|
|
|
);
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2012-07-11 00:51:32 +02:00
|
|
|
//using propel's phpNames.
|
|
|
|
private $categories = array(
|
|
|
|
"dc:title" => "Name",
|
|
|
|
"dc:creator" => "Creator",
|
|
|
|
"dc:description" => "Description",
|
|
|
|
"dcterms:extent" => "Length"
|
|
|
|
);
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2012-02-03 18:15:10 +01:00
|
|
|
public function __construct($id=null, $con=null)
|
2010-12-07 20:19:27 +01:00
|
|
|
{
|
2012-02-03 18:15:10 +01:00
|
|
|
if (isset($id)) {
|
|
|
|
$this->pl = CcPlaylistQuery::create()->findPK($id);
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2012-02-06 18:46:53 +01:00
|
|
|
if (is_null($this->pl)) {
|
2012-02-04 00:12:06 +01:00
|
|
|
throw new PlaylistNotFoundException();
|
2012-02-03 18:28:35 +01:00
|
|
|
}
|
2012-07-16 03:17:13 +02:00
|
|
|
} else {
|
2012-02-03 18:15:10 +01:00
|
|
|
$this->pl = new CcPlaylist();
|
2012-07-25 23:08:22 +02:00
|
|
|
$this->pl->setDbUTime(new DateTime("now", new DateTimeZone("UTC")));
|
2012-02-04 00:12:06 +01:00
|
|
|
$this->pl->save();
|
2010-12-16 07:02:06 +01:00
|
|
|
}
|
|
|
|
|
2012-02-04 00:12:06 +01:00
|
|
|
$defaultFade = Application_Model_Preference::GetDefaultFade();
|
|
|
|
if ($defaultFade !== "") {
|
2012-02-06 12:48:53 +01:00
|
|
|
//fade is in format SS.uuuuuu
|
2012-02-06 18:46:53 +01:00
|
|
|
|
|
|
|
$this->plItem["fadein"] = $defaultFade;
|
|
|
|
$this->plItem["fadeout"] = $defaultFade;
|
2011-06-24 21:51:21 +02:00
|
|
|
}
|
2010-12-16 07:02:06 +01:00
|
|
|
|
2012-02-03 18:15:10 +01:00
|
|
|
$this->con = isset($con) ? $con : Propel::getConnection(CcPlaylistPeer::DATABASE_NAME);
|
2012-02-04 00:12:06 +01:00
|
|
|
$this->id = $this->pl->getDbId();
|
2011-06-15 18:06:50 +02:00
|
|
|
}
|
2010-12-07 20:19:27 +01:00
|
|
|
|
|
|
|
/**
|
2012-02-03 18:15:10 +01:00
|
|
|
* Return local ID of virtual file.
|
2010-12-07 20:19:27 +01:00
|
|
|
*
|
2012-02-03 18:15:10 +01:00
|
|
|
* @return int
|
2010-12-07 20:19:27 +01:00
|
|
|
*/
|
2012-07-16 03:17:13 +02:00
|
|
|
public function getId()
|
|
|
|
{
|
2012-02-03 18:15:10 +01:00
|
|
|
return $this->id;
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Rename stored virtual playlist
|
|
|
|
*
|
|
|
|
* @param string $p_newname
|
|
|
|
*/
|
|
|
|
public function setName($p_newname)
|
|
|
|
{
|
2012-07-11 00:51:32 +02:00
|
|
|
$this->pl->setDbName($p_newname);
|
|
|
|
$this->pl->setDbMtime(new DateTime("now", new DateTimeZone("UTC")));
|
|
|
|
$this->pl->save($this->con);
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
2012-07-11 00:51:32 +02:00
|
|
|
/**
|
2010-12-07 20:19:27 +01:00
|
|
|
* Get mnemonic playlist name
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2012-02-03 18:15:10 +01:00
|
|
|
public function getName()
|
2010-12-07 20:19:27 +01:00
|
|
|
{
|
2012-02-03 18:15:10 +01:00
|
|
|
return $this->pl->getDbName();
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
2011-05-17 23:30:17 +02:00
|
|
|
public function setDescription($p_description)
|
|
|
|
{
|
2012-07-11 00:51:32 +02:00
|
|
|
$this->pl->setDbDescription($p_description);
|
|
|
|
$this->pl->setDbMtime(new DateTime("now", new DateTimeZone("UTC")));
|
|
|
|
$this->pl->save($this->con);
|
2011-05-17 23:30:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getDescription()
|
|
|
|
{
|
2012-02-03 18:15:10 +01:00
|
|
|
return $this->pl->getDbDescription();
|
2011-05-17 23:30:17 +02:00
|
|
|
}
|
|
|
|
|
2012-07-16 03:17:13 +02:00
|
|
|
public function getCreator()
|
|
|
|
{
|
2012-02-07 14:58:16 +01:00
|
|
|
return $this->pl->getCcSubjs()->getDbLogin();
|
|
|
|
}
|
2012-07-11 00:51:32 +02:00
|
|
|
|
2012-07-16 03:17:13 +02:00
|
|
|
public function getCreatorId()
|
|
|
|
{
|
2012-06-06 23:31:51 +02:00
|
|
|
return $this->pl->getCcSubjs()->getDbId();
|
|
|
|
}
|
2012-02-07 14:58:16 +01:00
|
|
|
|
2012-07-16 03:17:13 +02:00
|
|
|
public function setCreator($p_id)
|
|
|
|
{
|
2012-02-07 14:58:16 +01:00
|
|
|
$this->pl->setDbCreatorId($p_id);
|
2012-02-20 18:24:04 +01:00
|
|
|
$this->pl->setDbMtime(new DateTime("now", new DateTimeZone("UTC")));
|
2012-02-07 14:58:16 +01:00
|
|
|
$this->pl->save($this->con);
|
|
|
|
}
|
|
|
|
|
2012-07-16 03:17:13 +02:00
|
|
|
public function getLastModified($format = null)
|
|
|
|
{
|
2012-08-22 00:41:56 +02:00
|
|
|
//Logging::info($this->pl->getDbMtime($format));
|
|
|
|
//Logging::info($this->pl);
|
2012-02-04 15:52:31 +01:00
|
|
|
return $this->pl->getDbMtime($format);
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
2012-07-16 03:17:13 +02:00
|
|
|
public function getSize()
|
|
|
|
{
|
2012-02-03 18:15:10 +01:00
|
|
|
return $this->pl->countCcPlaylistcontentss();
|
2011-02-08 22:10:48 +01:00
|
|
|
}
|
|
|
|
|
2010-12-07 20:19:27 +01:00
|
|
|
/**
|
|
|
|
* Get the entire playlist as a two dimentional array, sorted in order of play.
|
2012-04-24 18:59:07 +02:00
|
|
|
* @param boolean $filterFiles if this is true, it will only return files that has
|
2012-07-11 00:51:32 +02:00
|
|
|
* file_exists flag set to true
|
2010-12-07 20:19:27 +01:00
|
|
|
* @return array
|
|
|
|
*/
|
2012-07-16 03:17:13 +02:00
|
|
|
public function getContents($filterFiles=false)
|
|
|
|
{
|
2012-08-22 00:41:56 +02:00
|
|
|
Logging::info("Getting contents for playlist {$this->id}");
|
2010-12-07 20:19:27 +01:00
|
|
|
$files = array();
|
2012-07-11 00:51:32 +02:00
|
|
|
|
2012-08-09 23:42:25 +02:00
|
|
|
$sql = <<<SQL
|
2012-08-10 06:57:03 +02:00
|
|
|
SELECT *
|
2012-08-09 23:42:25 +02:00
|
|
|
FROM (
|
|
|
|
(SELECT pc.id AS id,
|
|
|
|
pc.type,
|
|
|
|
pc.position,
|
|
|
|
pc.cliplength AS LENGTH,
|
|
|
|
pc.cuein,
|
|
|
|
pc.cueout,
|
|
|
|
pc.fadein,
|
|
|
|
pc.fadeout,
|
|
|
|
f.id AS item_id,
|
|
|
|
f.track_title,
|
|
|
|
f.artist_name AS creator,
|
|
|
|
f.file_exists AS EXISTS,
|
2012-08-21 20:08:30 +02:00
|
|
|
f.filepath AS path,
|
|
|
|
f.length AS orig_length
|
2012-08-09 23:42:25 +02:00
|
|
|
FROM cc_playlistcontents AS pc
|
|
|
|
JOIN cc_files AS f ON pc.file_id=f.id
|
|
|
|
WHERE pc.playlist_id = {$this->id}
|
|
|
|
AND TYPE = 0)
|
|
|
|
UNION ALL
|
|
|
|
(SELECT pc.id AS id,
|
|
|
|
pc.TYPE, pc.position,
|
|
|
|
pc.cliplength AS LENGTH,
|
|
|
|
pc.cuein,
|
|
|
|
pc.cueout,
|
|
|
|
pc.fadein,
|
|
|
|
pc.fadeout,
|
|
|
|
ws.id AS item_id,
|
|
|
|
(ws.name || ': ' || ws.url) AS title,
|
|
|
|
sub.login AS creator,
|
|
|
|
't'::boolean AS EXISTS,
|
2012-08-21 20:08:30 +02:00
|
|
|
ws.url AS path,
|
|
|
|
ws.length AS orig_length
|
2012-08-09 23:42:25 +02:00
|
|
|
FROM cc_playlistcontents AS pc
|
|
|
|
JOIN cc_webstream AS ws ON pc.stream_id=ws.id
|
|
|
|
LEFT JOIN cc_subjs AS sub ON sub.id = ws.creator_id
|
|
|
|
WHERE pc.playlist_id = {$this->id}
|
|
|
|
AND pc.TYPE = 1)
|
|
|
|
UNION ALL
|
|
|
|
(SELECT pc.id AS id,
|
|
|
|
pc.TYPE, pc.position,
|
|
|
|
pc.cliplength AS LENGTH,
|
|
|
|
pc.cuein,
|
|
|
|
pc.cueout,
|
|
|
|
pc.fadein,
|
|
|
|
pc.fadeout,
|
|
|
|
bl.id AS item_id,
|
|
|
|
bl.name AS title,
|
|
|
|
sbj.login AS creator,
|
|
|
|
't'::boolean AS EXISTS,
|
2012-08-21 20:08:30 +02:00
|
|
|
NULL::text AS path,
|
|
|
|
bl.length AS orig_length
|
2012-08-09 23:42:25 +02:00
|
|
|
FROM cc_playlistcontents AS pc
|
|
|
|
JOIN cc_block AS bl ON pc.block_id=bl.id
|
|
|
|
JOIN cc_subjs AS sbj ON bl.creator_id=sbj.id
|
|
|
|
WHERE pc.playlist_id = {$this->id}
|
|
|
|
AND pc.TYPE = 2)) AS temp
|
2012-08-10 06:57:03 +02:00
|
|
|
ORDER BY temp.position;
|
2012-08-09 23:42:25 +02:00
|
|
|
SQL;
|
|
|
|
|
2012-07-20 23:38:11 +02:00
|
|
|
$con = Propel::getConnection();
|
2012-08-10 06:57:03 +02:00
|
|
|
$rows = $con->query($sql)->fetchAll(PDO::FETCH_ASSOC);
|
2012-07-20 23:38:11 +02:00
|
|
|
|
|
|
|
$offset = 0;
|
|
|
|
foreach ($rows as &$row) {
|
2012-07-26 20:41:09 +02:00
|
|
|
$clipSec = Application_Common_DateHelper::playlistTimeToSeconds($row['length']);
|
2012-07-20 23:38:11 +02:00
|
|
|
$offset += $clipSec;
|
2012-07-26 00:41:52 +02:00
|
|
|
$offset_cliplength = Application_Common_DateHelper::secondsToPlaylistTime($offset);
|
2012-07-20 23:38:11 +02:00
|
|
|
|
|
|
|
//format the length for UI.
|
2012-08-09 23:42:25 +02:00
|
|
|
if ($row['type'] == 2) {
|
2012-08-02 17:17:10 +02:00
|
|
|
$bl = new Application_Model_Block($row['item_id']);
|
2012-08-15 17:36:41 +02:00
|
|
|
$formatter = new LengthFormatter($bl->getLength());
|
2012-08-02 17:17:10 +02:00
|
|
|
} else {
|
|
|
|
$formatter = new LengthFormatter($row['length']);
|
|
|
|
}
|
2012-07-21 04:49:34 +02:00
|
|
|
$row['length'] = $formatter->format();
|
2012-07-20 23:38:11 +02:00
|
|
|
|
|
|
|
$formatter = new LengthFormatter($offset_cliplength);
|
|
|
|
$row['offset'] = $formatter->format();
|
2012-08-16 20:37:10 +02:00
|
|
|
|
2012-08-16 20:45:51 +02:00
|
|
|
//format the fades in format 00(.000000)
|
2012-08-16 20:37:10 +02:00
|
|
|
$fades = $this->getFadeInfo($row['position']);
|
|
|
|
$row['fadein'] = $fades[0];
|
|
|
|
$row['fadeout'] = $fades[1];
|
2012-08-21 20:08:30 +02:00
|
|
|
|
|
|
|
//format original length
|
|
|
|
$formatter = new LengthFormatter($row['orig_length']);
|
|
|
|
$row['orig_length'] = $formatter->format();
|
2012-07-20 23:38:11 +02:00
|
|
|
}
|
2011-06-16 12:39:17 +02:00
|
|
|
|
2012-07-20 23:38:11 +02:00
|
|
|
return $rows;
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
2012-02-02 20:44:14 +01:00
|
|
|
/**
|
|
|
|
* The database stores fades in 00:00:00 Time format with optional millisecond resolution .000000
|
|
|
|
* but this isn't practical since fades shouldn't be very long usuall 1 second or less. This function
|
|
|
|
* will normalize the fade so that it looks like 00.000000 to the user.
|
|
|
|
**/
|
2012-07-16 03:17:13 +02:00
|
|
|
public function normalizeFade($fade)
|
|
|
|
{
|
2012-07-20 23:38:11 +02:00
|
|
|
//First get rid of the first six characters 00:00: which will be added back later for db update
|
|
|
|
$fade = substr($fade, 6);
|
|
|
|
|
|
|
|
//Second add .000000 if the fade does't have milliseconds format already
|
|
|
|
$dbFadeStrPos = strpos( $fade, '.' );
|
|
|
|
if ($dbFadeStrPos === false) {
|
|
|
|
$fade .= '.000000';
|
|
|
|
} else {
|
|
|
|
while (strlen($fade) < 9) {
|
|
|
|
$fade .= '0';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//done, just need to set back the formated values
|
|
|
|
return $fade;
|
2012-02-02 20:44:14 +01:00
|
|
|
}
|
2012-07-31 23:46:37 +02:00
|
|
|
|
2012-08-02 22:36:12 +02:00
|
|
|
// returns true/false and ids of dynamic blocks
|
2012-08-21 22:54:14 +02:00
|
|
|
public function hasDynamicBlock(){
|
|
|
|
$ids = $this->getIdsOfDynamicBlocks();
|
2012-08-02 22:36:12 +02:00
|
|
|
if (count($ids) > 0) {
|
2012-07-31 23:46:37 +02:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2012-08-02 22:36:12 +02:00
|
|
|
|
|
|
|
public function getIdsOfDynamicBlocks() {
|
2012-08-21 22:54:14 +02:00
|
|
|
$sql = "SELECT bl.id FROM cc_playlistcontents as pc
|
|
|
|
JOIN cc_block as bl ON pc.type=2 AND pc.block_id=bl.id AND bl.type='dynamic'
|
|
|
|
WHERE playlist_id={$this->id} AND pc.type=2";
|
|
|
|
$r = $this->con->query($sql);
|
2012-08-02 22:36:12 +02:00
|
|
|
$result = $r->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
return $result;
|
|
|
|
}
|
2012-02-02 20:44:14 +01:00
|
|
|
|
2012-02-04 21:26:21 +01:00
|
|
|
//aggregate column on playlistcontents cliplength column.
|
2012-07-16 03:17:13 +02:00
|
|
|
public function getLength()
|
|
|
|
{
|
2012-08-02 22:36:12 +02:00
|
|
|
if ($this->hasDynamicBlock()){
|
|
|
|
$ids = $this->getIdsOfDynamicBlocks();
|
|
|
|
$length = $this->pl->getDbLength();
|
|
|
|
foreach ($ids as $id){
|
|
|
|
$bl = new Application_Model_Block($id['id']);
|
|
|
|
if ($bl->hasItemLimit()) {
|
|
|
|
return "N/A";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$formatter = new LengthFormatter($length);
|
|
|
|
return "~".$formatter->format();
|
2012-07-31 23:46:37 +02:00
|
|
|
} else {
|
|
|
|
return $this->pl->getDbLength();
|
|
|
|
}
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
2012-07-27 17:51:50 +02:00
|
|
|
private function insertPlaylistElement($info)
|
2012-02-03 18:15:10 +01:00
|
|
|
{
|
|
|
|
$row = new CcPlaylistcontents();
|
|
|
|
$row->setDbPlaylistId($this->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"]);
|
2012-07-27 17:51:50 +02:00
|
|
|
if ($info["ftype"] == "audioclip") {
|
|
|
|
$row->setDbFileId($info["id"]);
|
|
|
|
$type = 0;
|
|
|
|
} else if ($info["ftype"] == "stream") {
|
|
|
|
$row->setDbStreamId($info["id"]);
|
|
|
|
$type = 1;
|
|
|
|
} else if ($info["ftype"] == "block") {
|
|
|
|
$row->setDbBlockId($info["id"]);
|
|
|
|
$type = 2;
|
|
|
|
}
|
2012-07-20 23:38:11 +02:00
|
|
|
$row->setDbType($type);
|
2012-02-03 18:15:10 +01:00
|
|
|
$row->save($this->con);
|
2012-07-20 21:32:46 +02:00
|
|
|
// above save result update on cc_playlist table on length column.
|
|
|
|
// but $this->pl doesn't get updated automatically
|
|
|
|
// so we need to manually grab it again from DB so it has updated values
|
|
|
|
// It is something to do FORMAT_ON_DEMAND( Lazy Loading )
|
|
|
|
$this->pl = CcPlaylistQuery::create()->findPK($this->id);
|
2012-02-03 18:15:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2010-12-07 20:19:27 +01:00
|
|
|
*
|
|
|
|
*/
|
2012-02-03 18:15:10 +01:00
|
|
|
private function buildEntry($p_item, $pos)
|
2010-12-07 20:19:27 +01:00
|
|
|
{
|
2012-07-26 22:16:07 +02:00
|
|
|
$objType = $p_item[1];
|
|
|
|
$objId = $p_item[0];
|
|
|
|
if ($objType == 'audioclip') {
|
|
|
|
$obj = CcFilesQuery::create()->findPK($objId, $this->con);
|
|
|
|
} else if ($objType == "stream") {
|
|
|
|
$obj = CcWebstreamQuery::create()->findPK($objId, $this->con);
|
|
|
|
} else if ($objType == "block") {
|
|
|
|
$obj = CcBlockQuery::create()->findPK($objId, $this->con);
|
|
|
|
} else {
|
|
|
|
throw new Exception("Unknown file type");
|
|
|
|
}
|
2011-03-30 23:27:14 +02:00
|
|
|
|
2012-08-09 17:03:57 +02:00
|
|
|
if (isset($obj)) {
|
2012-07-26 22:16:07 +02:00
|
|
|
if (($obj instanceof CcFiles && $obj->getDbFileExists()) || $obj instanceof CcWebstream || $obj instanceof CcBlock) {
|
|
|
|
$entry = $this->plItem;
|
|
|
|
$entry["id"] = $obj->getDbId();
|
|
|
|
$entry["pos"] = $pos;
|
|
|
|
$entry["cliplength"] = $obj->getDbLength();
|
|
|
|
$entry["cueout"] = $obj->getDbLength();
|
2012-07-27 17:51:50 +02:00
|
|
|
$entry["ftype"] = $objType;
|
2012-07-26 22:16:07 +02:00
|
|
|
}
|
2012-02-20 18:24:04 +01:00
|
|
|
return $entry;
|
2012-07-16 03:17:13 +02:00
|
|
|
} else {
|
2012-07-26 22:16:07 +02:00
|
|
|
throw new Exception("trying to add a object that does not exist.");
|
2012-02-20 18:24:04 +01:00
|
|
|
}
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
2012-02-03 18:15:10 +01:00
|
|
|
/*
|
|
|
|
* @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.
|
2012-02-04 19:27:26 +01:00
|
|
|
* @param string (before|after) $addAfter
|
|
|
|
* whether to add the clips before or after the selected item.
|
2010-12-07 20:19:27 +01:00
|
|
|
*/
|
2012-07-20 23:38:11 +02:00
|
|
|
public function addAudioClips($p_items, $p_afterItem=null, $addType = 'after')
|
2010-12-07 20:19:27 +01:00
|
|
|
{
|
2012-02-03 18:15:10 +01:00
|
|
|
$this->con->beginTransaction();
|
|
|
|
$contentsToUpdate = array();
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2012-02-03 18:15:10 +01:00
|
|
|
try {
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2012-02-04 00:12:06 +01:00
|
|
|
if (is_numeric($p_afterItem)) {
|
2012-08-22 00:41:56 +02:00
|
|
|
Logging::info("Finding playlist content item {$p_afterItem}");
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2012-02-03 18:15:10 +01:00
|
|
|
$afterItem = CcPlaylistcontentsQuery::create()->findPK($p_afterItem);
|
2012-02-04 19:27:26 +01:00
|
|
|
$index = $afterItem->getDbPosition();
|
2012-08-22 00:41:56 +02:00
|
|
|
Logging::info("index is {$index}");
|
2012-02-04 19:27:26 +01:00
|
|
|
$pos = ($addType == 'after') ? $index + 1 : $index;
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2012-02-03 18:15:10 +01:00
|
|
|
$contentsToUpdate = CcPlaylistcontentsQuery::create()
|
|
|
|
->filterByDbPlaylistId($this->id)
|
2012-02-04 19:27:26 +01:00
|
|
|
->filterByDbPosition($pos, Criteria::GREATER_EQUAL)
|
2012-02-03 18:15:10 +01:00
|
|
|
->orderByDbPosition()
|
2012-02-03 18:28:35 +01:00
|
|
|
->find($this->con);
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2012-07-16 03:17:13 +02:00
|
|
|
} else {
|
2012-02-04 00:12:06 +01:00
|
|
|
|
2012-02-04 21:26:21 +01:00
|
|
|
//add to the end of the playlist
|
|
|
|
if ($addType == 'after') {
|
|
|
|
$pos = $this->getSize();
|
|
|
|
}
|
|
|
|
//add to the beginning of the playlist.
|
|
|
|
else {
|
|
|
|
$pos = 0;
|
|
|
|
|
|
|
|
$contentsToUpdate = CcPlaylistcontentsQuery::create()
|
|
|
|
->filterByDbPlaylistId($this->id)
|
|
|
|
->orderByDbPosition()
|
|
|
|
->find($this->con);
|
|
|
|
}
|
|
|
|
|
|
|
|
$contentsToUpdate = CcPlaylistcontentsQuery::create()
|
|
|
|
->filterByDbPlaylistId($this->id)
|
|
|
|
->filterByDbPosition($pos, Criteria::GREATER_EQUAL)
|
|
|
|
->orderByDbPosition()
|
|
|
|
->find($this->con);
|
2012-02-04 19:27:26 +01:00
|
|
|
|
2012-02-03 18:15:10 +01:00
|
|
|
}
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2012-08-22 00:41:56 +02:00
|
|
|
Logging::info("Adding to playlist");
|
|
|
|
Logging::info("at position {$pos}");
|
2012-07-20 23:38:11 +02:00
|
|
|
|
2012-07-16 03:17:13 +02:00
|
|
|
foreach ($p_items as $ac) {
|
2012-08-21 22:54:14 +02:00
|
|
|
$res = $this->insertPlaylistElement($this->buildEntry($ac, $pos));
|
2012-07-26 22:16:07 +02:00
|
|
|
$pos = $pos + 1;
|
2012-08-22 00:41:56 +02:00
|
|
|
Logging::info("Adding $ac[1] $ac[0]");
|
2010-12-10 00:44:47 +01:00
|
|
|
|
2012-02-03 18:15:10 +01:00
|
|
|
}
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2012-02-03 18:15:10 +01:00
|
|
|
//reset the positions of the remaining items.
|
|
|
|
for ($i = 0; $i < count($contentsToUpdate); $i++) {
|
2012-02-04 00:12:06 +01:00
|
|
|
$contentsToUpdate[$i]->setDbPosition($pos);
|
|
|
|
$contentsToUpdate[$i]->save($this->con);
|
2012-02-03 18:15:10 +01:00
|
|
|
$pos = $pos + 1;
|
|
|
|
}
|
2010-12-10 00:44:47 +01:00
|
|
|
|
2012-02-20 18:24:04 +01:00
|
|
|
$this->pl->setDbMtime(new DateTime("now", new DateTimeZone("UTC")));
|
2012-02-04 00:12:06 +01:00
|
|
|
$this->pl->save($this->con);
|
2010-12-10 00:44:47 +01:00
|
|
|
|
2012-02-03 18:15:10 +01:00
|
|
|
$this->con->commit();
|
2012-07-16 03:17:13 +02:00
|
|
|
} catch (Exception $e) {
|
2012-02-03 18:15:10 +01:00
|
|
|
$this->con->rollback();
|
|
|
|
throw $e;
|
|
|
|
}
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-02-03 18:15:10 +01:00
|
|
|
* Move audioClip to the new position in the playlist
|
2010-12-07 20:19:27 +01:00
|
|
|
*
|
2012-02-04 00:12:06 +01:00
|
|
|
* @param array $p_items
|
2012-02-03 18:15:10 +01:00
|
|
|
* array of unique ids of the selected items
|
2012-02-04 00:12:06 +01:00
|
|
|
* @param int $p_afterItem
|
2012-02-03 18:15:10 +01:00
|
|
|
* unique id of the item to move the clip after
|
2010-12-07 20:19:27 +01:00
|
|
|
*/
|
2012-02-04 00:12:06 +01:00
|
|
|
public function moveAudioClips($p_items, $p_afterItem=NULL)
|
2010-12-07 20:19:27 +01:00
|
|
|
{
|
2012-02-03 18:15:10 +01:00
|
|
|
$this->con->beginTransaction();
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2012-02-03 18:15:10 +01:00
|
|
|
try {
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2012-02-04 15:52:31 +01:00
|
|
|
$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)) {
|
2012-08-22 00:41:56 +02:00
|
|
|
Logging::info("moving items to beginning of playlist");
|
2012-02-04 15:52:31 +01:00
|
|
|
|
|
|
|
foreach ($contentsToMove as $item) {
|
2012-08-22 00:41:56 +02:00
|
|
|
Logging::info("item {$item->getDbId()} to pos {$pos}");
|
2012-02-04 15:52:31 +01:00
|
|
|
$item->setDbPosition($pos);
|
|
|
|
$item->save($this->con);
|
|
|
|
$pos = $pos + 1;
|
|
|
|
}
|
|
|
|
foreach ($otherContent as $item) {
|
2012-08-22 00:41:56 +02:00
|
|
|
Logging::info("item {$item->getDbId()} to pos {$pos}");
|
2012-02-04 15:52:31 +01:00
|
|
|
$item->setDbPosition($pos);
|
|
|
|
$item->save($this->con);
|
|
|
|
$pos = $pos + 1;
|
|
|
|
}
|
2012-07-16 03:17:13 +02:00
|
|
|
} else {
|
2012-08-22 00:41:56 +02:00
|
|
|
Logging::info("moving items after {$p_afterItem}");
|
2012-02-04 15:52:31 +01:00
|
|
|
|
|
|
|
foreach ($otherContent as $item) {
|
2012-08-22 00:41:56 +02:00
|
|
|
Logging::info("item {$item->getDbId()} to pos {$pos}");
|
2012-02-04 15:52:31 +01:00
|
|
|
$item->setDbPosition($pos);
|
|
|
|
$item->save($this->con);
|
|
|
|
$pos = $pos + 1;
|
|
|
|
|
|
|
|
if ($item->getDbId() == $p_afterItem) {
|
|
|
|
foreach ($contentsToMove as $move) {
|
2012-08-22 00:41:56 +02:00
|
|
|
Logging::info("item {$move->getDbId()} to pos {$pos}");
|
2012-02-04 15:52:31 +01:00
|
|
|
$move->setDbPosition($pos);
|
|
|
|
$move->save($this->con);
|
|
|
|
$pos = $pos + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2012-02-03 18:15:10 +01:00
|
|
|
$this->con->commit();
|
2012-07-16 03:17:13 +02:00
|
|
|
} catch (Exception $e) {
|
2012-02-03 18:15:10 +01:00
|
|
|
$this->con->rollback();
|
|
|
|
throw $e;
|
|
|
|
}
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2012-02-03 18:15:10 +01:00
|
|
|
$this->pl = CcPlaylistQuery::create()->findPK($this->id);
|
2012-02-20 18:24:04 +01:00
|
|
|
$this->pl->setDbMtime(new DateTime("now", new DateTimeZone("UTC")));
|
2012-02-03 18:15:10 +01:00
|
|
|
$this->pl->save($this->con);
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
2012-02-03 18:15:10 +01:00
|
|
|
/**
|
|
|
|
* Remove audioClip from playlist
|
2010-12-07 20:19:27 +01:00
|
|
|
*
|
2012-02-03 18:15:10 +01:00
|
|
|
* @param array $p_items
|
2012-07-11 00:51:32 +02:00
|
|
|
* array of unique item ids to remove from the playlist..
|
2010-12-07 20:19:27 +01:00
|
|
|
*/
|
2012-02-03 18:15:10 +01:00
|
|
|
public function delAudioClips($p_items)
|
2010-12-07 20:19:27 +01:00
|
|
|
{
|
2012-02-06 11:07:10 +01:00
|
|
|
|
2012-02-03 18:15:10 +01:00
|
|
|
$this->con->beginTransaction();
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2012-02-03 18:15:10 +01:00
|
|
|
try {
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2012-02-03 18:15:10 +01:00
|
|
|
CcPlaylistcontentsQuery::create()
|
|
|
|
->findPKs($p_items)
|
2012-02-03 18:28:35 +01:00
|
|
|
->delete($this->con);
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2012-02-03 18:15:10 +01:00
|
|
|
$contents = CcPlaylistcontentsQuery::create()
|
|
|
|
->filterByDbPlaylistId($this->id)
|
|
|
|
->orderByDbPosition()
|
2012-02-03 18:28:35 +01:00
|
|
|
->find($this->con);
|
2012-02-03 18:15:10 +01:00
|
|
|
|
|
|
|
//reset the positions of the remaining items.
|
|
|
|
for ($i = 0; $i < count($contents); $i++) {
|
|
|
|
$contents[$i]->setDbPosition($i);
|
|
|
|
$contents[$i]->save($this->con);
|
|
|
|
}
|
|
|
|
|
2012-02-20 18:24:04 +01:00
|
|
|
$this->pl->setDbMtime(new DateTime("now", new DateTimeZone("UTC")));
|
2012-02-03 18:15:10 +01:00
|
|
|
$this->pl->save($this->con);
|
|
|
|
|
|
|
|
$this->con->commit();
|
2012-07-16 03:17:13 +02:00
|
|
|
} catch (Exception $e) {
|
2012-02-03 18:15:10 +01:00
|
|
|
$this->con->rollback();
|
|
|
|
throw $e;
|
|
|
|
}
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
2012-07-16 03:17:13 +02:00
|
|
|
public function getFadeInfo($pos)
|
|
|
|
{
|
2012-08-22 00:41:56 +02:00
|
|
|
Logging::info("Getting fade info for pos {$pos}");
|
2012-02-05 23:38:12 +01:00
|
|
|
|
2012-07-11 00:51:32 +02:00
|
|
|
$row = CcPlaylistcontentsQuery::create()
|
2011-01-17 01:31:10 +01:00
|
|
|
->joinWith(CcFilesPeer::OM_CLASS)
|
|
|
|
->filterByDbPlaylistId($this->id)
|
|
|
|
->filterByDbPosition($pos)
|
|
|
|
->findOne();
|
2012-07-10 22:41:30 +02:00
|
|
|
|
2012-08-09 17:03:57 +02:00
|
|
|
if (!$row) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2012-07-10 22:41:30 +02:00
|
|
|
#Propel returns values in form 00.000000 format which is for only seconds.
|
|
|
|
$fadeIn = $row->getDbFadein();
|
|
|
|
$fadeOut = $row->getDbFadeout();
|
|
|
|
return array($fadeIn, $fadeOut);
|
2011-01-17 01:31:10 +01:00
|
|
|
}
|
2010-12-07 20:19:27 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Change fadeIn and fadeOut values for playlist Element
|
|
|
|
*
|
|
|
|
* @param int $pos
|
2012-07-11 00:51:32 +02:00
|
|
|
* position of audioclip in playlist
|
2010-12-07 20:19:27 +01:00
|
|
|
* @param string $fadeIn
|
2012-07-11 00:51:32 +02:00
|
|
|
* new value in ss.ssssss or extent format
|
2010-12-07 20:19:27 +01:00
|
|
|
* @param string $fadeOut
|
2012-07-11 00:51:32 +02:00
|
|
|
* new value in ss.ssssss or extent format
|
2010-12-07 20:19:27 +01:00
|
|
|
* @return boolean
|
|
|
|
*/
|
2012-02-05 23:38:12 +01:00
|
|
|
public function changeFadeInfo($id, $fadeIn, $fadeOut)
|
2010-12-07 20:19:27 +01:00
|
|
|
{
|
2012-02-04 00:19:13 +01:00
|
|
|
//See issue CC-2065, pad the fadeIn and fadeOut so that it is TIME compatable with the DB schema
|
|
|
|
//For the top level PlayList either fadeIn or fadeOut will sometimes be Null so need a gaurd against
|
2012-07-11 00:51:32 +02:00
|
|
|
//setting it to nonNull for checks down below
|
2012-02-04 00:19:13 +01:00
|
|
|
$fadeIn = $fadeIn?'00:00:'.$fadeIn:$fadeIn;
|
|
|
|
$fadeOut = $fadeOut?'00:00:'.$fadeOut:$fadeOut;
|
2012-02-02 20:44:14 +01:00
|
|
|
|
2012-02-20 18:24:04 +01:00
|
|
|
$this->con->beginTransaction();
|
|
|
|
|
2010-12-07 20:19:27 +01:00
|
|
|
$errArray= array();
|
|
|
|
|
2012-02-20 18:24:04 +01:00
|
|
|
try {
|
|
|
|
$row = CcPlaylistcontentsQuery::create()->findPK($id);
|
2012-02-05 23:38:12 +01:00
|
|
|
|
2012-02-20 18:24:04 +01:00
|
|
|
if (is_null($row)) {
|
|
|
|
throw new Exception("Playlist item does not exist.");
|
|
|
|
}
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2012-02-20 18:24:04 +01:00
|
|
|
$clipLength = $row->getDbCliplength();
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2012-02-20 18:24:04 +01:00
|
|
|
if (!is_null($fadeIn)) {
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2012-07-11 00:51:32 +02:00
|
|
|
$sql = "SELECT INTERVAL '{$fadeIn}' > INTERVAL '{$clipLength}'";
|
|
|
|
$r = $this->con->query($sql);
|
2012-02-20 18:24:04 +01:00
|
|
|
if ($r->fetchColumn(0)) {
|
|
|
|
//"Fade In can't be larger than overall playlength.";
|
|
|
|
$fadeIn = $clipLength;
|
|
|
|
}
|
|
|
|
$row->setDbFadein($fadeIn);
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
2012-07-16 03:17:13 +02:00
|
|
|
if (!is_null($fadeOut)) {
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2012-07-11 00:51:32 +02:00
|
|
|
$sql = "SELECT INTERVAL '{$fadeOut}' > INTERVAL '{$clipLength}'";
|
|
|
|
$r = $this->con->query($sql);
|
2012-02-20 18:24:04 +01:00
|
|
|
if ($r->fetchColumn(0)) {
|
|
|
|
//Fade Out can't be larger than overall playlength.";
|
|
|
|
$fadeOut = $clipLength;
|
|
|
|
}
|
|
|
|
$row->setDbFadeout($fadeOut);
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
2012-02-20 18:24:04 +01:00
|
|
|
$row->save($this->con);
|
|
|
|
$this->pl->setDbMtime(new DateTime("now", new DateTimeZone("UTC")));
|
|
|
|
$this->pl->save($this->con);
|
|
|
|
|
|
|
|
$this->con->commit();
|
2012-07-16 03:17:13 +02:00
|
|
|
} catch (Exception $e) {
|
2012-02-20 18:24:04 +01:00
|
|
|
$this->con->rollback();
|
|
|
|
throw $e;
|
2012-02-06 18:46:53 +01:00
|
|
|
}
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2012-03-19 14:09:05 +01:00
|
|
|
return array("fadeIn" => $fadeIn, "fadeOut" => $fadeOut);
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
2012-07-30 23:18:33 +02:00
|
|
|
public function setfades($fadein, $fadeout)
|
2012-07-16 03:17:13 +02:00
|
|
|
{
|
2012-02-05 23:38:12 +01:00
|
|
|
if (isset($fadein)) {
|
2012-08-22 00:41:56 +02:00
|
|
|
Logging::info("Setting playlist fade in {$fadein}");
|
2012-02-05 23:38:12 +01:00
|
|
|
$row = CcPlaylistcontentsQuery::create()
|
|
|
|
->filterByDbPlaylistId($this->id)
|
|
|
|
->filterByDbPosition(0)
|
2012-02-20 18:24:04 +01:00
|
|
|
->findOne($this->con);
|
2011-01-17 01:31:10 +01:00
|
|
|
|
2012-02-05 23:38:12 +01:00
|
|
|
$this->changeFadeInfo($row->getDbId(), $fadein, null);
|
|
|
|
}
|
2011-01-17 01:31:10 +01:00
|
|
|
|
2012-02-05 23:38:12 +01:00
|
|
|
if (isset($fadeout)) {
|
2012-08-22 00:41:56 +02:00
|
|
|
Logging::info("Setting playlist fade out {$fadeout}");
|
2012-02-05 23:38:12 +01:00
|
|
|
$row = CcPlaylistcontentsQuery::create()
|
|
|
|
->filterByDbPlaylistId($this->id)
|
|
|
|
->filterByDbPosition($this->getSize()-1)
|
2012-02-20 18:24:04 +01:00
|
|
|
->findOne($this->con);
|
2012-04-01 21:51:03 +02:00
|
|
|
|
2012-02-05 23:38:12 +01:00
|
|
|
$this->changeFadeInfo($row->getDbId(), null, $fadeout);
|
|
|
|
}
|
|
|
|
}
|
2011-01-17 01:31:10 +01:00
|
|
|
|
2010-12-07 20:19:27 +01:00
|
|
|
/**
|
|
|
|
* Change cueIn/cueOut values for playlist element
|
|
|
|
*
|
|
|
|
* @param int $pos
|
2012-07-11 00:51:32 +02:00
|
|
|
* position of audioclip in playlist
|
2010-12-07 20:19:27 +01:00
|
|
|
* @param string $cueIn
|
2012-07-11 00:51:32 +02:00
|
|
|
* new value in ss.ssssss or extent format
|
2010-12-07 20:19:27 +01:00
|
|
|
* @param string $cueOut
|
2012-07-11 00:51:32 +02:00
|
|
|
* new value in ss.ssssss or extent format
|
2010-12-07 20:19:27 +01:00
|
|
|
* @return boolean or pear error object
|
|
|
|
*/
|
2012-02-04 19:27:26 +01:00
|
|
|
public function changeClipLength($id, $cueIn, $cueOut)
|
2010-12-07 20:19:27 +01:00
|
|
|
{
|
2012-02-20 18:24:04 +01:00
|
|
|
$this->con->beginTransaction();
|
|
|
|
|
2010-12-07 20:19:27 +01:00
|
|
|
$errArray= array();
|
|
|
|
|
2012-02-20 18:24:04 +01:00
|
|
|
try {
|
|
|
|
if (is_null($cueIn) && is_null($cueOut)) {
|
|
|
|
$errArray["error"] = "Cue in and cue out are null.";
|
2012-07-16 03:17:13 +02:00
|
|
|
|
2012-02-20 18:24:04 +01:00
|
|
|
return $errArray;
|
|
|
|
}
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2012-02-20 18:24:04 +01:00
|
|
|
$row = CcPlaylistcontentsQuery::create()
|
|
|
|
->joinWith(CcFilesPeer::OM_CLASS)
|
|
|
|
->filterByPrimaryKey($id)
|
|
|
|
->findOne($this->con);
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2012-02-20 18:24:04 +01:00
|
|
|
if (is_null($row)) {
|
|
|
|
throw new Exception("Playlist item does not exist.");
|
|
|
|
}
|
2012-02-04 19:27:26 +01:00
|
|
|
|
2012-02-20 18:24:04 +01:00
|
|
|
$oldCueIn = $row->getDBCuein();
|
|
|
|
$oldCueOut = $row->getDbCueout();
|
|
|
|
$fadeIn = $row->getDbFadein();
|
|
|
|
$fadeOut = $row->getDbFadeout();
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2012-02-20 18:24:04 +01:00
|
|
|
$file = $row->getCcFiles($this->con);
|
|
|
|
$origLength = $file->getDbLength();
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2012-07-16 03:17:13 +02:00
|
|
|
if (!is_null($cueIn) && !is_null($cueOut)) {
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2012-07-16 03:17:13 +02:00
|
|
|
if ($cueOut === "") {
|
2012-02-20 18:24:04 +01:00
|
|
|
$cueOut = $origLength;
|
|
|
|
}
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2012-07-11 00:51:32 +02:00
|
|
|
$sql = "SELECT INTERVAL '{$cueIn}' > INTERVAL '{$cueOut}'";
|
|
|
|
$r = $this->con->query($sql);
|
2012-02-20 18:24:04 +01:00
|
|
|
if ($r->fetchColumn(0)) {
|
|
|
|
$errArray["error"] = "Can't set cue in to be larger than cue out.";
|
2012-07-16 03:17:13 +02:00
|
|
|
|
2012-02-20 18:24:04 +01:00
|
|
|
return $errArray;
|
|
|
|
}
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2012-07-11 00:51:32 +02:00
|
|
|
$sql = "SELECT INTERVAL '{$cueOut}' > INTERVAL '{$origLength}'";
|
|
|
|
$r = $this->con->query($sql);
|
2012-07-16 03:17:13 +02:00
|
|
|
if ($r->fetchColumn(0)) {
|
2012-02-20 18:24:04 +01:00
|
|
|
$errArray["error"] = "Can't set cue out to be greater than file length.";
|
2012-07-16 03:17:13 +02:00
|
|
|
|
2012-02-20 18:24:04 +01:00
|
|
|
return $errArray;
|
|
|
|
}
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2012-07-11 00:51:32 +02:00
|
|
|
$sql = "SELECT INTERVAL '{$cueOut}' - INTERVAL '{$cueIn}'";
|
|
|
|
$r = $this->con->query($sql);
|
|
|
|
$cliplength = $r->fetchColumn(0);
|
2012-02-20 18:24:04 +01:00
|
|
|
|
|
|
|
$row->setDbCuein($cueIn);
|
|
|
|
$row->setDbCueout($cueOut);
|
|
|
|
$row->setDBCliplength($cliplength);
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2012-07-16 03:17:13 +02:00
|
|
|
} elseif (!is_null($cueIn)) {
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2012-07-11 00:51:32 +02:00
|
|
|
$sql = "SELECT INTERVAL '{$cueIn}' > INTERVAL '{$oldCueOut}'";
|
|
|
|
$r = $this->con->query($sql);
|
2012-02-20 18:24:04 +01:00
|
|
|
if ($r->fetchColumn(0)) {
|
|
|
|
$errArray["error"] = "Can't set cue in to be larger than cue out.";
|
2012-07-16 03:17:13 +02:00
|
|
|
|
2012-02-20 18:24:04 +01:00
|
|
|
return $errArray;
|
|
|
|
}
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2012-02-20 18:24:04 +01:00
|
|
|
$sql = "SELECT INTERVAL '{$oldCueOut}' - INTERVAL '{$cueIn}'";
|
2012-07-11 00:51:32 +02:00
|
|
|
$r = $this->con->query($sql);
|
|
|
|
$cliplength = $r->fetchColumn(0);
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2012-02-20 18:24:04 +01:00
|
|
|
$row->setDbCuein($cueIn);
|
|
|
|
$row->setDBCliplength($cliplength);
|
2012-07-16 03:17:13 +02:00
|
|
|
} elseif (!is_null($cueOut)) {
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2012-07-16 03:17:13 +02:00
|
|
|
if ($cueOut === "") {
|
2012-02-20 18:24:04 +01:00
|
|
|
$cueOut = $origLength;
|
|
|
|
}
|
2010-12-10 00:44:47 +01:00
|
|
|
|
2012-07-11 00:51:32 +02:00
|
|
|
$sql = "SELECT INTERVAL '{$cueOut}' < INTERVAL '{$oldCueIn}'";
|
|
|
|
$r = $this->con->query($sql);
|
2012-02-20 18:24:04 +01:00
|
|
|
if ($r->fetchColumn(0)) {
|
|
|
|
$errArray["error"] = "Can't set cue out to be smaller than cue in.";
|
2012-07-16 03:17:13 +02:00
|
|
|
|
2012-02-20 18:24:04 +01:00
|
|
|
return $errArray;
|
|
|
|
}
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2012-07-11 00:51:32 +02:00
|
|
|
$sql = "SELECT INTERVAL '{$cueOut}' > INTERVAL '{$origLength}'";
|
|
|
|
$r = $this->con->query($sql);
|
2012-07-16 03:17:13 +02:00
|
|
|
if ($r->fetchColumn(0)) {
|
2012-02-20 18:24:04 +01:00
|
|
|
$errArray["error"] = "Can't set cue out to be greater than file length.";
|
2012-07-16 03:17:13 +02:00
|
|
|
|
2012-02-20 18:24:04 +01:00
|
|
|
return $errArray;
|
|
|
|
}
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2012-02-20 18:24:04 +01:00
|
|
|
$sql = "SELECT INTERVAL '{$cueOut}' - INTERVAL '{$oldCueIn}'";
|
2012-07-11 00:51:32 +02:00
|
|
|
$r = $this->con->query($sql);
|
|
|
|
$cliplength = $r->fetchColumn(0);
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2012-02-20 18:24:04 +01:00
|
|
|
$row->setDbCueout($cueOut);
|
|
|
|
$row->setDBCliplength($cliplength);
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
2012-02-20 18:24:04 +01:00
|
|
|
$cliplength = $row->getDbCliplength();
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2012-07-11 00:51:32 +02:00
|
|
|
$sql = "SELECT INTERVAL '{$fadeIn}' > INTERVAL '{$cliplength}'";
|
|
|
|
$r = $this->con->query($sql);
|
2012-07-16 03:17:13 +02:00
|
|
|
if ($r->fetchColumn(0)) {
|
2012-02-20 18:24:04 +01:00
|
|
|
$fadeIn = $cliplength;
|
|
|
|
$row->setDbFadein($fadeIn);
|
|
|
|
}
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2012-07-11 00:51:32 +02:00
|
|
|
$sql = "SELECT INTERVAL '{$fadeOut}' > INTERVAL '{$cliplength}'";
|
|
|
|
$r = $this->con->query($sql);
|
2012-07-16 03:17:13 +02:00
|
|
|
if ($r->fetchColumn(0)) {
|
2012-02-20 18:24:04 +01:00
|
|
|
$fadeOut = $cliplength;
|
|
|
|
$row->setDbFadein($fadeOut);
|
|
|
|
}
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2012-02-20 18:24:04 +01:00
|
|
|
$row->save($this->con);
|
|
|
|
$this->pl->setDbMtime(new DateTime("now", new DateTimeZone("UTC")));
|
|
|
|
$this->pl->save($this->con);
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2012-02-20 18:24:04 +01:00
|
|
|
$this->con->commit();
|
2012-07-16 03:17:13 +02:00
|
|
|
} catch (Exception $e) {
|
2012-02-20 18:24:04 +01:00
|
|
|
$this->con->rollback();
|
|
|
|
throw $e;
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
2012-02-20 18:24:04 +01:00
|
|
|
return array("cliplength"=> $cliplength, "cueIn"=> $cueIn, "cueOut"=> $cueOut, "length"=> $this->getLength(),
|
|
|
|
"fadeIn"=> $fadeIn, "fadeOut"=> $fadeOut);
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
2011-02-04 06:15:56 +01:00
|
|
|
public function getAllPLMetaData()
|
|
|
|
{
|
|
|
|
$categories = $this->categories;
|
|
|
|
$md = array();
|
|
|
|
|
2012-07-16 03:17:13 +02:00
|
|
|
foreach ($categories as $key => $val) {
|
2011-02-04 06:15:56 +01:00
|
|
|
$method = 'get' . $val;
|
2012-02-07 14:58:16 +01:00
|
|
|
$md[$key] = $this->$method();
|
2011-02-04 06:15:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return $md;
|
|
|
|
}
|
|
|
|
|
2012-07-25 17:00:46 +02:00
|
|
|
public function getMetaData($category)
|
2010-12-07 20:19:27 +01:00
|
|
|
{
|
|
|
|
$cat = $this->categories[$category];
|
|
|
|
$method = 'get' . $cat;
|
2012-07-16 03:17:13 +02:00
|
|
|
|
2012-02-07 14:58:16 +01:00
|
|
|
return $this->$method();
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
2012-08-21 22:54:14 +02:00
|
|
|
public function setMetadata($category, $value)
|
2010-12-07 20:19:27 +01:00
|
|
|
{
|
|
|
|
$cat = $this->categories[$category];
|
|
|
|
|
|
|
|
$method = 'set' . $cat;
|
2012-02-07 14:58:16 +01:00
|
|
|
$this->$method($value);
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
2012-04-01 21:51:03 +02:00
|
|
|
public static function getPlaylistCount()
|
|
|
|
{
|
|
|
|
global $CC_CONFIG;
|
|
|
|
$con = Propel::getConnection();
|
2012-02-03 18:15:10 +01:00
|
|
|
$sql = 'SELECT count(*) as cnt FROM '.$CC_CONFIG["playListTable"];
|
2012-07-16 03:17:13 +02:00
|
|
|
|
2012-04-01 21:51:03 +02:00
|
|
|
return $con->query($sql)->fetchColumn(0);
|
2012-02-03 18:15:10 +01:00
|
|
|
}
|
2010-12-07 20:19:27 +01:00
|
|
|
|
|
|
|
/**
|
2012-02-03 18:15:10 +01:00
|
|
|
* Delete the file from all playlists.
|
|
|
|
* @param string $p_fileId
|
2010-12-07 20:19:27 +01:00
|
|
|
*/
|
2012-02-03 18:15:10 +01:00
|
|
|
public static function DeleteFileFromAllPlaylists($p_fileId)
|
2010-12-07 20:19:27 +01:00
|
|
|
{
|
2012-02-03 18:15:10 +01:00
|
|
|
CcPlaylistcontentsQuery::create()->filterByDbFileId($p_fileId)->delete();
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-02-04 00:12:06 +01:00
|
|
|
* Delete playlists that match the ids..
|
|
|
|
* @param array $p_ids
|
2010-12-07 20:19:27 +01:00
|
|
|
*/
|
2012-07-10 23:24:57 +02:00
|
|
|
public static function deletePlaylists($p_ids, $p_userId)
|
2010-12-07 20:19:27 +01:00
|
|
|
{
|
2012-08-21 21:42:44 +02:00
|
|
|
$userInfo = Zend_Auth::getInstance()->getStorage()->read();
|
|
|
|
$user = new Application_Model_User($userInfo->id);
|
|
|
|
$isAdminOrPM = $user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER));
|
|
|
|
|
|
|
|
if (!$isAdminOrPM) {
|
|
|
|
$leftOver = self::playlistsNotOwnedByUser($p_ids, $p_userId);
|
|
|
|
if (count($leftOver) == 0) {
|
|
|
|
CcPlaylistQuery::create()->findPKs($p_ids)->delete();
|
|
|
|
} else {
|
|
|
|
throw new PlaylistNoPermissionException;
|
|
|
|
}
|
2012-07-10 23:24:57 +02:00
|
|
|
} else {
|
2012-08-21 21:42:44 +02:00
|
|
|
CcPlaylistQuery::create()->findPKs($p_ids)->delete();
|
2012-07-10 23:09:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-09 17:03:57 +02:00
|
|
|
// This function returns that are not owen by $p_user_id among $p_ids
|
2012-07-10 23:09:21 +02:00
|
|
|
private static function playlistsNotOwnedByUser($p_ids, $p_userId){
|
|
|
|
$ownedByUser = CcPlaylistQuery::create()->filterByDbCreatorId($p_userId)->find()->getData();
|
|
|
|
$selectedPls = $p_ids;
|
|
|
|
$ownedPls = array();
|
2012-07-10 23:24:57 +02:00
|
|
|
foreach ($ownedByUser as $pl) {
|
|
|
|
if (in_array($pl->getDbId(), $selectedPls)) {
|
2012-07-10 23:09:21 +02:00
|
|
|
$ownedPls[] = $pl->getDbId();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$leftOvers = array_diff($selectedPls, $ownedPls);
|
|
|
|
return $leftOvers;
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
2012-07-11 22:14:11 +02:00
|
|
|
|
2012-08-21 22:54:14 +02:00
|
|
|
/**
|
|
|
|
* Delete all files from playlist
|
|
|
|
* @param int $p_playlistId
|
|
|
|
*/
|
|
|
|
public function deleteAllFilesFromPlaylist()
|
2012-08-21 17:12:33 +02:00
|
|
|
{
|
2012-08-21 22:54:14 +02:00
|
|
|
CcPlaylistcontentsQuery::create()->findByDbPlaylistId($this->id)->delete();
|
2012-08-21 17:12:33 +02:00
|
|
|
}
|
|
|
|
|
2010-12-07 20:19:27 +01:00
|
|
|
} // class Playlist
|
2012-02-04 00:12:06 +01:00
|
|
|
|
|
|
|
class PlaylistNotFoundException extends Exception {}
|
2012-07-10 23:09:21 +02:00
|
|
|
class PlaylistNoPermissionException extends Exception {}
|
2012-02-16 19:46:14 +01:00
|
|
|
class PlaylistOutDatedException extends Exception {}
|