CC-84: Smart Playlists

- dynamic block length display
This commit is contained in:
James 2012-08-02 11:17:10 -04:00
parent f99574b723
commit 6e71a6bb92
4 changed files with 37 additions and 6 deletions

View File

@ -245,11 +245,35 @@ EOT;
// function return "N/A" if dynamic
public function getLength()
{
$length = $this->block->getDbLength();
if ($this->isStatic()){
$length = $this->block->getDbLength();
} else {
$length = $this->getDynamicBlockLength();
}
$length = $length == null ? "N/A" : $length;
return $length;
}
public function getDynamicBlockLength()
{
$result = CcBlockcriteriaQuery::create()->filterByDbBlockId($this->id)
->filterByDbCriteria('limit')->findOne();
$modifier = $result->getDbModifier();
$value = $result->getDbValue();
if ($modifier == "items") {
$length = $value." ".$modifier;
} else {
if ($modifier == "minutes") {
$timestamp = "00:".$value.":00";
} else if ($modifier == "hours") {
$timestamp = $value."00:00";
}
$formatter = new LengthFormatter($timestamp);
$length = "~".$formatter->format();
}
return $length;
}
//
public function getStaticLength(){
$sql = "SELECT SUM(cliplength) as length FROM cc_blockcontents WHERE block_id={$this->id}";
@ -1033,7 +1057,7 @@ EOT;
// as it cannot be calculated
if ($blockType == 'dynamic') {
$this->setLength(null);
$output['blockLength'] = "N/A";
$output['blockLength'] = $this->getDynamicBlockLength();
} else {
$length = $this->getStaticLength();
$this->setLength($length);

View File

@ -93,6 +93,9 @@ class Application_Model_Datatables
if ($r['ftype'] == 'playlist') {
$pl = new Application_Model_Playlist($r['id']);
$r['length'] = $pl->getLength();
} else if ($r['ftype'] == "block") {
$bl = new Application_Model_Block($r['id']);
$r['length'] = $bl->getLength();
}
}
} catch (Exception $e) {

View File

@ -196,7 +196,12 @@ EOT;
$offset_cliplength = Application_Common_DateHelper::secondsToPlaylistTime($offset);
//format the length for UI.
$formatter = new LengthFormatter($row['length']);
if ($row['type'] == 2){
$bl = new Application_Model_Block($row['item_id']);
$formatter = new LengthFormatter($bl->getLength());
} else {
$formatter = new LengthFormatter($row['length']);
}
$row['length'] = $formatter->format();
$formatter = new LengthFormatter($offset_cliplength);
@ -268,7 +273,6 @@ EOT;
//aggregate column on playlistcontents cliplength column.
public function getLength()
{
Logging::log($this->hasDynamicBlockOrWebStream());
if ($this->hasDynamicBlockOrWebStream()){
return "N/A";
} else {

View File

@ -16,8 +16,8 @@ class LengthFormatter {
}
public function format() {
if ($this->_length == "N/A" || $this->_length == "") {
return "N/A";
if (!preg_match("/^[0-9]{2}:[0-9]{2}:[0-9]{2}/", $this->_length)) {
return $this->_length;
}
$pieces = explode(":", $this->_length);