CC-84: Smart Playlists
- audio preview on playlist - cleaning up some code
This commit is contained in:
parent
3b5a3e6713
commit
0d2d8218bf
14 changed files with 202 additions and 72 deletions
|
@ -250,30 +250,50 @@ EOT;
|
|||
} else {
|
||||
$length = $this->getDynamicBlockLength();
|
||||
}
|
||||
$length = $length == null ? "N/A" : $length;
|
||||
return $length;
|
||||
}
|
||||
|
||||
public function getFormattedLength()
|
||||
{
|
||||
$prepend = "";
|
||||
if ($this->isStatic()){
|
||||
$length = $this->block->getDbLength();
|
||||
} else {
|
||||
$length = $this->getDynamicBlockLength();
|
||||
if (!$this->hasItemLimit()) {
|
||||
$prepend = "~";
|
||||
}
|
||||
}
|
||||
$formatter = new LengthFormatter($length);
|
||||
$length = $prepend.$formatter->format();
|
||||
return $length;
|
||||
}
|
||||
|
||||
public function getDynamicBlockLength()
|
||||
{
|
||||
$result = CcBlockcriteriaQuery::create()->filterByDbBlockId($this->id)
|
||||
->filterByDbCriteria('limit')->findOne();
|
||||
$modifier = $result->getDbModifier();
|
||||
$value = $result->getDbValue();
|
||||
list($value, $modifier) = $this->getLimitValueAndModifier();
|
||||
if ($modifier == "items") {
|
||||
$length = $value." ".$modifier;
|
||||
} else {
|
||||
$value = str_pad($value, 2, "0", STR_PAD_LEFT);
|
||||
if ($modifier == "minutes") {
|
||||
$timestamp = "00:".$value.":00";
|
||||
$length = "00:".$value.":00";
|
||||
} else if ($modifier == "hours") {
|
||||
$timestamp = $value."00:00";
|
||||
$length = $value."00:00";
|
||||
}
|
||||
$formatter = new LengthFormatter($timestamp);
|
||||
$length = "~".$formatter->format();
|
||||
}
|
||||
return $length;
|
||||
}
|
||||
|
||||
public function getLimitValueAndModifier()
|
||||
{
|
||||
$result = CcBlockcriteriaQuery::create()->filterByDbBlockId($this->id)
|
||||
->filterByDbCriteria('limit')->findOne();
|
||||
$modifier = $result->getDbModifier();
|
||||
$value = $result->getDbValue();
|
||||
return array($value, $modifier);
|
||||
}
|
||||
|
||||
//
|
||||
public function getStaticLength(){
|
||||
$sql = "SELECT SUM(cliplength) as length FROM cc_blockcontents WHERE block_id={$this->id}";
|
||||
|
@ -886,6 +906,7 @@ EOT;
|
|||
public function setLength($value){
|
||||
$this->block->setDbLength($value);
|
||||
$this->block->save($this->con);
|
||||
$this->updateBlockLengthInAllPlaylist();
|
||||
}
|
||||
|
||||
|
||||
|
@ -1056,18 +1077,31 @@ EOT;
|
|||
// if the block is dynamic, put null to the length
|
||||
// as it cannot be calculated
|
||||
if ($blockType == 'dynamic') {
|
||||
$this->setLength(null);
|
||||
$output['blockLength'] = $this->getDynamicBlockLength();
|
||||
if ($this->hasItemLimit()) {
|
||||
$this->setLength(null);
|
||||
} else {
|
||||
$this->setLength($this->getDynamicBlockLength());
|
||||
}
|
||||
} else {
|
||||
$length = $this->getStaticLength();
|
||||
$this->setLength($length);
|
||||
$formatter = new LengthFormatter($length);
|
||||
$output['blockLength'] = $formatter->format();
|
||||
}
|
||||
$output['blockLength'] = $this->getFormattedLength();
|
||||
}
|
||||
$this->updateBlockLengthInAllPlaylist();
|
||||
return $output;
|
||||
}
|
||||
|
||||
public function hasItemLimit()
|
||||
{
|
||||
list($value, $modifier) = $this->getLimitValueAndModifier();
|
||||
if ($modifier == 'items') {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function storeCriteriaIntoDb($p_criteriaData){
|
||||
// delete criteria under $p_blockId
|
||||
CcBlockcriteriaQuery::create()->findByDbBlockId($this->id)->delete();
|
||||
|
@ -1128,18 +1162,28 @@ EOT;
|
|||
$this->deleteAllFilesFromBlock();
|
||||
$this->addAudioClips(array_keys($insertList));
|
||||
// update length in playlist contents.
|
||||
$blocks = CcPlaylistcontentsQuery::create()->filterByDbBlockId($this->id)->find();
|
||||
$blocks->getFirst();
|
||||
$iterator = $blocks->getIterator();
|
||||
while ($iterator->valid()) {
|
||||
$iterator->current()->setDbClipLength($this->getLength());
|
||||
$iterator->current()->save();
|
||||
$iterator->next();
|
||||
}
|
||||
$this->updateBlockLengthInAllPlaylist();
|
||||
return array("result"=>0);
|
||||
}
|
||||
}
|
||||
|
||||
public function updateBlockLengthInAllPlaylist()
|
||||
{
|
||||
$blocks = CcPlaylistcontentsQuery::create()->filterByDbBlockId($this->id)->find();
|
||||
$blocks->getFirst();
|
||||
$iterator = $blocks->getIterator();
|
||||
while ($iterator->valid()) {
|
||||
$length = $this->getLength();
|
||||
if (!preg_match("/^[0-9]{2}:[0-9]{2}:[0-9]{2}/", $length)) {
|
||||
$iterator->current()->setDbClipLength(null);
|
||||
} else {
|
||||
$iterator->current()->setDbClipLength($length);
|
||||
}
|
||||
$iterator->current()->save();
|
||||
$iterator->next();
|
||||
}
|
||||
}
|
||||
|
||||
public function getListOfFilesUnderLimit()
|
||||
{
|
||||
$info = $this->getListofFilesMeetCriteria();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue