2012-07-25 18:44:37 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require_once 'formatters/LengthFormatter.php';
|
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @package Airtime
|
|
|
|
* @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_Block implements Application_Model_LibraryEditable
|
2012-07-25 18:44:37 +02:00
|
|
|
{
|
2012-07-30 23:31:54 +02:00
|
|
|
/**
|
|
|
|
* propel connection object.
|
|
|
|
*/
|
|
|
|
private $con;
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
/**
|
|
|
|
* unique id for the block.
|
|
|
|
*/
|
2012-07-25 18:44:37 +02:00
|
|
|
private $id;
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-25 18:44:37 +02:00
|
|
|
private $block;
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
/**
|
|
|
|
* info needed to insert a new block element.
|
|
|
|
*/
|
|
|
|
private $blockItem = array(
|
2012-09-12 17:31:41 +02:00
|
|
|
"id" => "",
|
|
|
|
"pos" => "",
|
2012-07-30 23:31:54 +02:00
|
|
|
"cliplength" => "",
|
2012-09-12 17:31:41 +02:00
|
|
|
"cuein" => "00:00:00",
|
|
|
|
"cueout" => "00:00:00",
|
|
|
|
"fadein" => "0.0",
|
|
|
|
"fadeout" => "0.0",
|
2012-07-30 23:31:54 +02:00
|
|
|
);
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
//using propel's phpNames.
|
|
|
|
private $categories = array(
|
2012-09-12 17:31:41 +02:00
|
|
|
"dc:title" => "Name",
|
|
|
|
"dc:creator" => "Creator",
|
2012-07-30 23:31:54 +02:00
|
|
|
"dc:description" => "Description",
|
|
|
|
"dcterms:extent" => "Length"
|
|
|
|
);
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
private static $modifier2CriteriaMap = array(
|
2012-09-12 17:31:41 +02:00
|
|
|
"contains" => Criteria::ILIKE,
|
2012-07-30 23:31:54 +02:00
|
|
|
"does not contain" => Criteria::NOT_ILIKE,
|
2012-09-12 17:31:41 +02:00
|
|
|
"is" => Criteria::EQUAL,
|
|
|
|
"is not" => Criteria::NOT_EQUAL,
|
|
|
|
"starts with" => Criteria::ILIKE,
|
|
|
|
"ends with" => Criteria::ILIKE,
|
|
|
|
"is greater than" => Criteria::GREATER_THAN,
|
|
|
|
"is less than" => Criteria::LESS_THAN,
|
|
|
|
"is in the range" => Criteria::CUSTOM);
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
private static $criteria2PeerMap = array(
|
2012-09-12 17:31:41 +02:00
|
|
|
0 => "Select criteria",
|
|
|
|
"album_title" => "DbAlbumTitle",
|
|
|
|
"artist_name" => "DbArtistName",
|
|
|
|
"bit_rate" => "DbBitRate",
|
|
|
|
"bpm" => "DbBpm",
|
|
|
|
"composer" => "DbComposer",
|
|
|
|
"conductor" => "DbConductor",
|
|
|
|
"copyright" => "DbCopyright",
|
2013-02-19 22:38:58 +01:00
|
|
|
"cuein" => "DbCuein",
|
|
|
|
"cueout" => "DbCueout",
|
2012-09-12 17:31:41 +02:00
|
|
|
"encoded_by" => "DbEncodedBy",
|
|
|
|
"utime" => "DbUtime",
|
|
|
|
"mtime" => "DbMtime",
|
|
|
|
"lptime" => "DbLPtime",
|
|
|
|
"genre" => "DbGenre",
|
|
|
|
"info_url" => "DbInfoUrl",
|
|
|
|
"isrc_number" => "DbIsrcNumber",
|
|
|
|
"label" => "DbLabel",
|
|
|
|
"language" => "DbLanguage",
|
|
|
|
"length" => "DbLength",
|
|
|
|
"mime" => "DbMime",
|
|
|
|
"mood" => "DbMood",
|
|
|
|
"owner_id" => "DbOwnerId",
|
|
|
|
"replay_gain" => "DbReplayGain",
|
|
|
|
"sample_rate" => "DbSampleRate",
|
|
|
|
"track_title" => "DbTrackTitle",
|
2012-08-01 23:10:56 +02:00
|
|
|
"track_number" => "DbTrackNumber",
|
2012-09-12 17:31:41 +02:00
|
|
|
"year" => "DbYear"
|
2012-07-25 18:44:37 +02:00
|
|
|
);
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
public function __construct($id=null, $con=null)
|
|
|
|
{
|
|
|
|
if (isset($id)) {
|
|
|
|
$this->block = CcBlockQuery::create()->findPk($id);
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
if (is_null($this->block)) {
|
|
|
|
throw new BlockNotFoundException();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$this->block = new CcBlock();
|
|
|
|
$this->block->setDbUTime(new DateTime("now", new DateTimeZone("UTC")));
|
|
|
|
$this->block->save();
|
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2013-04-29 22:55:08 +02:00
|
|
|
$this->blockItem["fadein"] = Application_Model_Preference::GetDefaultFadeIn();
|
|
|
|
$this->blockItem["fadeout"] = Application_Model_Preference::GetDefaultFadeOut();
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
$this->con = isset($con) ? $con : Propel::getConnection(CcBlockPeer::DATABASE_NAME);
|
|
|
|
$this->id = $this->block->getDbId();
|
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
/**
|
|
|
|
* Return local ID of virtual file.
|
|
|
|
*
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function getId()
|
|
|
|
{
|
|
|
|
return $this->id;
|
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
/**
|
|
|
|
* Rename stored virtual block
|
|
|
|
*
|
|
|
|
* @param string $p_newname
|
|
|
|
*/
|
|
|
|
public function setName($p_newname)
|
|
|
|
{
|
|
|
|
$this->block->setDbName($p_newname);
|
|
|
|
$this->block->setDbMtime(new DateTime("now", new DateTimeZone("UTC")));
|
|
|
|
$this->block->save($this->con);
|
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
/**
|
|
|
|
* Get mnemonic block name
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getName()
|
|
|
|
{
|
|
|
|
return $this->block->getDbName();
|
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
public function setDescription($p_description)
|
|
|
|
{
|
|
|
|
$this->block->setDbDescription($p_description);
|
|
|
|
$this->block->setDbMtime(new DateTime("now", new DateTimeZone("UTC")));
|
|
|
|
$this->block->save($this->con);
|
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
public function getDescription()
|
|
|
|
{
|
|
|
|
return $this->block->getDbDescription();
|
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
public function getCreator()
|
|
|
|
{
|
|
|
|
return $this->block->getCcSubjs()->getDbLogin();
|
2012-07-25 18:44:37 +02:00
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
public function getCreatorId()
|
|
|
|
{
|
|
|
|
return $this->block->getCcSubjs()->getDbId();
|
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
public function setCreator($p_id)
|
|
|
|
{
|
|
|
|
$this->block->setDbCreatorId($p_id);
|
|
|
|
$this->block->setDbMtime(new DateTime("now", new DateTimeZone("UTC")));
|
|
|
|
$this->block->save($this->con);
|
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
public function getLastModified($format = null)
|
|
|
|
{
|
|
|
|
return $this->block->getDbMtime($format);
|
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
public function getSize()
|
|
|
|
{
|
|
|
|
return $this->block->countCcBlockcontentss();
|
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
/**
|
|
|
|
* Get the entire block as a two dimentional array, sorted in order of play.
|
|
|
|
* @param boolean $filterFiles if this is true, it will only return files that has
|
|
|
|
* file_exists flag set to true
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getContents($filterFiles=false)
|
|
|
|
{
|
2012-08-22 00:41:56 +02:00
|
|
|
Logging::info("Getting contents for block {$this->id}");
|
2012-09-12 23:26:41 +02:00
|
|
|
|
2012-09-12 21:36:37 +02:00
|
|
|
$sql = <<<SQL
|
2012-09-12 17:31:41 +02:00
|
|
|
SELECT pc.id AS id,
|
|
|
|
pc.position,
|
|
|
|
pc.cliplength AS LENGTH,
|
|
|
|
pc.cuein,
|
|
|
|
pc.cueout,
|
|
|
|
pc.fadein,
|
|
|
|
pc.fadeout,
|
|
|
|
bl.type,
|
|
|
|
f.LENGTH AS orig_length,
|
|
|
|
f.id AS item_id,
|
|
|
|
f.track_title,
|
|
|
|
f.artist_name AS creator,
|
|
|
|
f.file_exists AS EXISTS,
|
2012-09-12 21:55:43 +02:00
|
|
|
f.filepath AS path,
|
|
|
|
f.mime as mime
|
2012-09-12 17:31:41 +02:00
|
|
|
FROM cc_blockcontents AS pc
|
|
|
|
LEFT JOIN cc_files AS f ON pc.file_id=f.id
|
|
|
|
LEFT JOIN cc_block AS bl ON pc.block_id = bl.id
|
|
|
|
WHERE pc.block_id = :block_id
|
2012-11-05 19:58:11 +01:00
|
|
|
|
|
|
|
SQL;
|
|
|
|
|
|
|
|
if ($filterFiles) {
|
|
|
|
$sql .= <<<SQL
|
|
|
|
AND f.file_exists = :file_exists
|
2012-09-12 21:36:37 +02:00
|
|
|
SQL;
|
2012-11-05 19:58:11 +01:00
|
|
|
}
|
|
|
|
$sql .= <<<SQL
|
2012-09-06 17:11:09 +02:00
|
|
|
|
2012-11-05 19:58:11 +01:00
|
|
|
ORDER BY pc.position
|
|
|
|
SQL;
|
|
|
|
$params = array(':block_id'=>$this->id);
|
|
|
|
if ($filterFiles) {
|
|
|
|
$params[':file_exists'] = $filterFiles;
|
|
|
|
}
|
|
|
|
$rows = Application_Common_Database::prepareAndExecute($sql, $params);
|
2012-07-26 21:30:49 +02:00
|
|
|
|
|
|
|
$offset = 0;
|
|
|
|
foreach ($rows as &$row) {
|
|
|
|
|
|
|
|
$clipSec = Application_Common_DateHelper::playlistTimeToSeconds($row['length']);
|
2013-04-29 22:55:08 +02:00
|
|
|
|
|
|
|
$row['trackSec'] = $clipSec;
|
|
|
|
|
|
|
|
$row['cueInSec'] = Application_Common_DateHelper::playlistTimeToSeconds($row['cuein']);
|
|
|
|
$row['cueOutSec'] = Application_Common_DateHelper::playlistTimeToSeconds($row['cueout']);
|
|
|
|
|
2012-07-26 21:30:49 +02:00
|
|
|
$offset += $clipSec;
|
|
|
|
$offset_cliplength = Application_Common_DateHelper::secondsToPlaylistTime($offset);
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-26 21:30:49 +02:00
|
|
|
//format the length for UI.
|
|
|
|
$formatter = new LengthFormatter($row['length']);
|
|
|
|
$row['length'] = $formatter->format();
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-26 21:30:49 +02:00
|
|
|
$formatter = new LengthFormatter($offset_cliplength);
|
|
|
|
$row['offset'] = $formatter->format();
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-10-11 17:49:04 +02:00
|
|
|
//format the fades in format 00(.0)
|
2012-08-16 20:35:24 +02:00
|
|
|
$fades = $this->getFadeInfo($row['position']);
|
|
|
|
$row['fadein'] = $fades[0];
|
|
|
|
$row['fadeout'] = $fades[1];
|
2012-10-11 17:49:04 +02:00
|
|
|
|
|
|
|
// format the cues in format 00:00:00(.0)
|
|
|
|
// we need to add the '.0' for cues and not fades
|
|
|
|
// because propel takes care of this for us
|
|
|
|
// (we use propel to fetch the fades)
|
|
|
|
$row['cuein'] = str_pad(substr($row['cuein'], 0, 10), 10, '.0');
|
|
|
|
$row['cueout'] = str_pad(substr($row['cueout'], 0, 10), 10, '.0');
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-08-21 20:08:30 +02:00
|
|
|
//format original length
|
|
|
|
$formatter = new LengthFormatter($row['orig_length']);
|
|
|
|
$row['orig_length'] = $formatter->format();
|
2013-02-05 16:56:38 +01:00
|
|
|
|
|
|
|
// XSS exploit prevention
|
|
|
|
$row["track_title"] = htmlspecialchars($row["track_title"]);
|
|
|
|
$row["creator"] = htmlspecialchars($row["creator"]);
|
2012-07-26 21:30:49 +02:00
|
|
|
}
|
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
return $rows;
|
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02: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.
|
|
|
|
**/
|
|
|
|
public function normalizeFade($fade)
|
|
|
|
{
|
|
|
|
//First get rid of the first six characters 00:00: which will be added back later for db update
|
|
|
|
$fade = substr($fade, 6);
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
//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-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
//done, just need to set back the formated values
|
|
|
|
return $fade;
|
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-08-15 17:36:41 +02:00
|
|
|
public function getUnformatedLength()
|
2012-07-30 23:31:54 +02:00
|
|
|
{
|
2012-08-15 17:36:41 +02:00
|
|
|
$this->block->reload();
|
2012-08-29 16:58:03 +02:00
|
|
|
if ($this->isStatic()) {
|
2012-08-02 17:17:10 +02:00
|
|
|
$length = $this->block->getDbLength();
|
|
|
|
} else {
|
|
|
|
$length = $this->getDynamicBlockLength();
|
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-31 23:46:37 +02:00
|
|
|
return $length;
|
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-08-24 04:27:24 +02:00
|
|
|
public function getLength()
|
2012-08-02 22:36:12 +02:00
|
|
|
{
|
2012-08-15 17:36:41 +02:00
|
|
|
$this->block->reload();
|
2012-08-24 04:27:24 +02:00
|
|
|
$prepend = "";
|
2012-08-29 16:58:03 +02:00
|
|
|
if ($this->isStatic()) {
|
2012-08-24 04:27:24 +02:00
|
|
|
$length = $this->block->getDbLength();
|
2012-08-02 22:36:12 +02:00
|
|
|
} else {
|
|
|
|
$length = $this->getDynamicBlockLength();
|
2012-08-24 04:27:24 +02:00
|
|
|
if (!$this->hasItemLimit()) {
|
2012-08-02 22:36:12 +02:00
|
|
|
$prepend = "~";
|
2012-08-24 04:27:24 +02:00
|
|
|
}
|
2012-08-02 22:36:12 +02:00
|
|
|
}
|
|
|
|
$formatter = new LengthFormatter($length);
|
2012-08-24 04:27:24 +02:00
|
|
|
$length = $prepend.$formatter->format();
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-08-24 04:27:24 +02:00
|
|
|
return $length;
|
2012-08-02 22:36:12 +02:00
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-08-02 17:17:10 +02:00
|
|
|
public function getDynamicBlockLength()
|
|
|
|
{
|
2012-08-02 22:36:12 +02:00
|
|
|
list($value, $modifier) = $this->getLimitValueAndModifier();
|
2012-08-02 17:17:10 +02:00
|
|
|
if ($modifier == "items") {
|
|
|
|
$length = $value." ".$modifier;
|
|
|
|
} else {
|
2012-08-13 17:59:28 +02:00
|
|
|
$hour = "00";
|
2012-10-30 17:36:50 +01:00
|
|
|
$mins = "00";
|
2012-08-02 17:17:10 +02:00
|
|
|
if ($modifier == "minutes") {
|
2012-11-06 17:14:40 +01:00
|
|
|
$mins = $value;
|
2012-08-13 17:42:48 +02:00
|
|
|
if ($value >59) {
|
2012-09-12 17:35:28 +02:00
|
|
|
$hour = intval($value/60);
|
2012-10-30 17:36:50 +01:00
|
|
|
$mins = $value%60;
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-08-13 17:42:48 +02:00
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
} elseif ($modifier == "hours") {
|
2012-08-13 17:59:28 +02:00
|
|
|
$mins = $value * 60;
|
2012-08-24 04:27:24 +02:00
|
|
|
if ($mins >59) {
|
2012-09-12 17:35:28 +02:00
|
|
|
$hour = intval($mins/60);
|
|
|
|
$hour = str_pad($hour, 2, "0", STR_PAD_LEFT);
|
2012-10-18 21:03:59 +02:00
|
|
|
$mins = $mins%60;
|
2012-08-13 17:59:28 +02:00
|
|
|
}
|
2012-08-02 17:17:10 +02:00
|
|
|
}
|
2012-09-12 17:35:28 +02:00
|
|
|
$hour = str_pad($hour, 2, "0", STR_PAD_LEFT);
|
2012-10-18 21:03:59 +02:00
|
|
|
$mins = str_pad($mins, 2, "0", STR_PAD_LEFT);
|
|
|
|
$length = $hour.":".$mins.":00";
|
2012-08-07 20:53:07 +02:00
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-08-02 17:17:10 +02:00
|
|
|
return $length;
|
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-08-02 22:36:12 +02:00
|
|
|
public function getLimitValueAndModifier()
|
|
|
|
{
|
2012-08-24 04:27:24 +02:00
|
|
|
$result = CcBlockcriteriaQuery::create()->filterByDbBlockId($this->id)
|
|
|
|
->filterByDbCriteria('limit')->findOne();
|
|
|
|
$modifier = $result->getDbModifier();
|
2012-09-12 17:35:28 +02:00
|
|
|
$value = $result->getDbValue();
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-08-02 22:36:12 +02:00
|
|
|
return array($value, $modifier);
|
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-08-07 20:53:07 +02:00
|
|
|
// this function returns sum of all track length under this block.
|
2012-08-29 16:58:03 +02:00
|
|
|
public function getStaticLength()
|
|
|
|
{
|
2012-09-12 17:35:28 +02:00
|
|
|
$sql = <<<SQL
|
|
|
|
SELECT SUM(cliplength) AS LENGTH
|
2012-12-03 17:06:56 +01:00
|
|
|
FROM cc_blockcontents as bc
|
|
|
|
JOIN cc_files as f ON bc.file_id = f.id
|
2012-09-12 17:35:28 +02:00
|
|
|
WHERE block_id = :block_id
|
2012-12-03 17:06:56 +01:00
|
|
|
AND f.file_exists = true
|
2012-09-12 17:35:28 +02:00
|
|
|
SQL;
|
2012-09-06 17:11:09 +02:00
|
|
|
$result = Application_Common_Database::prepareAndExecute($sql, array(':block_id'=>$this->id), 'all', PDO::FETCH_NUM);
|
2012-07-31 23:46:37 +02:00
|
|
|
return $result[0][0];
|
2012-07-30 23:31:54 +02:00
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
private function insertBlockElement($info)
|
|
|
|
{
|
|
|
|
$row = new CcBlockcontents();
|
|
|
|
$row->setDbBlockId($this->id);
|
|
|
|
$row->setDbFileId($info["id"]);
|
|
|
|
$row->setDbPosition($info["pos"]);
|
|
|
|
$row->setDbCliplength($info["cliplength"]);
|
|
|
|
$row->setDbCuein($info["cuein"]);
|
|
|
|
$row->setDbCueout($info["cueout"]);
|
2013-01-22 16:39:20 +01:00
|
|
|
$row->setDbFadein(Application_Common_DateHelper::secondsToPlaylistTime($info["fadein"]));
|
|
|
|
$row->setDbFadeout(Application_Common_DateHelper::secondsToPlaylistTime($info["fadeout"]));
|
2012-07-30 23:31:54 +02:00
|
|
|
$row->save($this->con);
|
|
|
|
// above save result update on cc_block table on length column.
|
|
|
|
// but $this->block 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->block = CcBlockQuery::create()->findPK($this->id);
|
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
private function buildEntry($p_item, $pos)
|
|
|
|
{
|
|
|
|
$file = CcFilesQuery::create()->findPK($p_item, $this->con);
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-11-05 16:57:18 +01:00
|
|
|
if (isset($file) && $file->visible()) {
|
2012-09-12 17:35:28 +02:00
|
|
|
$entry = $this->blockItem;
|
|
|
|
$entry["id"] = $file->getDbId();
|
|
|
|
$entry["pos"] = $pos;
|
2013-01-03 20:02:06 +01:00
|
|
|
$entry["cueout"] = $file->getDbCueout();
|
|
|
|
$entry["cuein"] = $file->getDbCuein();
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2013-02-11 18:24:06 +01:00
|
|
|
$cue_out = Application_Common_DateHelper::calculateLengthInSeconds($entry['cueout']);
|
|
|
|
$cue_in = Application_Common_DateHelper::calculateLengthInSeconds($entry['cuein']);
|
2013-02-11 18:37:20 +01:00
|
|
|
$entry["cliplength"] = Application_Common_DateHelper::secondsToPlaylistTime($cue_out-$cue_in);
|
2013-02-11 18:24:06 +01:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
return $entry;
|
|
|
|
} else {
|
|
|
|
throw new Exception("trying to add a file that does not exist.");
|
|
|
|
}
|
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
|
|
|
public function isStatic()
|
|
|
|
{
|
2012-11-05 16:12:03 +01:00
|
|
|
return $this->block->getDbType() == "static";
|
2012-07-30 23:31:54 +02:00
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
/*
|
|
|
|
* @param array $p_items
|
|
|
|
* an array of audioclips to add to the block
|
|
|
|
* @param int|null $p_afterItem
|
|
|
|
* item which to add the new items after in the block, null if added to the end.
|
|
|
|
* @param string (before|after) $addAfter
|
|
|
|
* whether to add the clips before or after the selected item.
|
|
|
|
*/
|
|
|
|
public function addAudioClips($p_items, $p_afterItem=NULL, $addType = 'after')
|
|
|
|
{
|
|
|
|
$this->con->beginTransaction();
|
|
|
|
$contentsToUpdate = array();
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
try {
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
if (is_numeric($p_afterItem)) {
|
2012-08-22 00:41:56 +02:00
|
|
|
Logging::info("Finding block content item {$p_afterItem}");
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
$afterItem = CcBlockcontentsQuery::create()->findPK($p_afterItem);
|
|
|
|
$index = $afterItem->getDbPosition();
|
2012-08-22 00:41:56 +02:00
|
|
|
Logging::info("index is {$index}");
|
2012-07-30 23:31:54 +02:00
|
|
|
$pos = ($addType == 'after') ? $index + 1 : $index;
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
$contentsToUpdate = CcBlockcontentsQuery::create()
|
|
|
|
->filterByDbBlockId($this->id)
|
|
|
|
->filterByDbPosition($pos, Criteria::GREATER_EQUAL)
|
|
|
|
->orderByDbPosition()
|
|
|
|
->find($this->con);
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-08-22 00:41:56 +02:00
|
|
|
Logging::info("Adding to block");
|
|
|
|
Logging::info("at position {$pos}");
|
2012-07-30 23:31:54 +02:00
|
|
|
} else {
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
//add to the end of the block
|
|
|
|
if ($addType == 'after') {
|
|
|
|
$pos = $this->getSize();
|
|
|
|
}
|
|
|
|
//add to the beginning of the block.
|
|
|
|
else {
|
|
|
|
$pos = 0;
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
$contentsToUpdate = CcBlockcontentsQuery::create()
|
|
|
|
->filterByDbBlockId($this->id)
|
|
|
|
->orderByDbPosition()
|
|
|
|
->find($this->con);
|
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
$contentsToUpdate = CcBlockcontentsQuery::create()
|
|
|
|
->filterByDbBlockId($this->id)
|
|
|
|
->filterByDbPosition($pos, Criteria::GREATER_EQUAL)
|
|
|
|
->orderByDbPosition()
|
|
|
|
->find($this->con);
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-08-22 00:41:56 +02:00
|
|
|
Logging::info("Adding to block");
|
|
|
|
Logging::info("at position {$pos}");
|
2012-07-30 23:31:54 +02:00
|
|
|
}
|
2012-11-20 22:38:43 +01:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
foreach ($p_items as $ac) {
|
2012-11-20 22:38:43 +01:00
|
|
|
Logging::info("Adding audio file {$ac[0]}");
|
2012-08-24 23:02:37 +02:00
|
|
|
try {
|
|
|
|
if (is_array($ac) && $ac[1] == 'audioclip') {
|
|
|
|
$res = $this->insertBlockElement($this->buildEntry($ac[0], $pos));
|
2013-02-01 23:47:07 +01:00
|
|
|
|
|
|
|
// update is_playlist flag in cc_files to indicate the
|
|
|
|
// file belongs to a playlist or block (in this case a block)
|
|
|
|
$db_file = CcFilesQuery::create()->findPk($ac[0], $this->con);
|
|
|
|
$db_file->setDbIsPlaylist(true)->save($this->con);
|
|
|
|
|
2012-08-24 23:02:37 +02:00
|
|
|
$pos = $pos + 1;
|
|
|
|
} elseif (!is_array($ac)) {
|
|
|
|
$res = $this->insertBlockElement($this->buildEntry($ac, $pos));
|
|
|
|
$pos = $pos + 1;
|
2013-02-01 23:47:07 +01:00
|
|
|
|
|
|
|
$db_file = CcFilesQuery::create()->findPk($ac, $this->con);
|
|
|
|
$db_file->setDbIsPlaylist(true)->save($this->con);
|
2012-08-24 23:02:37 +02:00
|
|
|
}
|
|
|
|
} catch (Exception $e) {
|
2012-09-04 23:22:21 +02:00
|
|
|
Logging::info($e->getMessage());
|
2012-08-02 17:52:11 +02:00
|
|
|
}
|
2012-07-30 23:31:54 +02:00
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
//reset the positions of the remaining items.
|
|
|
|
for ($i = 0; $i < count($contentsToUpdate); $i++) {
|
|
|
|
$contentsToUpdate[$i]->setDbPosition($pos);
|
|
|
|
$contentsToUpdate[$i]->save($this->con);
|
|
|
|
$pos = $pos + 1;
|
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
$this->block->setDbMtime(new DateTime("now", new DateTimeZone("UTC")));
|
|
|
|
$this->block->save($this->con);
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
$this->con->commit();
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-08-24 17:12:31 +02:00
|
|
|
$this->updateBlockLengthInAllPlaylist();
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
} catch (Exception $e) {
|
|
|
|
$this->con->rollback();
|
|
|
|
throw $e;
|
|
|
|
}
|
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
/**
|
|
|
|
* Move audioClip to the new position in the block
|
|
|
|
*
|
|
|
|
* @param array $p_items
|
|
|
|
* array of unique ids of the selected items
|
|
|
|
* @param int $p_afterItem
|
|
|
|
* unique id of the item to move the clip after
|
|
|
|
*/
|
|
|
|
public function moveAudioClips($p_items, $p_afterItem=NULL)
|
|
|
|
{
|
|
|
|
$this->con->beginTransaction();
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
try {
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
$contentsToMove = CcBlockcontentsQuery::create()
|
|
|
|
->filterByDbId($p_items, Criteria::IN)
|
|
|
|
->orderByDbPosition()
|
|
|
|
->find($this->con);
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
$otherContent = CcBlockcontentsQuery::create()
|
|
|
|
->filterByDbId($p_items, Criteria::NOT_IN)
|
|
|
|
->filterByDbBlockId($this->id)
|
|
|
|
->orderByDbPosition()
|
|
|
|
->find($this->con);
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
$pos = 0;
|
|
|
|
//moving items to beginning of the block.
|
|
|
|
if (is_null($p_afterItem)) {
|
2012-08-22 00:41:56 +02:00
|
|
|
Logging::info("moving items to beginning of block");
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
foreach ($contentsToMove as $item) {
|
2012-08-22 00:41:56 +02:00
|
|
|
Logging::info("item {$item->getDbId()} to pos {$pos}");
|
2012-07-30 23:31:54 +02: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-07-30 23:31:54 +02:00
|
|
|
$item->setDbPosition($pos);
|
|
|
|
$item->save($this->con);
|
|
|
|
$pos = $pos + 1;
|
|
|
|
}
|
|
|
|
} else {
|
2012-08-22 00:41:56 +02:00
|
|
|
Logging::info("moving items after {$p_afterItem}");
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
foreach ($otherContent as $item) {
|
2012-08-22 00:41:56 +02:00
|
|
|
Logging::info("item {$item->getDbId()} to pos {$pos}");
|
2012-07-30 23:31:54 +02:00
|
|
|
$item->setDbPosition($pos);
|
|
|
|
$item->save($this->con);
|
|
|
|
$pos = $pos + 1;
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
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-07-30 23:31:54 +02:00
|
|
|
$move->setDbPosition($pos);
|
|
|
|
$move->save($this->con);
|
|
|
|
$pos = $pos + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
$this->con->commit();
|
|
|
|
} catch (Exception $e) {
|
|
|
|
$this->con->rollback();
|
|
|
|
throw $e;
|
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
$this->block = CcBlockQuery::create()->findPK($this->id);
|
|
|
|
$this->block->setDbMtime(new DateTime("now", new DateTimeZone("UTC")));
|
|
|
|
$this->block->save($this->con);
|
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
/**
|
|
|
|
* Remove audioClip from block
|
|
|
|
*
|
|
|
|
* @param array $p_items
|
|
|
|
* array of unique item ids to remove from the block..
|
|
|
|
*/
|
|
|
|
public function delAudioClips($p_items)
|
|
|
|
{
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
$this->con->beginTransaction();
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
try {
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2013-02-01 23:47:07 +01:00
|
|
|
// we need to get the file id of the item we are deleting
|
|
|
|
// before the item gets deleted from the block
|
|
|
|
$itemsToDelete = CcBlockcontentsQuery::create()
|
|
|
|
->filterByPrimaryKeys($p_items)
|
|
|
|
->filterByDbFileId(null, Criteria::NOT_EQUAL)
|
|
|
|
->find($this->con);
|
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
CcBlockcontentsQuery::create()
|
|
|
|
->findPKs($p_items)
|
|
|
|
->delete($this->con);
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2013-02-01 23:47:07 +01:00
|
|
|
// now that the items have been deleted we can update the
|
|
|
|
// is_playlist flag in cc_files
|
|
|
|
Application_Model_StoredFile::setIsPlaylist($itemsToDelete, 'block', false);
|
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
$contents = CcBlockcontentsQuery::create()
|
|
|
|
->filterByDbBlockId($this->id)
|
|
|
|
->orderByDbPosition()
|
|
|
|
->find($this->con);
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02: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-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
$this->block->setDbMtime(new DateTime("now", new DateTimeZone("UTC")));
|
|
|
|
$this->block->save($this->con);
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
$this->con->commit();
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-08-24 17:12:31 +02:00
|
|
|
$this->updateBlockLengthInAllPlaylist();
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
} catch (Exception $e) {
|
|
|
|
$this->con->rollback();
|
|
|
|
throw $e;
|
|
|
|
}
|
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
public function getFadeInfo($pos)
|
|
|
|
{
|
2012-08-22 00:41:56 +02:00
|
|
|
Logging::info("Getting fade info for pos {$pos}");
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
$row = CcBlockcontentsQuery::create()
|
|
|
|
->joinWith(CcFilesPeer::OM_CLASS)
|
|
|
|
->filterByDbBlockId($this->id)
|
|
|
|
->filterByDbPosition($pos)
|
|
|
|
->findOne();
|
2012-08-29 16:58:03 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2012-10-11 17:49:04 +02:00
|
|
|
//Propel returns values in form 00.000000 format which is for only seconds.
|
|
|
|
//We only want to display 1 decimal
|
|
|
|
$fadeIn = substr($row->getDbFadein(), 0, 4);
|
|
|
|
$fadeOut = substr($row->getDbFadeout(), 0, 4);
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
return array($fadeIn, $fadeOut);
|
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
/**
|
|
|
|
* Change fadeIn and fadeOut values for block Element
|
|
|
|
*
|
|
|
|
* @param int $pos
|
|
|
|
* position of audioclip in block
|
|
|
|
* @param string $fadeIn
|
|
|
|
* new value in ss.ssssss or extent format
|
|
|
|
* @param string $fadeOut
|
|
|
|
* new value in ss.ssssss or extent format
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function changeFadeInfo($id, $fadeIn, $fadeOut)
|
|
|
|
{
|
|
|
|
//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
|
|
|
|
//setting it to nonNull for checks down below
|
|
|
|
$fadeIn = $fadeIn?'00:00:'.$fadeIn:$fadeIn;
|
|
|
|
$fadeOut = $fadeOut?'00:00:'.$fadeOut:$fadeOut;
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
$this->con->beginTransaction();
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
try {
|
|
|
|
$row = CcBlockcontentsQuery::create()->findPK($id);
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
if (is_null($row)) {
|
|
|
|
throw new Exception("Block item does not exist.");
|
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
$clipLength = $row->getDbCliplength();
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
if (!is_null($fadeIn)) {
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-09-04 22:59:33 +02:00
|
|
|
$sql = "SELECT :fade_in::INTERVAL > :clip_length::INTERVAL";
|
2012-09-06 17:11:09 +02:00
|
|
|
$params = array(
|
|
|
|
':fade_in' => $fadeIn,
|
|
|
|
':clip_length' => $clipLength
|
|
|
|
);
|
2012-09-04 22:59:33 +02:00
|
|
|
|
2012-09-06 17:11:09 +02:00
|
|
|
$result = Application_Common_Database::prepareAndExecute($sql, $params, 'column');
|
|
|
|
if ($result) {
|
|
|
|
//"Fade In can't be larger than overall playlength.";
|
|
|
|
$fadeIn = $clipLength;
|
2012-07-30 23:31:54 +02:00
|
|
|
}
|
|
|
|
$row->setDbFadein($fadeIn);
|
2012-09-06 17:11:09 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
}
|
|
|
|
if (!is_null($fadeOut)) {
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-09-04 22:59:33 +02:00
|
|
|
$sql = "SELECT :fade_out::INTERVAL > :clip_length::INTERVAL";
|
2012-09-06 17:11:09 +02:00
|
|
|
$params = array(
|
|
|
|
':fade_out' => $fadeOut,
|
|
|
|
':clip_length' => $clipLength
|
|
|
|
);
|
2012-09-04 22:59:33 +02:00
|
|
|
|
2012-09-06 17:11:09 +02:00
|
|
|
$result = Application_Common_Database::prepareAndExecute($sql, $params, 'column');
|
|
|
|
if ($result) {
|
|
|
|
//"Fade Out can't be larger than overall playlength.";
|
|
|
|
$fadeOut = $clipLength;
|
2012-07-30 23:31:54 +02:00
|
|
|
}
|
|
|
|
$row->setDbFadeout($fadeOut);
|
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
$row->save($this->con);
|
|
|
|
$this->block->setDbMtime(new DateTime("now", new DateTimeZone("UTC")));
|
|
|
|
$this->block->save($this->con);
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
$this->con->commit();
|
|
|
|
} catch (Exception $e) {
|
|
|
|
$this->con->rollback();
|
|
|
|
throw $e;
|
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
return array("fadeIn" => $fadeIn, "fadeOut" => $fadeOut);
|
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-08-16 18:33:25 +02:00
|
|
|
public function setfades($fadein, $fadeout)
|
2012-07-30 23:31:54 +02:00
|
|
|
{
|
|
|
|
if (isset($fadein)) {
|
2012-08-22 00:41:56 +02:00
|
|
|
Logging::info("Setting block fade in {$fadein}");
|
2012-07-30 23:31:54 +02:00
|
|
|
$row = CcBlockcontentsQuery::create()
|
|
|
|
->filterByDbBlockId($this->id)
|
|
|
|
->filterByDbPosition(0)
|
|
|
|
->findOne($this->con);
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
$this->changeFadeInfo($row->getDbId(), $fadein, null);
|
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
if (isset($fadeout)) {
|
2012-08-22 00:41:56 +02:00
|
|
|
Logging::info("Setting block fade out {$fadeout}");
|
2012-07-30 23:31:54 +02:00
|
|
|
$row = CcBlockcontentsQuery::create()
|
|
|
|
->filterByDbBlockId($this->id)
|
|
|
|
->filterByDbPosition($this->getSize()-1)
|
|
|
|
->findOne($this->con);
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
$this->changeFadeInfo($row->getDbId(), null, $fadeout);
|
|
|
|
}
|
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
/**
|
|
|
|
* Change cueIn/cueOut values for block element
|
|
|
|
*
|
|
|
|
* @param int $pos
|
|
|
|
* position of audioclip in block
|
|
|
|
* @param string $cueIn
|
|
|
|
* new value in ss.ssssss or extent format
|
|
|
|
* @param string $cueOut
|
|
|
|
* new value in ss.ssssss or extent format
|
|
|
|
* @return boolean or pear error object
|
|
|
|
*/
|
|
|
|
public function changeClipLength($id, $cueIn, $cueOut)
|
|
|
|
{
|
|
|
|
$this->con->beginTransaction();
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
$errArray= array();
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
try {
|
|
|
|
if (is_null($cueIn) && is_null($cueOut)) {
|
2012-11-15 21:52:51 +01:00
|
|
|
$errArray["error"] = _("Cue in and cue out are null.");
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
return $errArray;
|
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
$row = CcBlockcontentsQuery::create()
|
|
|
|
->joinWith(CcFilesPeer::OM_CLASS)
|
|
|
|
->filterByPrimaryKey($id)
|
|
|
|
->findOne($this->con);
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
if (is_null($row)) {
|
|
|
|
throw new Exception("Block item does not exist.");
|
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-09-12 17:35:28 +02:00
|
|
|
$oldCueIn = $row->getDBCuein();
|
2012-07-30 23:31:54 +02:00
|
|
|
$oldCueOut = $row->getDbCueout();
|
2012-09-12 17:35:28 +02:00
|
|
|
$fadeIn = $row->getDbFadein();
|
|
|
|
$fadeOut = $row->getDbFadeout();
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
$file = $row->getCcFiles($this->con);
|
|
|
|
$origLength = $file->getDbLength();
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
if (!is_null($cueIn) && !is_null($cueOut)) {
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
if ($cueOut === "") {
|
|
|
|
$cueOut = $origLength;
|
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-09-06 17:11:09 +02:00
|
|
|
$sql = "SELECT :cue_out::INTERVAL > :orig_length::INTERVAL";
|
|
|
|
$params = array(
|
|
|
|
':cue_out' => $cueOut,
|
|
|
|
':orig_length' => $origLength
|
|
|
|
);
|
|
|
|
$result = Application_Common_Database::prepareAndExecute($sql, $params, 'column');
|
|
|
|
if ($result) {
|
2012-11-15 21:52:51 +01:00
|
|
|
$errArray["error"] = _("Can't set cue out to be greater than file length.");
|
2012-09-06 17:11:09 +02:00
|
|
|
return $errArray;
|
2012-07-30 23:31:54 +02:00
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-09-06 17:11:09 +02:00
|
|
|
$sql = "SELECT :cue_in::INTERVAL > :cue_out::INTERVAL";
|
|
|
|
$params = array(
|
|
|
|
':cue_in' => $cueIn,
|
|
|
|
':cue_out' => $cueOut
|
|
|
|
);
|
|
|
|
$result = Application_Common_Database::prepareAndExecute($sql, $params, 'column');
|
|
|
|
if ($result) {
|
2012-11-15 21:52:51 +01:00
|
|
|
$errArray["error"] = _("Can't set cue in to be larger than cue out.");
|
2012-09-06 17:11:09 +02:00
|
|
|
return $errArray;
|
2012-07-30 23:31:54 +02:00
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-09-04 22:59:33 +02:00
|
|
|
$sql = "SELECT :cue_out::INTERVAL - :cue_in::INTERVAL";
|
2012-09-06 17:11:09 +02:00
|
|
|
$result = Application_Common_Database::prepareAndExecute($sql, $params, 'column');
|
|
|
|
$cliplength = $result;
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
$row->setDbCuein($cueIn);
|
|
|
|
$row->setDbCueout($cueOut);
|
|
|
|
$row->setDBCliplength($cliplength);
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
} elseif (!is_null($cueIn)) {
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-09-04 22:59:33 +02:00
|
|
|
$sql = "SELECT :cue_in::INTERVAL > :old_cue_out::INTERVAL";
|
2012-09-06 17:11:09 +02:00
|
|
|
$params = array(
|
|
|
|
':cue_in' => $cueIn,
|
|
|
|
':old_cue_out' => $oldCueOut
|
|
|
|
);
|
|
|
|
$result = Application_Common_Database::prepareAndExecute($sql, $params, 'column');
|
|
|
|
if ($result) {
|
2012-11-15 21:52:51 +01:00
|
|
|
$errArray["error"] = _("Can't set cue in to be larger than cue out.");
|
2012-09-06 17:11:09 +02:00
|
|
|
return $errArray;
|
2012-07-30 23:31:54 +02:00
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-09-04 22:59:33 +02:00
|
|
|
$sql = "SELECT :old_cue_out::INTERVAL - :cue_in::INTERVAL";
|
2012-09-06 17:11:09 +02:00
|
|
|
$result = Application_Common_Database::prepareAndExecute($sql, $params, 'column');
|
|
|
|
$cliplength = $result;
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
$row->setDbCuein($cueIn);
|
|
|
|
$row->setDBCliplength($cliplength);
|
2012-09-06 17:11:09 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
} elseif (!is_null($cueOut)) {
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
if ($cueOut === "") {
|
|
|
|
$cueOut = $origLength;
|
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-09-04 22:59:33 +02:00
|
|
|
$sql = "SELECT :cue_out::INTERVAL > :orig_length::INTERVAL";
|
2012-09-06 17:11:09 +02:00
|
|
|
$params = array(
|
|
|
|
':cue_out' => $cueOut,
|
|
|
|
':orig_length' => $origLength
|
|
|
|
);
|
|
|
|
$result = Application_Common_Database::prepareAndExecute($sql, $params, 'column');
|
|
|
|
if ($result) {
|
2012-11-15 21:52:51 +01:00
|
|
|
$errArray["error"] = _("Can't set cue out to be greater than file length.");
|
2012-09-06 17:11:09 +02:00
|
|
|
return $errArray;
|
|
|
|
}
|
2012-09-04 22:59:33 +02:00
|
|
|
|
2012-09-06 17:11:09 +02:00
|
|
|
$sql = "SELECT :cue_out::INTERVAL < :old_cue_in::INTERVAL";
|
|
|
|
$params = array(
|
|
|
|
':cue_out' => $cueOut,
|
|
|
|
':old_cue_in' => $oldCueIn
|
|
|
|
);
|
|
|
|
$result = Application_Common_Database::prepareAndExecute($sql, $params, 'column');
|
|
|
|
if ($result) {
|
2012-11-15 21:52:51 +01:00
|
|
|
$errArray["error"] = _("Can't set cue out to be smaller than cue in.");
|
2012-09-06 17:11:09 +02:00
|
|
|
return $errArray;
|
2012-07-30 23:31:54 +02:00
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-09-04 22:59:33 +02:00
|
|
|
$sql = "SELECT :cue_out::INTERVAL - :old_cue_in::INTERVAL";
|
2012-09-06 17:11:09 +02:00
|
|
|
$result = Application_Common_Database::prepareAndExecute($sql, $params, 'column');
|
|
|
|
$cliplength = $result;
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
$row->setDbCueout($cueOut);
|
|
|
|
$row->setDBCliplength($cliplength);
|
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
$cliplength = $row->getDbCliplength();
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-09-04 22:59:33 +02:00
|
|
|
$sql = "SELECT :fade_in::INTERVAL > :clip_length::INTERVAL";
|
2012-09-06 17:11:09 +02:00
|
|
|
$params = array(
|
|
|
|
':fade_in' => $fadeIn,
|
|
|
|
':clip_length' => $cliplength
|
|
|
|
);
|
|
|
|
$result = Application_Common_Database::prepareAndExecute($sql, $params, 'column');
|
|
|
|
if ($result) {
|
|
|
|
$fadeIn = $cliplength;
|
|
|
|
$row->setDbFadein($fadeIn);
|
2012-07-30 23:31:54 +02:00
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-09-04 22:59:33 +02:00
|
|
|
$sql = "SELECT :fade_out::INTERVAL > :clip_length::INTERVAL";
|
2012-09-06 17:11:09 +02:00
|
|
|
$params = array(
|
|
|
|
':fade_out' => $fadeOut,
|
|
|
|
':clip_length' => $cliplength
|
|
|
|
);
|
|
|
|
$result = Application_Common_Database::prepareAndExecute($sql, $params, 'column');
|
|
|
|
if ($result) {
|
|
|
|
$fadeOut = $cliplength;
|
|
|
|
$row->setDbFadein($fadeOut);
|
2012-07-30 23:31:54 +02:00
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
$row->save($this->con);
|
|
|
|
$this->block->setDbMtime(new DateTime("now", new DateTimeZone("UTC")));
|
|
|
|
$this->block->save($this->con);
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
$this->con->commit();
|
|
|
|
} catch (Exception $e) {
|
|
|
|
$this->con->rollback();
|
|
|
|
throw $e;
|
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-08-15 17:36:41 +02:00
|
|
|
return array("cliplength"=> $cliplength, "cueIn"=> $cueIn, "cueOut"=> $cueOut, "length"=> $this->getUnformatedLength(),
|
2012-07-30 23:31:54 +02:00
|
|
|
"fadeIn"=> $fadeIn, "fadeOut"=> $fadeOut);
|
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
public function getAllPLMetaData()
|
|
|
|
{
|
|
|
|
$categories = $this->categories;
|
|
|
|
$md = array();
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
foreach ($categories as $key => $val) {
|
|
|
|
$method = 'get' . $val;
|
|
|
|
$md[$key] = $this->$method();
|
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
return $md;
|
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
public function getMetaData($category)
|
|
|
|
{
|
|
|
|
$cat = $this->categories[$category];
|
|
|
|
$method = 'get' . $cat;
|
|
|
|
|
|
|
|
return $this->$method();
|
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-08-21 22:54:14 +02:00
|
|
|
public function setMetadata($category, $value)
|
2012-07-30 23:31:54 +02:00
|
|
|
{
|
|
|
|
$cat = $this->categories[$category];
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
$method = 'set' . $cat;
|
|
|
|
$this->$method($value);
|
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
public static function getBlockCount()
|
|
|
|
{
|
|
|
|
$con = Propel::getConnection();
|
2013-01-11 00:09:00 +01:00
|
|
|
$sql = 'SELECT count(*) as cnt FROM cc_playlist';
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
return $con->query($sql)->fetchColumn(0);
|
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
/**
|
|
|
|
* Delete the file from all blocks.
|
|
|
|
* @param string $p_fileId
|
|
|
|
*/
|
|
|
|
public static function DeleteFileFromAllBlocks($p_fileId)
|
|
|
|
{
|
|
|
|
CcBlockcontentsQuery::create()->filterByDbFileId($p_fileId)->delete();
|
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
/**
|
|
|
|
* Delete blocks that match the ids..
|
|
|
|
* @param array $p_ids
|
|
|
|
*/
|
|
|
|
public static function deleteBlocks($p_ids, $p_userId)
|
|
|
|
{
|
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));
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2013-02-01 23:47:07 +01:00
|
|
|
// get only the files from the blocks
|
|
|
|
// we are about to delete
|
|
|
|
$itemsToDelete = CcBlockcontentsQuery::create()
|
|
|
|
->filterByDbBlockId($p_ids)
|
|
|
|
->filterByDbFileId(null, Criteria::NOT_EQUAL)
|
|
|
|
->find();
|
|
|
|
|
|
|
|
$updateIsPlaylistFlag = false;
|
|
|
|
|
2012-08-21 21:42:44 +02:00
|
|
|
if (!$isAdminOrPM) {
|
|
|
|
$leftOver = self::blocksNotOwnedByUser($p_ids, $p_userId);
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-08-21 21:42:44 +02:00
|
|
|
if (count($leftOver) == 0) {
|
|
|
|
CcBlockQuery::create()->findPKs($p_ids)->delete();
|
2013-02-01 23:47:07 +01:00
|
|
|
$updateIsPlaylistFlag = true;
|
2012-08-21 21:42:44 +02:00
|
|
|
} else {
|
|
|
|
throw new BlockNoPermissionException;
|
|
|
|
}
|
2012-07-30 23:31:54 +02:00
|
|
|
} else {
|
2012-08-21 21:42:44 +02:00
|
|
|
CcBlockQuery::create()->findPKs($p_ids)->delete();
|
2013-02-01 23:47:07 +01:00
|
|
|
$updateIsPlaylistFlag = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($updateIsPlaylistFlag) {
|
|
|
|
// update is_playlist flag in cc_files
|
|
|
|
Application_Model_StoredFile::setIsPlaylist(
|
|
|
|
$itemsToDelete,
|
|
|
|
'block',
|
|
|
|
false
|
|
|
|
);
|
2012-07-30 23:31:54 +02:00
|
|
|
}
|
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
// This function returns that are not owen by $p_user_id among $p_ids
|
2012-07-25 18:44:37 +02:00
|
|
|
private static function blocksNotOwnedByUser($p_ids, $p_userId)
|
2012-07-30 23:31:54 +02:00
|
|
|
{
|
|
|
|
$ownedByUser = CcBlockQuery::create()->filterByDbCreatorId($p_userId)->find()->getData();
|
|
|
|
$selectedPls = $p_ids;
|
|
|
|
$ownedPls = array();
|
|
|
|
foreach ($ownedByUser as $pl) {
|
|
|
|
if (in_array($pl->getDbId(), $selectedPls)) {
|
|
|
|
$ownedPls[] = $pl->getDbId();
|
|
|
|
}
|
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
$leftOvers = array_diff($selectedPls, $ownedPls);
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
return $leftOvers;
|
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
/**
|
|
|
|
* Delete all files from block
|
|
|
|
*/
|
|
|
|
public function deleteAllFilesFromBlock()
|
|
|
|
{
|
2013-02-01 23:47:07 +01:00
|
|
|
// get only the files from the playlist
|
|
|
|
// we are about to clear out
|
|
|
|
$itemsToDelete = CcBlockcontentsQuery::create()
|
|
|
|
->filterByDbBlockId($this->id)
|
|
|
|
->filterByDbFileId(null, Criteria::NOT_EQUAL)
|
|
|
|
->find();
|
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
CcBlockcontentsQuery::create()->findByDbBlockId($this->id)->delete();
|
2013-02-01 23:47:07 +01:00
|
|
|
|
|
|
|
// update is_playlist flag in cc_files
|
|
|
|
Application_Model_StoredFile::setIsPlaylist(
|
|
|
|
$itemsToDelete,
|
|
|
|
'block',
|
|
|
|
false
|
|
|
|
);
|
|
|
|
|
2013-01-23 18:09:21 +01:00
|
|
|
//$this->block->reload();
|
|
|
|
$this->block->setDbMtime(new DateTime("now", new DateTimeZone("UTC")));
|
|
|
|
$this->block->save($this->con);
|
|
|
|
$this->con->commit();
|
2012-07-30 23:31:54 +02:00
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
// smart block functions start
|
2012-08-29 16:58:03 +02:00
|
|
|
public function shuffleSmartBlock()
|
|
|
|
{
|
2012-07-30 23:31:54 +02:00
|
|
|
// if it here that means it's static pl
|
|
|
|
$this->saveType("static");
|
|
|
|
$contents = CcBlockcontentsQuery::create()
|
|
|
|
->filterByDbBlockId($this->id)
|
|
|
|
->orderByDbPosition()
|
|
|
|
->find();
|
|
|
|
$shuffledPos = range(0, count($contents)-1);
|
|
|
|
shuffle($shuffledPos);
|
|
|
|
foreach ($contents as $item) {
|
|
|
|
$item->setDbPosition(array_shift($shuffledPos));
|
|
|
|
$item->save();
|
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
return array("result"=>0);
|
2012-07-25 18:44:37 +02:00
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
public function saveType($p_blockType)
|
|
|
|
{
|
|
|
|
// saving dynamic/static flag
|
|
|
|
CcBlockQuery::create()->findPk($this->id)->setDbType($p_blockType)->save();
|
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-08-24 04:27:24 +02:00
|
|
|
public function setLength($value)
|
|
|
|
{
|
|
|
|
$this->block->setDbLength($value);
|
2012-07-31 23:46:37 +02:00
|
|
|
$this->block->save($this->con);
|
2012-08-02 22:36:12 +02:00
|
|
|
$this->updateBlockLengthInAllPlaylist();
|
2012-07-31 23:46:37 +02:00
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
/**
|
|
|
|
* Saves smart block criteria
|
|
|
|
* @param array $p_criteria
|
|
|
|
*/
|
|
|
|
public function saveSmartBlockCriteria($p_criteria)
|
|
|
|
{
|
|
|
|
$data = $this->organizeSmartPlyalistCriteria($p_criteria);
|
|
|
|
// saving dynamic/static flag
|
|
|
|
$blockType = $data['etc']['sp_type'] == 0 ? 'static':'dynamic';
|
|
|
|
$this->saveType($blockType);
|
2012-08-15 17:36:41 +02:00
|
|
|
$this->storeCriteriaIntoDb($data);
|
2012-09-12 23:26:41 +02:00
|
|
|
|
2012-08-15 17:36:41 +02:00
|
|
|
// if the block is dynamic, put null to the length
|
|
|
|
// as it cannot be calculated
|
|
|
|
if ($blockType == 'dynamic') {
|
|
|
|
if ($this->hasItemLimit()) {
|
|
|
|
$this->setLength(null);
|
2012-07-30 23:31:54 +02:00
|
|
|
} else {
|
2012-08-15 17:36:41 +02:00
|
|
|
$this->setLength($this->getDynamicBlockLength());
|
2012-07-30 23:31:54 +02:00
|
|
|
}
|
|
|
|
} else {
|
2012-08-15 17:36:41 +02:00
|
|
|
$length = $this->getStaticLength();
|
|
|
|
if (!$length) {
|
|
|
|
$length = "00:00:00";
|
2012-07-30 23:31:54 +02:00
|
|
|
}
|
2012-08-15 17:36:41 +02:00
|
|
|
$this->setLength($length);
|
2012-07-30 23:31:54 +02:00
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-08-02 22:36:12 +02:00
|
|
|
$this->updateBlockLengthInAllPlaylist();
|
2012-07-30 23:31:54 +02:00
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-08-02 22:36:12 +02:00
|
|
|
public function hasItemLimit()
|
|
|
|
{
|
|
|
|
list($value, $modifier) = $this->getLimitValueAndModifier();
|
2012-09-12 17:35:28 +02:00
|
|
|
return ($modifier == 'items');
|
2012-08-02 22:36:12 +02:00
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-08-24 04:27:24 +02:00
|
|
|
public function storeCriteriaIntoDb($p_criteriaData)
|
|
|
|
{
|
2012-07-30 23:31:54 +02:00
|
|
|
// delete criteria under $p_blockId
|
|
|
|
CcBlockcriteriaQuery::create()->findByDbBlockId($this->id)->delete();
|
2012-09-11 23:18:17 +02:00
|
|
|
//Logging::info($p_criteriaData);
|
2012-07-27 20:32:31 +02:00
|
|
|
//insert modifier rows
|
2012-08-14 15:26:49 +02:00
|
|
|
if (isset($p_criteriaData['criteria'])) {
|
|
|
|
$critKeys = array_keys($p_criteriaData['criteria']);
|
|
|
|
for ($i = 0; $i < count($critKeys); $i++) {
|
2012-08-24 04:27:24 +02:00
|
|
|
foreach ($p_criteriaData['criteria'][$critKeys[$i]] as $d) {
|
2012-08-01 20:07:38 +02:00
|
|
|
$qry = new CcBlockcriteria();
|
|
|
|
$qry->setDbCriteria($d['sp_criteria_field'])
|
|
|
|
->setDbModifier($d['sp_criteria_modifier'])
|
|
|
|
->setDbValue($d['sp_criteria_value'])
|
|
|
|
->setDbBlockId($this->id);
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-08-01 20:07:38 +02:00
|
|
|
if (isset($d['sp_criteria_extra'])) {
|
|
|
|
$qry->setDbExtra($d['sp_criteria_extra']);
|
|
|
|
}
|
|
|
|
$qry->save();
|
2012-07-27 20:32:31 +02:00
|
|
|
}
|
|
|
|
}
|
2012-07-30 23:31:54 +02:00
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
// insert limit info
|
|
|
|
$qry = new CcBlockcriteria();
|
|
|
|
$qry->setDbCriteria("limit")
|
|
|
|
->setDbModifier($p_criteriaData['etc']['sp_limit_options'])
|
|
|
|
->setDbValue($p_criteriaData['etc']['sp_limit_value'])
|
|
|
|
->setDbBlockId($this->id)
|
|
|
|
->save();
|
2012-10-30 22:57:58 +01:00
|
|
|
|
|
|
|
// insert repeate track option
|
|
|
|
$qry = new CcBlockcriteria();
|
|
|
|
$qry->setDbCriteria("repeat_tracks")
|
2012-10-30 23:03:03 +01:00
|
|
|
->setDbModifier("N/A")
|
|
|
|
->setDbValue($p_criteriaData['etc']['sp_repeat_tracks'])
|
|
|
|
->setDbBlockId($this->id)
|
2012-10-30 22:57:58 +01:00
|
|
|
->save();
|
2012-07-30 23:31:54 +02:00
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
/**
|
|
|
|
* generate list of tracks. This function saves creiteria and generate
|
|
|
|
* tracks.
|
|
|
|
* @param array $p_criteria
|
|
|
|
*/
|
|
|
|
public function generateSmartBlock($p_criteria, $returnList=false)
|
|
|
|
{
|
2012-08-16 21:40:36 +02:00
|
|
|
$this->saveSmartBlockCriteria($p_criteria);
|
|
|
|
$insertList = $this->getListOfFilesUnderLimit();
|
|
|
|
$this->deleteAllFilesFromBlock();
|
2012-10-31 17:05:17 +01:00
|
|
|
// constrcut id array
|
|
|
|
$ids = array();
|
|
|
|
foreach ($insertList as $ele) {
|
|
|
|
$ids[] = $ele['id'];
|
|
|
|
}
|
|
|
|
$this->addAudioClips(array_values($ids));
|
2012-08-16 21:40:36 +02:00
|
|
|
// update length in playlist contents.
|
|
|
|
$this->updateBlockLengthInAllPlaylist();
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-08-16 21:40:36 +02:00
|
|
|
return array("result"=>0);
|
2012-07-30 23:31:54 +02:00
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-08-02 22:36:12 +02:00
|
|
|
public function updateBlockLengthInAllPlaylist()
|
|
|
|
{
|
2012-08-24 04:27:24 +02:00
|
|
|
$blocks = CcPlaylistcontentsQuery::create()->filterByDbBlockId($this->id)->find();
|
|
|
|
$blocks->getFirst();
|
|
|
|
$iterator = $blocks->getIterator();
|
2012-08-02 22:36:12 +02:00
|
|
|
while ($iterator->valid()) {
|
2012-08-15 17:36:41 +02:00
|
|
|
$length = $this->getUnformatedLength();
|
2012-08-02 22:36:12 +02:00
|
|
|
if (!preg_match("/^[0-9]{2}:[0-9]{2}:[0-9]{2}/", $length)) {
|
|
|
|
$iterator->current()->setDbClipLength(null);
|
2012-08-24 04:27:24 +02:00
|
|
|
} else {
|
2012-08-02 22:36:12 +02:00
|
|
|
$iterator->current()->setDbClipLength($length);
|
2012-08-24 04:27:24 +02:00
|
|
|
}
|
|
|
|
$iterator->current()->save();
|
|
|
|
$iterator->next();
|
2012-08-02 22:36:12 +02:00
|
|
|
}
|
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
public function getListOfFilesUnderLimit()
|
|
|
|
{
|
2012-09-12 17:35:28 +02:00
|
|
|
$info = $this->getListofFilesMeetCriteria();
|
|
|
|
$files = $info['files'];
|
|
|
|
$limit = $info['limit'];
|
2012-10-30 22:57:58 +01:00
|
|
|
$repeat = $info['repeat_tracks'];
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
$insertList = array();
|
2012-09-12 17:35:28 +02:00
|
|
|
$totalTime = 0;
|
2012-08-08 17:46:48 +02:00
|
|
|
$totalItems = 0;
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
// this moves the pointer to the first element in the collection
|
|
|
|
$files->getFirst();
|
|
|
|
$iterator = $files->getIterator();
|
2012-10-30 22:57:58 +01:00
|
|
|
|
|
|
|
$isBlockFull = false;
|
|
|
|
|
|
|
|
while ($iterator->valid()) {
|
2012-07-30 23:31:54 +02:00
|
|
|
$id = $iterator->current()->getDbId();
|
|
|
|
$length = Application_Common_DateHelper::calculateLengthInSeconds($iterator->current()->getDbLength());
|
2012-10-31 17:05:17 +01:00
|
|
|
$insertList[] = array('id'=>$id, 'length'=>$length);
|
2012-07-30 23:31:54 +02:00
|
|
|
$totalTime += $length;
|
2012-08-08 17:46:48 +02:00
|
|
|
$totalItems++;
|
2012-10-30 22:57:58 +01:00
|
|
|
|
2012-10-30 23:03:03 +01:00
|
|
|
if ((!is_null($limit['items']) && $limit['items'] == count($insertList)) || $totalItems > 500 || $totalTime > $limit['time']) {
|
|
|
|
$isBlockFull = true;
|
|
|
|
break;
|
2012-07-30 23:31:54 +02:00
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
$iterator->next();
|
|
|
|
}
|
2012-10-30 22:57:58 +01:00
|
|
|
|
2012-10-31 17:05:17 +01:00
|
|
|
$sizeOfInsert = count($insertList);
|
|
|
|
|
2012-10-30 22:57:58 +01:00
|
|
|
// if block is not full and reapeat_track is check, fill up more
|
2012-11-06 22:32:00 +01:00
|
|
|
while (!$isBlockFull && $repeat == 1 && $sizeOfInsert > 0) {
|
2012-10-31 17:05:17 +01:00
|
|
|
$randomEleKey = array_rand(array_slice($insertList, 0, $sizeOfInsert));
|
|
|
|
$insertList[] = $insertList[$randomEleKey];
|
|
|
|
$totalTime += $insertList[$randomEleKey]['length'];
|
2012-10-30 22:57:58 +01:00
|
|
|
$totalItems++;
|
|
|
|
|
2012-10-30 23:03:03 +01:00
|
|
|
if ((!is_null($limit['items']) && $limit['items'] == count($insertList)) || $totalItems > 500 || $totalTime > $limit['time']) {
|
|
|
|
break;
|
2012-10-30 22:57:58 +01:00
|
|
|
}
|
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
return $insertList;
|
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-31 00:21:27 +02:00
|
|
|
public function getCriteria()
|
2012-07-29 21:47:42 +02:00
|
|
|
{
|
2012-08-24 04:27:24 +02:00
|
|
|
$criteriaOptions = array(
|
2012-11-15 21:52:51 +01:00
|
|
|
0 => _("Select criteria"),
|
|
|
|
"album_title" => _("Album"),
|
|
|
|
"bit_rate" => _("Bit Rate (Kbps)"),
|
|
|
|
"bpm" => _("BPM"),
|
|
|
|
"composer" => _("Composer"),
|
|
|
|
"conductor" => _("Conductor"),
|
|
|
|
"copyright" => _("Copyright"),
|
2013-02-19 22:38:58 +01:00
|
|
|
"cuein" => _("Cue In"),
|
|
|
|
"cueout" => _("Cue Out"),
|
2012-11-15 21:52:51 +01:00
|
|
|
"artist_name" => _("Creator"),
|
|
|
|
"encoded_by" => _("Encoded By"),
|
|
|
|
"genre" => _("Genre"),
|
|
|
|
"isrc_number" => _("ISRC"),
|
|
|
|
"label" => _("Label"),
|
|
|
|
"language" => _("Language"),
|
|
|
|
"mtime" => _("Last Modified"),
|
|
|
|
"lptime" => _("Last Played"),
|
|
|
|
"length" => _("Length"),
|
|
|
|
"mime" => _("Mime"),
|
|
|
|
"mood" => _("Mood"),
|
|
|
|
"owner_id" => _("Owner"),
|
|
|
|
"replay_gain" => _("Replay Gain"),
|
|
|
|
"sample_rate" => _("Sample Rate (kHz)"),
|
|
|
|
"track_title" => _("Title"),
|
|
|
|
"track_number" => _("Track Number"),
|
|
|
|
"utime" => _("Uploaded"),
|
|
|
|
"info_url" => _("Website"),
|
|
|
|
"year" => _("Year")
|
2012-07-31 00:21:27 +02:00
|
|
|
);
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-29 21:47:42 +02:00
|
|
|
// Load criteria from db
|
2012-07-31 00:21:27 +02:00
|
|
|
$out = CcBlockcriteriaQuery::create()->orderByDbCriteria()->findByDbBlockId($this->id);
|
2012-07-29 21:47:42 +02:00
|
|
|
$storedCrit = array();
|
|
|
|
|
|
|
|
foreach ($out as $crit) {
|
|
|
|
$criteria = $crit->getDbCriteria();
|
|
|
|
$modifier = $crit->getDbModifier();
|
2013-02-05 16:56:38 +01:00
|
|
|
$value = htmlspecialchars($crit->getDbValue());
|
2012-07-29 21:47:42 +02:00
|
|
|
$extra = $crit->getDbExtra();
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-29 21:47:42 +02:00
|
|
|
if ($criteria == "limit") {
|
|
|
|
$storedCrit["limit"] = array("value"=>$value, "modifier"=>$modifier);
|
2012-10-30 22:57:58 +01:00
|
|
|
} else if($criteria == "repeat_tracks") {
|
|
|
|
$storedCrit["repeat_tracks"] = array("value"=>$value);
|
2012-07-29 21:47:42 +02:00
|
|
|
} else {
|
2012-07-31 00:21:27 +02:00
|
|
|
$storedCrit["crit"][$criteria][] = array("criteria"=>$criteria, "value"=>$value, "modifier"=>$modifier, "extra"=>$extra, "display_name"=>$criteriaOptions[$criteria]);
|
2012-07-29 21:47:42 +02:00
|
|
|
}
|
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-29 21:47:42 +02:00
|
|
|
return $storedCrit;
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-29 21:47:42 +02:00
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
// this function return list of propel object
|
|
|
|
public function getListofFilesMeetCriteria()
|
|
|
|
{
|
2012-07-31 00:21:27 +02:00
|
|
|
$storedCrit = $this->getCriteria();
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
$qry = CcFilesQuery::create();
|
2012-09-11 23:18:17 +02:00
|
|
|
$qry->useFkOwnerQuery("subj", "left join");
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
if (isset($storedCrit["crit"])) {
|
2012-07-31 00:21:27 +02:00
|
|
|
foreach ($storedCrit["crit"] as $crit) {
|
2012-08-07 20:53:07 +02:00
|
|
|
$i = 0;
|
2012-07-31 00:21:27 +02:00
|
|
|
foreach ($crit as $criteria) {
|
2012-09-11 23:18:17 +02:00
|
|
|
//$spCriteriaPhpName = self::$criteria2PeerMap[$criteria['criteria']];
|
2012-07-31 00:21:27 +02:00
|
|
|
$spCriteria = $criteria['criteria'];
|
|
|
|
$spCriteriaModifier = $criteria['modifier'];
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-08-13 17:18:15 +02:00
|
|
|
$column = CcFilesPeer::getTableMap()->getColumnByPhpName(self::$criteria2PeerMap[$spCriteria]);
|
2012-08-24 04:27:24 +02:00
|
|
|
// if the column is timestamp, convert it into UTC
|
2012-08-13 17:18:15 +02:00
|
|
|
if ($column->getType() == PropelColumnTypes::TIMESTAMP) {
|
2012-08-21 18:01:48 +02:00
|
|
|
$spCriteriaValue = Application_Common_DateHelper::ConvertToUtcDateTimeString($criteria['value']);
|
2012-08-21 17:58:39 +02:00
|
|
|
/* Check if only a date was supplied and trim
|
|
|
|
* the time after it is converted to UTC time
|
|
|
|
*/
|
|
|
|
if (strlen($criteria['value']) <= 10) {
|
|
|
|
//extract date only from timestamp in db
|
|
|
|
$spCriteria = 'date('.$spCriteria.')';
|
|
|
|
$spCriteriaValue = substr($spCriteriaValue, 0, 10);
|
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-08-27 18:04:04 +02:00
|
|
|
if (isset($criteria['extra'])) {
|
|
|
|
$spCriteriaExtra = Application_Common_DateHelper::ConvertToUtcDateTimeString($criteria['extra']);
|
|
|
|
if (strlen($criteria['extra']) <= 10) {
|
|
|
|
$spCriteriaExtra = substr($spCriteriaExtra, 0, 10);
|
|
|
|
}
|
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
} elseif ($spCriteria == "bit_rate" || $spCriteria == 'sample_rate') {
|
2012-08-13 17:32:06 +02:00
|
|
|
// multiply 1000 because we store only number value
|
|
|
|
// e.g 192kps is stored as 192000
|
|
|
|
$spCriteriaValue = $criteria['value']*1000;
|
2012-08-22 22:29:17 +02:00
|
|
|
if (isset($criteria['extra'])) {
|
2012-08-27 18:04:04 +02:00
|
|
|
$spCriteriaExtra = $criteria['extra']*1000;
|
2012-08-22 22:29:17 +02:00
|
|
|
}
|
2012-08-28 17:22:41 +02:00
|
|
|
/*
|
|
|
|
* If user is searching for an exact match of length we need to
|
|
|
|
* search as if it starts with the specified length because the
|
|
|
|
* user only sees the rounded version (i.e. 4:02.7 is 4:02.761625
|
|
|
|
* in the database)
|
|
|
|
*/
|
2013-02-19 22:38:58 +01:00
|
|
|
} elseif (in_array($spCriteria, array('length', 'cuein', 'cueout')) && $spCriteriaModifier == "is") {
|
2012-08-28 17:22:41 +02:00
|
|
|
$spCriteriaModifier = "starts with";
|
|
|
|
$spCriteria = $spCriteria.'::text';
|
|
|
|
$spCriteriaValue = $criteria['value'];
|
2012-08-13 17:18:15 +02:00
|
|
|
} else {
|
2012-08-24 16:29:28 +02:00
|
|
|
/* Propel does not escape special characters properly when using LIKE/ILIKE
|
|
|
|
* We have to add extra slashes in these cases
|
|
|
|
*/
|
|
|
|
$tempModifier = trim(self::$modifier2CriteriaMap[$spCriteriaModifier]);
|
|
|
|
if ($tempModifier == 'ILIKE') {
|
|
|
|
$spCriteriaValue = addslashes($criteria['value']);
|
|
|
|
// addslashes() does not esapce '%' so we have to do it manually
|
|
|
|
$spCriteriaValue = str_replace('%', '\%', $spCriteriaValue);
|
|
|
|
} else {
|
|
|
|
$spCriteriaValue = ($criteria['value']);
|
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-08-27 18:43:46 +02:00
|
|
|
$spCriteriaExtra = $criteria['extra'];
|
2012-08-13 17:18:15 +02:00
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-31 00:21:27 +02:00
|
|
|
if ($spCriteriaModifier == "starts with") {
|
|
|
|
$spCriteriaValue = "$spCriteriaValue%";
|
2012-08-29 16:58:03 +02:00
|
|
|
} elseif ($spCriteriaModifier == "ends with") {
|
2012-07-31 00:21:27 +02:00
|
|
|
$spCriteriaValue = "%$spCriteriaValue";
|
2012-08-29 16:58:03 +02:00
|
|
|
} elseif ($spCriteriaModifier == "contains" || $spCriteriaModifier == "does not contain") {
|
2012-07-31 00:21:27 +02:00
|
|
|
$spCriteriaValue = "%$spCriteriaValue%";
|
2012-08-29 16:58:03 +02:00
|
|
|
} elseif ($spCriteriaModifier == "is in the range") {
|
2012-08-27 18:04:04 +02:00
|
|
|
$spCriteriaValue = "$spCriteria >= '$spCriteriaValue' AND $spCriteria <= '$spCriteriaExtra'";
|
2012-07-31 00:21:27 +02:00
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-31 00:21:27 +02:00
|
|
|
$spCriteriaModifier = self::$modifier2CriteriaMap[$spCriteriaModifier];
|
2012-08-28 17:22:41 +02:00
|
|
|
|
2012-08-24 03:43:55 +02:00
|
|
|
try {
|
2012-09-11 23:18:17 +02:00
|
|
|
if ($spCriteria == "owner_id") {
|
|
|
|
$spCriteria = "subj.login";
|
|
|
|
}
|
2012-07-31 17:01:19 +02:00
|
|
|
if ($i > 0) {
|
2012-08-15 22:40:04 +02:00
|
|
|
$qry->addOr($spCriteria, $spCriteriaValue, $spCriteriaModifier);
|
2012-07-31 17:01:19 +02:00
|
|
|
} else {
|
2012-08-15 22:40:04 +02:00
|
|
|
$qry->add($spCriteria, $spCriteriaValue, $spCriteriaModifier);
|
2012-07-31 17:01:19 +02:00
|
|
|
}
|
2012-09-18 22:50:42 +02:00
|
|
|
|
|
|
|
if ($spCriteriaModifier == Criteria::NOT_ILIKE || $spCriteriaModifier == Criteria::NOT_EQUAL) {
|
|
|
|
$qry->addOr($spCriteria, null, Criteria::ISNULL);
|
|
|
|
}
|
2012-08-24 03:43:55 +02:00
|
|
|
} catch (Exception $e) {
|
2012-08-22 00:41:56 +02:00
|
|
|
Logging::info($e);
|
2012-07-31 00:21:27 +02:00
|
|
|
}
|
2012-07-31 17:01:19 +02:00
|
|
|
$i++;
|
2012-07-30 23:31:54 +02:00
|
|
|
}
|
|
|
|
}
|
2012-09-13 23:06:44 +02:00
|
|
|
|
|
|
|
// check if file exists
|
2012-09-13 23:05:40 +02:00
|
|
|
$qry->add("file_exists", "true", Criteria::EQUAL);
|
2012-11-05 15:40:58 +01:00
|
|
|
$qry->add("hidden", "false", Criteria::EQUAL);
|
2012-07-31 17:01:19 +02:00
|
|
|
$qry->addAscendingOrderByColumn('random()');
|
2012-07-30 23:31:54 +02:00
|
|
|
}
|
|
|
|
// construct limit restriction
|
|
|
|
$limits = array();
|
2012-10-30 22:57:58 +01:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
if (isset($storedCrit['limit'])) {
|
|
|
|
if ($storedCrit['limit']['modifier'] == "items") {
|
|
|
|
$limits['time'] = 1440 * 60;
|
|
|
|
$limits['items'] = $storedCrit['limit']['value'];
|
|
|
|
} else {
|
2012-08-24 23:02:37 +02:00
|
|
|
$limits['time'] = $storedCrit['limit']['modifier'] == "hours" ?
|
|
|
|
intval(floatval($storedCrit['limit']['value']) * 60 * 60) :
|
2012-08-24 04:27:24 +02:00
|
|
|
intval($storedCrit['limit']['value'] * 60);
|
2012-07-30 23:31:54 +02:00
|
|
|
$limits['items'] = null;
|
|
|
|
}
|
|
|
|
}
|
2012-10-30 22:57:58 +01:00
|
|
|
|
|
|
|
$repeatTracks = 0;
|
|
|
|
if (isset($storedCrit['repeat_tracks'])) {
|
|
|
|
$repeatTracks = $storedCrit['repeat_tracks']['value'];
|
|
|
|
}
|
|
|
|
|
2012-08-24 03:43:55 +02:00
|
|
|
try {
|
2012-07-30 23:31:54 +02:00
|
|
|
$out = $qry->setFormatter(ModelCriteria::FORMAT_ON_DEMAND)->find();
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-10-30 22:57:58 +01:00
|
|
|
return array("files"=>$out, "limit"=>$limits, "repeat_tracks"=> $repeatTracks, "count"=>$out->count());
|
2012-08-24 03:43:55 +02:00
|
|
|
} catch (Exception $e) {
|
2012-08-22 00:41:56 +02:00
|
|
|
Logging::info($e);
|
2012-07-30 23:31:54 +02:00
|
|
|
}
|
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-08-15 17:36:41 +02:00
|
|
|
public static function organizeSmartPlyalistCriteria($p_criteria)
|
2012-07-30 23:31:54 +02:00
|
|
|
{
|
|
|
|
$fieldNames = array('sp_criteria_field', 'sp_criteria_modifier', 'sp_criteria_value', 'sp_criteria_extra');
|
|
|
|
$output = array();
|
2012-07-27 20:32:31 +02:00
|
|
|
foreach ($p_criteria as $ele) {
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-07-27 20:32:31 +02:00
|
|
|
$index = strrpos($ele['name'], '_');
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-08-14 15:26:49 +02:00
|
|
|
/* Strip field name of modifier index
|
|
|
|
* Ex: sp_criteria_field_0_0 -> sp_criteria_field_0
|
|
|
|
*/
|
|
|
|
$fieldName = substr($ele['name'], 0, $index);
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-08-15 17:36:41 +02:00
|
|
|
// Get criteria row index.
|
2012-07-27 20:32:31 +02:00
|
|
|
$tempName = $ele['name'];
|
2012-08-14 16:02:36 +02:00
|
|
|
// Get the last digit in the field name
|
2012-07-27 20:32:31 +02:00
|
|
|
preg_match('/^\D*(?=\d)/', $tempName, $r);
|
2012-08-01 20:07:38 +02:00
|
|
|
if (isset($r[0])) {
|
|
|
|
$critIndexPos = strlen($r[0]);
|
|
|
|
$critIndex = $tempName[$critIndexPos];
|
|
|
|
}
|
2012-08-14 15:26:49 +02:00
|
|
|
$lastChar = substr($ele['name'], -1);
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-08-14 15:26:49 +02:00
|
|
|
// If lastChar is an integer we should strip it off
|
|
|
|
if (!preg_match("/^[a-zA-Z]$/", $lastChar)) {
|
|
|
|
/* Strip field name of criteria index
|
|
|
|
* Ex: sp_criteria_field_0 -> sp_criteria_field
|
|
|
|
* We do this to check if the field name is a criteria
|
|
|
|
* or the block type
|
|
|
|
*/
|
|
|
|
$n = strrpos($fieldName, '_');
|
|
|
|
$fieldName = substr($fieldName, 0, $n);
|
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-08-14 15:26:49 +02:00
|
|
|
if (in_array($fieldName, $fieldNames)) {
|
|
|
|
$output['criteria'][$critIndex][$lastChar][$fieldName] = trim($ele['value']);
|
2012-08-29 16:58:03 +02:00
|
|
|
} else {
|
2012-08-14 15:26:49 +02:00
|
|
|
$output['etc'][$ele['name']] = $ele['value'];
|
2012-07-30 23:31:54 +02:00
|
|
|
}
|
|
|
|
}
|
2012-10-30 22:57:58 +01:00
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
return $output;
|
|
|
|
}
|
2013-02-01 23:47:07 +01:00
|
|
|
public static function getAllBlockFiles()
|
2013-01-30 16:55:24 +01:00
|
|
|
{
|
|
|
|
$con = Propel::getConnection();
|
|
|
|
$sql = <<<SQL
|
|
|
|
SELECT distinct(file_id)
|
|
|
|
FROM cc_blockcontents
|
|
|
|
SQL;
|
|
|
|
$files = $con->query($sql)->fetchAll();
|
|
|
|
$real_files = array();
|
|
|
|
foreach ($files as $f) {
|
|
|
|
$real_files[] = $f['file_id'];
|
|
|
|
}
|
|
|
|
return $real_files;
|
|
|
|
}
|
2012-07-25 18:44:37 +02:00
|
|
|
// smart block functions end
|
|
|
|
}
|
|
|
|
|
2012-07-30 23:31:54 +02:00
|
|
|
class BlockNotFoundException extends Exception {}
|
|
|
|
class BlockNoPermissionException extends Exception {}
|
|
|
|
class BlockOutDatedException extends Exception {}
|
|
|
|
class BlockDyanmicException extends Exception {}
|