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-07-16 03:17:13 +02:00
|
|
|
class Application_Model_Playlist
|
|
|
|
{
|
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"
|
|
|
|
);
|
2012-07-12 21:27:51 +02:00
|
|
|
|
|
|
|
private static $modifier2CriteriaMap = array(
|
2012-07-18 22:12:06 +02:00
|
|
|
"contains" => Criteria::ILIKE,
|
|
|
|
"does not contain" => Criteria::NOT_ILIKE,
|
2012-07-12 21:27:51 +02:00
|
|
|
"is" => Criteria::EQUAL,
|
|
|
|
"is not" => Criteria::NOT_EQUAL,
|
2012-07-18 22:12:06 +02:00
|
|
|
"starts with" => Criteria::ILIKE,
|
|
|
|
"ends with" => Criteria::ILIKE,
|
2012-07-12 21:27:51 +02:00
|
|
|
"is greater than" => Criteria::GREATER_THAN,
|
|
|
|
"is less than" => Criteria::LESS_THAN,
|
|
|
|
"is in the range" => Criteria::CUSTOM);
|
|
|
|
|
|
|
|
private static $criteria2PeerMap = array(
|
|
|
|
0 => "Select criteria",
|
2012-07-18 17:52:09 +02:00
|
|
|
"album_title" => "DbAlbumTitle",
|
|
|
|
"artist_name" => "DbArtistName",
|
|
|
|
"bit_rate" => "DbBitRate",
|
|
|
|
"bpm" => "DbBpm",
|
|
|
|
"comments" => "DbComments",
|
|
|
|
"composer" => "DbComposer",
|
|
|
|
"conductor" => "DbConductor",
|
|
|
|
"utime" => "DbUtime",
|
|
|
|
"mtime" => "DbMtime",
|
2012-07-20 17:25:54 +02:00
|
|
|
"lptime" => "DbLPtime",
|
2012-07-18 17:52:09 +02:00
|
|
|
"disc_number" => "DbDiscNumber",
|
|
|
|
"genre" => "DbGenre",
|
|
|
|
"isrc_number" => "DbIsrcNumber",
|
|
|
|
"label" => "DbLabel",
|
|
|
|
"language" => "DbLanguage",
|
|
|
|
"length" => "DbLength",
|
|
|
|
"lyricist" => "DbLyricist",
|
|
|
|
"mood" => "DbMood",
|
|
|
|
"name" => "DbName",
|
|
|
|
"orchestra" => "DbOrchestra",
|
|
|
|
"radio_station_name" => "DbRadioStation",
|
|
|
|
"rating" => "DbRating",
|
|
|
|
"sample_rate" => "DbSampleRate",
|
|
|
|
"track_title" => "DbTrackTitle",
|
|
|
|
"track_num" => "DbTrackNum",
|
|
|
|
"year" => "DbYear"
|
2012-07-12 21:27:51 +02:00
|
|
|
);
|
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-02-04 21:26:21 +01:00
|
|
|
$this->pl->setDbUTime("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-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-02-04 00:12:06 +01:00
|
|
|
Logging::log("Getting contents for playlist {$this->id}");
|
|
|
|
|
2010-12-07 20:19:27 +01:00
|
|
|
$files = array();
|
2012-04-24 18:59:07 +02:00
|
|
|
$query = CcPlaylistcontentsQuery::create()
|
|
|
|
->filterByDbPlaylistId($this->id);
|
2012-07-11 00:51:32 +02:00
|
|
|
|
2012-07-16 03:17:13 +02:00
|
|
|
if ($filterFiles) {
|
2012-04-24 18:59:07 +02:00
|
|
|
$query->useCcFilesQuery()
|
|
|
|
->filterByDbFileExists(true)
|
|
|
|
->endUse();
|
|
|
|
}
|
|
|
|
$query->orderByDbPosition()
|
|
|
|
->leftJoinWith('CcFiles');
|
|
|
|
$rows = $query->find($this->con);
|
2011-06-16 12:39:17 +02:00
|
|
|
|
2011-05-31 22:49:01 +02:00
|
|
|
$i = 0;
|
|
|
|
$offset = 0;
|
2010-12-07 20:19:27 +01:00
|
|
|
foreach ($rows as $row) {
|
2011-05-31 22:49:01 +02:00
|
|
|
$files[$i] = $row->toArray(BasePeer::TYPE_FIELDNAME, true, true);
|
2012-02-07 14:58:16 +01:00
|
|
|
|
|
|
|
|
2011-09-22 18:24:17 +02:00
|
|
|
$clipSec = Application_Model_Playlist::playlistTimeToSeconds($files[$i]['cliplength']);
|
2011-06-24 21:51:21 +02:00
|
|
|
$offset += $clipSec;
|
2012-02-24 15:07:04 +01:00
|
|
|
$offset_cliplength = Application_Model_Playlist::secondsToPlaylistTime($offset);
|
|
|
|
|
|
|
|
//format the length for UI.
|
|
|
|
$formatter = new LengthFormatter($files[$i]['cliplength']);
|
|
|
|
$files[$i]['cliplength'] = $formatter->format();
|
|
|
|
|
|
|
|
$formatter = new LengthFormatter($offset_cliplength);
|
|
|
|
$files[$i]['offset'] = $formatter->format();
|
2012-02-06 11:07:10 +01:00
|
|
|
|
2011-05-31 22:49:01 +02:00
|
|
|
$i++;
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return $files;
|
|
|
|
}
|
|
|
|
|
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-02-04 00:19:13 +01: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';
|
2012-02-06 11:07:10 +01:00
|
|
|
|
2012-02-04 00:19:13 +01:00
|
|
|
//done, just need to set back the formated values
|
|
|
|
return $fade;
|
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-02-07 14:58:16 +01:00
|
|
|
return $this->pl->getDbLength();
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
2012-02-03 18:15:10 +01:00
|
|
|
private function insertPlaylistElement($info)
|
|
|
|
{
|
|
|
|
$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);
|
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-02-04 00:12:06 +01:00
|
|
|
$file = CcFilesQuery::create()->findPK($p_item, $this->con);
|
2011-03-30 23:27:14 +02:00
|
|
|
|
2012-02-20 18:24:04 +01:00
|
|
|
if (isset($file) && $file->getDbFileExists()) {
|
|
|
|
$entry = $this->plItem;
|
|
|
|
$entry["id"] = $file->getDbId();
|
|
|
|
$entry["pos"] = $pos;
|
|
|
|
$entry["cliplength"] = $file->getDbLength();
|
|
|
|
$entry["cueout"] = $file->getDbLength();
|
2011-03-30 23:27:14 +02:00
|
|
|
|
2012-02-20 18:24:04 +01:00
|
|
|
return $entry;
|
2012-07-16 03:17:13 +02:00
|
|
|
} else {
|
2012-02-20 18:24:04 +01:00
|
|
|
throw new Exception("trying to add a file that does not exist.");
|
|
|
|
}
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
2012-07-18 17:52:09 +02:00
|
|
|
|
|
|
|
public function isStatic(){
|
|
|
|
if ($this->pl->getDbType() == "static") {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
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-02-04 19:27:26 +01: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)) {
|
|
|
|
Logging::log("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();
|
|
|
|
Logging::log("index is {$index}");
|
|
|
|
$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-02-04 00:12:06 +01:00
|
|
|
Logging::log("Adding to playlist");
|
|
|
|
Logging::log("at position {$pos}");
|
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
|
|
|
|
|
|
|
Logging::log("Adding to playlist");
|
2012-02-04 00:12:06 +01:00
|
|
|
Logging::log("at position {$pos}");
|
2012-02-03 18:15:10 +01:00
|
|
|
}
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2012-07-16 03:17:13 +02:00
|
|
|
foreach ($p_items as $ac) {
|
2012-02-04 00:12:06 +01:00
|
|
|
Logging::log("Adding audio file {$ac}");
|
2010-12-10 00:44:47 +01:00
|
|
|
|
2012-02-04 00:12:06 +01:00
|
|
|
$res = $this->insertPlaylistElement($this->buildEntry($ac, $pos));
|
2012-02-03 18:15:10 +01:00
|
|
|
$pos = $pos + 1;
|
|
|
|
}
|
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)) {
|
|
|
|
Logging::log("moving items to beginning of playlist");
|
|
|
|
|
|
|
|
foreach ($contentsToMove as $item) {
|
|
|
|
Logging::log("item {$item->getDbId()} to pos {$pos}");
|
|
|
|
$item->setDbPosition($pos);
|
|
|
|
$item->save($this->con);
|
|
|
|
$pos = $pos + 1;
|
|
|
|
}
|
|
|
|
foreach ($otherContent as $item) {
|
|
|
|
Logging::log("item {$item->getDbId()} to pos {$pos}");
|
|
|
|
$item->setDbPosition($pos);
|
|
|
|
$item->save($this->con);
|
|
|
|
$pos = $pos + 1;
|
|
|
|
}
|
2012-07-16 03:17:13 +02:00
|
|
|
} else {
|
2012-02-04 15:52:31 +01:00
|
|
|
Logging::log("moving items after {$p_afterItem}");
|
|
|
|
|
|
|
|
foreach ($otherContent as $item) {
|
|
|
|
Logging::log("item {$item->getDbId()} to pos {$pos}");
|
|
|
|
$item->setDbPosition($pos);
|
|
|
|
$item->save($this->con);
|
|
|
|
$pos = $pos + 1;
|
|
|
|
|
|
|
|
if ($item->getDbId() == $p_afterItem) {
|
|
|
|
foreach ($contentsToMove as $move) {
|
|
|
|
Logging::log("item {$move->getDbId()} to pos {$pos}");
|
|
|
|
$move->setDbPosition($pos);
|
|
|
|
$move->save($this->con);
|
|
|
|
$pos = $pos + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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-07-11 00:51:32 +02:00
|
|
|
Logging::log("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
|
|
|
|
|
|
|
|
2011-01-17 01:31:10 +01:00
|
|
|
|
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-16 03:17:13 +02:00
|
|
|
public function setPlaylistfades($fadein, $fadeout)
|
|
|
|
{
|
2012-02-05 23:38:12 +01:00
|
|
|
if (isset($fadein)) {
|
|
|
|
Logging::log("Setting playlist fade in {$fadein}");
|
|
|
|
$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-03-19 14:09:05 +01:00
|
|
|
Logging::log("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;
|
|
|
|
}
|
|
|
|
|
2010-12-07 20:19:27 +01:00
|
|
|
public function getPLMetaData($category)
|
|
|
|
{
|
|
|
|
$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
|
|
|
}
|
|
|
|
|
|
|
|
public function setPLMetaData($category, $value)
|
|
|
|
{
|
|
|
|
$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-02-07 17:29:52 +01:00
|
|
|
* This function is used for calculations! Don't modify for display purposes!
|
|
|
|
*
|
|
|
|
* Convert playlist time value to float seconds
|
|
|
|
*
|
|
|
|
* @param string $plt
|
|
|
|
* playlist interval value (HH:mm:ss.dddddd)
|
|
|
|
* @return int
|
|
|
|
* seconds
|
|
|
|
*/
|
2012-02-03 18:15:10 +01:00
|
|
|
public static function playlistTimeToSeconds($plt)
|
2010-12-07 20:19:27 +01:00
|
|
|
{
|
2012-02-03 18:15:10 +01:00
|
|
|
$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]);
|
|
|
|
}
|
2012-07-16 03:17:13 +02:00
|
|
|
|
2012-02-03 18:15:10 +01:00
|
|
|
return floatval($arr[0]);
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2012-02-07 17:29:52 +01:00
|
|
|
* This function is used for calculations! Don't modify for display purposes!
|
|
|
|
*
|
|
|
|
* Convert float seconds value to playlist time format
|
|
|
|
*
|
2012-07-16 03:17:13 +02:00
|
|
|
* @param float $seconds
|
2012-02-07 17:29:52 +01:00
|
|
|
* @return string
|
|
|
|
* interval in playlist time format (HH:mm:ss.d)
|
|
|
|
*/
|
2012-02-03 18:15:10 +01:00
|
|
|
public static function secondsToPlaylistTime($p_seconds)
|
2010-12-07 20:19:27 +01:00
|
|
|
{
|
2012-02-07 14:58:16 +01:00
|
|
|
$info = explode('.', $p_seconds);
|
2012-02-03 18:15:10 +01:00
|
|
|
$seconds = $info[0];
|
2012-07-16 03:17:13 +02:00
|
|
|
if (!isset($info[1])) {
|
2012-02-03 18:15:10 +01:00
|
|
|
$milliStr = 0;
|
2012-07-16 03:17:13 +02:00
|
|
|
} else {
|
2012-02-03 18:15:10 +01:00
|
|
|
$milliStr = $info[1];
|
|
|
|
}
|
|
|
|
$hours = floor($seconds / 3600);
|
|
|
|
$seconds -= $hours * 3600;
|
|
|
|
$minutes = floor($seconds / 60);
|
|
|
|
$seconds -= $minutes * 60;
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2012-02-03 18:15:10 +01:00
|
|
|
$res = sprintf("%02d:%02d:%02d.%s", $hours, $minutes, $seconds, $milliStr);
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2012-02-03 18:15:10 +01:00
|
|
|
return $res;
|
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-07-10 23:09:21 +02:00
|
|
|
$leftOver = self::playlistsNotOwnedByUser($p_ids, $p_userId);
|
2012-07-10 23:24:57 +02:00
|
|
|
if (count($leftOver) == 0) {
|
2012-07-10 23:09:21 +02:00
|
|
|
CcPlaylistQuery::create()->findPKs($p_ids)->delete();
|
2012-07-10 23:24:57 +02:00
|
|
|
} else {
|
2012-07-10 23:09:21 +02:00
|
|
|
throw new PlaylistNoPermissionException;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// This function returns that are not owen by $p_user_id among $p_ids
|
|
|
|
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-07-16 23:18:37 +02:00
|
|
|
/**
|
|
|
|
* Delete all files from playlist
|
|
|
|
* @param int $p_playlistId
|
|
|
|
*/
|
2012-07-18 17:52:09 +02:00
|
|
|
public function deleteAllFilesFromPlaylist()
|
2012-07-16 23:18:37 +02:00
|
|
|
{
|
2012-07-18 17:52:09 +02:00
|
|
|
CcPlaylistcontentsQuery::create()->findByDbPlaylistId($this->id)->delete();
|
2012-07-16 23:18:37 +02:00
|
|
|
}
|
|
|
|
|
2012-07-11 22:14:11 +02:00
|
|
|
|
|
|
|
// smart playlist functions start
|
2012-07-18 17:52:09 +02:00
|
|
|
public function shuffleSmartPlaylist(){
|
|
|
|
// if it here that means it's static pl
|
|
|
|
$this->saveType("static");
|
|
|
|
$contents = CcPlaylistcontentsQuery::create()
|
|
|
|
->filterByDbPlaylistId($this->id)
|
|
|
|
->orderByDbPosition()
|
|
|
|
->find();
|
|
|
|
$shuffledPos = range(0, count($contents)-1);
|
|
|
|
shuffle($shuffledPos);
|
|
|
|
$temp = new CcPlaylist();
|
|
|
|
foreach ($contents as $item) {
|
|
|
|
$item->setDbPosition(array_shift($shuffledPos));
|
|
|
|
$item->save();
|
|
|
|
}
|
|
|
|
return array("result"=>0);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function saveType($p_playlistType)
|
|
|
|
{
|
|
|
|
// saving dynamic/static flag
|
|
|
|
CcPlaylistQuery::create()->findPk($this->id)->setDbType($p_playlistType)->save();
|
|
|
|
}
|
|
|
|
|
2012-07-11 22:14:11 +02:00
|
|
|
/**
|
|
|
|
* Saves smart playlist criteria
|
|
|
|
* @param array $p_criteria
|
|
|
|
*/
|
2012-07-18 17:52:09 +02:00
|
|
|
public function saveSmartPlaylistCriteria($p_criteria)
|
2012-07-11 22:14:11 +02:00
|
|
|
{
|
2012-07-18 17:52:09 +02:00
|
|
|
$data = $this->organizeSmartPlyalistCriteria($p_criteria);
|
2012-07-12 21:27:51 +02:00
|
|
|
// things we need to check
|
|
|
|
// 1. limit value shouldn't be empty and has upperbound of 24 hrs
|
|
|
|
// 2. sp_criteria or sp_criteria_modifier shouldn't be 0
|
2012-07-12 23:58:44 +02:00
|
|
|
// 3. validate formate according to DB column type
|
2012-07-12 21:27:51 +02:00
|
|
|
$multiplier = 1;
|
|
|
|
$result = 0;
|
|
|
|
$errors = array();
|
2012-07-12 23:58:44 +02:00
|
|
|
$error = array();
|
2012-07-17 17:07:16 +02:00
|
|
|
|
|
|
|
// saving dynamic/static flag
|
|
|
|
$playlistType = $data['etc']['sp_type'] == 0 ? 'static':'dynamic';
|
2012-07-18 17:52:09 +02:00
|
|
|
$this->saveType($playlistType);
|
2012-07-17 17:07:16 +02:00
|
|
|
|
2012-07-20 21:32:46 +02:00
|
|
|
// validation start
|
2012-07-12 21:27:51 +02:00
|
|
|
if ($data['etc']['sp_limit_options'] == 'hours') {
|
|
|
|
$multiplier = 60;
|
|
|
|
}
|
|
|
|
if ($data['etc']['sp_limit_options'] == 'hours' || $data['etc']['sp_limit_options'] == 'mins') {
|
2012-07-19 20:45:15 +02:00
|
|
|
if ($data['etc']['sp_limit_value'] == "" || floatval($data['etc']['sp_limit_value']) <= 0) {
|
|
|
|
$error[] = "Limit cannot be empty or smaller than 0";
|
2012-07-12 21:27:51 +02:00
|
|
|
} else {
|
|
|
|
$mins = $data['etc']['sp_limit_value'] * $multiplier;
|
|
|
|
if ($mins > 14400) {
|
2012-07-16 17:01:34 +02:00
|
|
|
$error[] = "Limit cannot be more than 24 hrs";
|
2012-07-12 21:27:51 +02:00
|
|
|
}
|
|
|
|
}
|
2012-07-19 20:45:15 +02:00
|
|
|
} else {
|
|
|
|
if ($data['etc']['sp_limit_value'] == "" || floatval($data['etc']['sp_limit_value']) <= 0) {
|
|
|
|
$error[] = "Limit cannot be empty or smaller than 0";
|
|
|
|
} else if (floatval($data['etc']['sp_limit_value']) < 1) {
|
|
|
|
$error[] = "The value should be an integer";
|
2012-07-12 23:58:44 +02:00
|
|
|
}
|
2012-07-12 21:27:51 +02:00
|
|
|
}
|
|
|
|
|
2012-07-19 20:45:15 +02:00
|
|
|
if (count($error) > 0){
|
|
|
|
$errors[] = array("element"=>"sp_limit_value", "msg"=>$error);
|
|
|
|
}
|
2012-07-20 21:32:46 +02:00
|
|
|
|
2012-07-12 21:27:51 +02:00
|
|
|
foreach ($data['criteria'] as $key=>$d){
|
|
|
|
$error = array();
|
2012-07-20 21:32:46 +02:00
|
|
|
$column = CcFilesPeer::getTableMap()->getColumnByPhpName(self::$criteria2PeerMap[$d['sp_criteria_field']]);
|
2012-07-12 21:27:51 +02:00
|
|
|
// check for not selected select box
|
2012-07-16 17:01:34 +02:00
|
|
|
if ($d['sp_criteria_field'] == "0" || $d['sp_criteria_modifier'] == "0"){
|
2012-07-12 21:27:51 +02:00
|
|
|
$error[] = "You must select Criteria and Modifier";
|
|
|
|
} else {
|
2012-07-20 21:32:46 +02:00
|
|
|
// validation on type of column
|
2012-07-16 17:01:34 +02:00
|
|
|
if ($d['sp_criteria_field'] == 'length') {
|
2012-07-12 21:27:51 +02:00
|
|
|
if (!preg_match("/(\d{2}):(\d{2}):(\d{2})/", $d['sp_criteria_value'])) {
|
|
|
|
$error[] = "'Length' should be in '00:00:00' format";
|
|
|
|
}
|
2012-07-20 21:32:46 +02:00
|
|
|
} else if ($column->getType() == PropelColumnTypes::TIMESTAMP) {
|
2012-07-19 22:57:24 +02:00
|
|
|
if (!preg_match("/(\d{4})-(\d{2})-(\d{2})/", $d['sp_criteria_value'])) {
|
|
|
|
$error[] = "The value should be in timestamp format(eg. 0000-00-00 or 00-00-00 00:00:00";
|
2012-07-20 21:32:46 +02:00
|
|
|
} else if (!Application_Common_DateHelper::checkDateTimeRangeForSQL($d['sp_criteria_value'])) {
|
2012-07-19 22:57:24 +02:00
|
|
|
// check for if it is in valid range( 1753-01-01 ~ 12/31/9999 )
|
2012-07-20 21:32:46 +02:00
|
|
|
$error[] = "$d[sp_criteria_value] is not a valid date/time string";
|
2012-07-19 22:57:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($d['sp_criteria_extra'])) {
|
|
|
|
if (!preg_match("/(\d{4})-(\d{2})-(\d{2})/", $d['sp_criteria_extra'])) {
|
2012-07-12 21:27:51 +02:00
|
|
|
$error[] = "The value should be in timestamp format(eg. 0000-00-00 or 00-00-00 00:00:00";
|
2012-07-20 21:32:46 +02:00
|
|
|
} else if (!Application_Common_DateHelper::checkDateTimeRangeForSQL($d['sp_criteria_extra'])) {
|
2012-07-19 22:57:24 +02:00
|
|
|
// check for if it is in valid range( 1753-01-01 ~ 12/31/9999 )
|
2012-07-20 21:32:46 +02:00
|
|
|
$error[] = "$d[sp_criteria_extra] is not a valid date/time string";
|
2012-07-12 21:27:51 +02:00
|
|
|
}
|
|
|
|
}
|
2012-07-20 21:32:46 +02:00
|
|
|
} else if ($column->getType() == PropelColumnTypes::INTEGER) {
|
2012-07-19 22:57:24 +02:00
|
|
|
if (!is_numeric($d['sp_criteria_value'])) {
|
|
|
|
$error[] = "The value has to be numeric";
|
|
|
|
}
|
2012-07-20 21:32:46 +02:00
|
|
|
// length check
|
|
|
|
if (intval($d['sp_criteria_value']) >= pow(2,31)) {
|
|
|
|
$error[] = "The value should be less then 2147483648";
|
|
|
|
}
|
|
|
|
} else if ($column->getType() == PropelColumnTypes::VARCHAR) {
|
|
|
|
if (strlen($d['sp_criteria_value']) > $column->getSize()) {
|
|
|
|
$error[] = "The value should be less ".$column->getSize()." characters";
|
|
|
|
}
|
2012-07-12 21:27:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($d['sp_criteria_value'] == "") {
|
|
|
|
$error[] = "Value cannot be empty";
|
|
|
|
}
|
2012-07-12 23:58:44 +02:00
|
|
|
if(count($error) > 0){
|
2012-07-16 20:44:50 +02:00
|
|
|
$errors[] = array("element"=>"sp_criteria_field_".$key, "msg"=>$error);
|
2012-07-12 23:58:44 +02:00
|
|
|
}
|
2012-07-12 21:27:51 +02:00
|
|
|
}
|
|
|
|
$result = count($errors) > 0 ? 1 :0;
|
2012-07-12 23:58:44 +02:00
|
|
|
if ($result == 0) {
|
2012-07-18 17:52:09 +02:00
|
|
|
$this->storeCriteriaIntoDb($data);
|
2012-07-12 23:58:44 +02:00
|
|
|
}
|
2012-07-19 20:52:39 +02:00
|
|
|
|
|
|
|
//get number of files that meet the criteria
|
|
|
|
$files = $this->getListofFilesMeetCriteria();
|
|
|
|
|
|
|
|
return array("result"=>$result, "errors"=>$errors, "poolCount"=>$files["count"]);
|
2012-07-11 22:14:11 +02:00
|
|
|
}
|
|
|
|
|
2012-07-18 17:52:09 +02:00
|
|
|
public function storeCriteriaIntoDb($p_criteriaData){
|
2012-07-12 23:58:44 +02:00
|
|
|
// delete criteria under $p_playlistId
|
2012-07-18 17:52:09 +02:00
|
|
|
CcPlaylistcriteriaQuery::create()->findByDbPlaylistId($this->id)->delete();
|
2012-07-12 23:58:44 +02:00
|
|
|
|
|
|
|
foreach( $p_criteriaData['criteria'] as $d){
|
2012-07-18 17:52:09 +02:00
|
|
|
$qry = new CcPlaylistcriteria();
|
|
|
|
$qry->setDbCriteria($d['sp_criteria_field'])
|
|
|
|
->setDbModifier($d['sp_criteria_modifier'])
|
|
|
|
->setDbValue($d['sp_criteria_value'])
|
|
|
|
->setDbPlaylistId($this->id);
|
|
|
|
|
2012-07-12 23:58:44 +02:00
|
|
|
if (isset($d['sp_criteria_extra'])) {
|
2012-07-18 17:52:09 +02:00
|
|
|
$qry->setDbExtra($d['sp_criteria_extra']);
|
2012-07-12 23:58:44 +02:00
|
|
|
}
|
2012-07-18 17:52:09 +02:00
|
|
|
$qry->save();
|
2012-07-12 23:58:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// insert limit info
|
2012-07-18 17:52:09 +02:00
|
|
|
$qry = new CcPlaylistcriteria();
|
|
|
|
$qry->setDbCriteria("limit")
|
|
|
|
->setDbModifier($p_criteriaData['etc']['sp_limit_options'])
|
|
|
|
->setDbValue($p_criteriaData['etc']['sp_limit_value'])
|
|
|
|
->setDbPlaylistId($this->id)
|
|
|
|
->save();
|
2012-07-11 22:14:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* generate list of tracks. This function saves creiteria and generate
|
|
|
|
* tracks.
|
|
|
|
* @param array $p_criteria
|
|
|
|
*/
|
2012-07-18 17:52:09 +02:00
|
|
|
public function generateSmartPlaylist($p_criteria, $returnList=false)
|
2012-07-11 22:14:11 +02:00
|
|
|
{
|
2012-07-18 17:52:09 +02:00
|
|
|
$result = $this->saveSmartPlaylistCriteria($p_criteria);
|
2012-07-12 21:27:51 +02:00
|
|
|
if ($result['result'] != 0) {
|
|
|
|
return $result;
|
2012-07-16 23:18:37 +02:00
|
|
|
} else {
|
2012-07-18 17:52:09 +02:00
|
|
|
$insertList = $this->getListOfFilesUnderLimit();
|
|
|
|
$this->deleteAllFilesFromPlaylist();
|
|
|
|
$this->addAudioClips(array_keys($insertList));
|
|
|
|
return array("result"=>0);
|
2012-07-12 21:27:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-18 17:52:09 +02:00
|
|
|
public function getListOfFilesUnderLimit()
|
2012-07-17 17:07:16 +02:00
|
|
|
{
|
2012-07-18 17:52:09 +02:00
|
|
|
$info = $this->getListofFilesMeetCriteria();
|
2012-07-17 17:07:16 +02:00
|
|
|
$files = $info['files'];
|
2012-07-19 20:45:15 +02:00
|
|
|
$limit = $info['limit'];
|
|
|
|
|
2012-07-17 17:07:16 +02:00
|
|
|
$insertList = array();
|
2012-07-19 20:45:15 +02:00
|
|
|
$totalTime = 0;
|
|
|
|
|
|
|
|
// this moves the pointer to the first element in the collection
|
|
|
|
$files->getFirst();
|
|
|
|
$iterator = $files->getIterator();
|
2012-07-19 22:57:24 +02:00
|
|
|
while ($iterator->valid() && $totalTime < $limit['time']) {
|
2012-07-19 20:45:15 +02:00
|
|
|
$id = $iterator->current()->getDbId();
|
|
|
|
$length = Application_Common_DateHelper::calculateLengthInSeconds($iterator->current()->getDbLength());
|
|
|
|
$insertList[$id] = $length;
|
|
|
|
$totalTime += $length;
|
2012-07-17 17:07:16 +02:00
|
|
|
if ( !is_null($limit['items']) && $limit['items'] == count($insertList)) {
|
|
|
|
break;
|
2012-07-19 20:45:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$iterator->next();
|
2012-07-17 17:07:16 +02:00
|
|
|
}
|
|
|
|
return $insertList;
|
|
|
|
}
|
|
|
|
|
2012-07-12 21:27:51 +02:00
|
|
|
// this function return list of propel object
|
2012-07-19 20:45:15 +02:00
|
|
|
public function getListofFilesMeetCriteria()
|
2012-07-12 21:27:51 +02:00
|
|
|
{
|
2012-07-18 17:52:09 +02:00
|
|
|
$out = CcPlaylistcriteriaQuery::create()->findByDbPlaylistId($this->id);
|
2012-07-16 23:18:37 +02:00
|
|
|
$storedCrit = array();
|
|
|
|
foreach ($out as $crit) {
|
|
|
|
$criteria = $crit->getDbCriteria();
|
|
|
|
$modifier = $crit->getDbModifier();
|
|
|
|
$value = $crit->getDbValue();
|
|
|
|
$extra = $crit->getDbExtra();
|
|
|
|
|
|
|
|
if($criteria == "limit"){
|
|
|
|
$storedCrit["limit"] = array("value"=>$value, "modifier"=>$modifier);
|
|
|
|
}else{
|
|
|
|
$storedCrit["crit"][] = array("criteria"=>$criteria, "value"=>$value, "modifier"=>$modifier, "extra"=>$extra);
|
|
|
|
}
|
|
|
|
}
|
2012-07-19 20:45:15 +02:00
|
|
|
|
2012-07-19 22:57:24 +02:00
|
|
|
$qry = CcFilesQuery::create();
|
2012-07-23 17:03:29 +02:00
|
|
|
|
2012-07-20 01:09:51 +02:00
|
|
|
if (isset($storedCrit["crit"])) {
|
|
|
|
foreach ($storedCrit["crit"] as $criteria) {
|
|
|
|
$spCriteriaPhpName = self::$criteria2PeerMap[$criteria['criteria']];
|
|
|
|
$spCriteria = $criteria['criteria'];
|
|
|
|
|
|
|
|
$spCriteriaModifier = $criteria['modifier'];
|
|
|
|
$spCriteriaValue = $criteria['value'];
|
|
|
|
if ($spCriteriaModifier == "starts with") {
|
|
|
|
$spCriteriaValue = "$spCriteriaValue%";
|
|
|
|
} else if ($spCriteriaModifier == "ends with") {
|
|
|
|
$spCriteriaValue = "%$spCriteriaValue";
|
|
|
|
} else if ($spCriteriaModifier == "contains" || $spCriteriaModifier == "does not contain") {
|
|
|
|
$spCriteriaValue = "%$spCriteriaValue%";
|
|
|
|
} else if ($spCriteriaModifier == "is in the range") {
|
|
|
|
$spCriteriaValue = "$spCriteria > '$spCriteriaValue' AND $spCriteria < '$criteria[extra]'";
|
|
|
|
}
|
|
|
|
$spCriteriaModifier = self::$modifier2CriteriaMap[$spCriteriaModifier];
|
|
|
|
try{
|
|
|
|
$qry->filterBy($spCriteriaPhpName, $spCriteriaValue, $spCriteriaModifier);
|
|
|
|
$qry->addAscendingOrderByColumn('random()');
|
|
|
|
}catch (Exception $e){
|
|
|
|
Logging::log($e);
|
|
|
|
}
|
2012-07-18 17:52:09 +02:00
|
|
|
}
|
2012-07-16 23:18:37 +02:00
|
|
|
}
|
|
|
|
// construct limit restriction
|
|
|
|
$limits = array();
|
2012-07-20 01:09:51 +02:00
|
|
|
if (isset($storedCrit['limit'])) {
|
|
|
|
if ($storedCrit['limit']['modifier'] == "items") {
|
|
|
|
$limits['time'] = 1440 * 60;
|
|
|
|
$limits['items'] = $storedCrit['limit']['value'];
|
|
|
|
} else {
|
|
|
|
$limits['time'] = $storedCrit['limit']['modifier'] == "hours" ? intval($storedCrit['limit']['value']) * 60 * 60 : intval($storedCrit['limit']['value'] * 60);
|
|
|
|
$limits['items'] = null;
|
|
|
|
}
|
2012-07-12 21:27:51 +02:00
|
|
|
}
|
|
|
|
try{
|
2012-07-19 22:57:24 +02:00
|
|
|
$out = $qry->setFormatter(ModelCriteria::FORMAT_ON_DEMAND)->find();
|
2012-07-19 20:45:15 +02:00
|
|
|
return array("files"=>$out, "limit"=>$limits, "count"=>$out->count());
|
2012-07-12 21:27:51 +02:00
|
|
|
}catch(Exception $e){
|
2012-07-18 17:52:09 +02:00
|
|
|
Logging::log($e);
|
2012-07-12 21:27:51 +02:00
|
|
|
}
|
|
|
|
|
2012-07-11 22:14:11 +02:00
|
|
|
}
|
|
|
|
|
2012-07-12 21:27:51 +02:00
|
|
|
private static function organizeSmartPlyalistCriteria($p_criteria)
|
2012-07-11 22:14:11 +02:00
|
|
|
{
|
2012-07-13 20:32:05 +02:00
|
|
|
$fieldNames = array('sp_criteria_field', 'sp_criteria_modifier', 'sp_criteria_value', 'sp_criteria_extra');
|
2012-07-11 22:14:11 +02:00
|
|
|
$output = array();
|
|
|
|
foreach ($p_criteria as $ele) {
|
|
|
|
$index = strrpos($ele['name'], '_');
|
|
|
|
$fieldName = substr($ele['name'], 0, $index);
|
|
|
|
if (in_array($fieldName, $fieldNames)) {
|
|
|
|
$rowNum = intval(substr($ele['name'], $index+1));
|
2012-07-12 21:27:51 +02:00
|
|
|
$output['criteria'][$rowNum][$fieldName] = trim($ele['value']);
|
2012-07-11 22:14:11 +02:00
|
|
|
}else{
|
|
|
|
$output['etc'][$ele['name']] = $ele['value'];
|
|
|
|
}
|
|
|
|
}
|
2012-07-12 21:27:51 +02:00
|
|
|
|
|
|
|
return $output;
|
2012-07-11 22:14:11 +02:00
|
|
|
}
|
|
|
|
// smart playlist functions end
|
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 {}
|
2012-07-18 17:52:09 +02:00
|
|
|
class PlaylistDyanmicException extends Exception {}
|