CC-84: Smart Playlists
- Length calculation for dynamic blocks and playlist that contains dynamic blocks
This commit is contained in:
parent
1b0cd6b01b
commit
9d51222dae
|
@ -199,7 +199,6 @@ class PlaylistController extends Zend_Controller_Action
|
|||
$this->view->form = $form;
|
||||
}
|
||||
}
|
||||
|
||||
$formatter = new LengthFormatter($obj->getLength());
|
||||
$this->view->length = $formatter->format();
|
||||
$this->view->type = $this->obj_sess->type;
|
||||
|
|
|
@ -242,10 +242,20 @@ EOT;
|
|||
return $fade;
|
||||
}
|
||||
|
||||
//aggregate column on blockcontents cliplength column.
|
||||
// function return "N/A" if dynamic
|
||||
public function getLength()
|
||||
{
|
||||
return $this->block->getDbLength();
|
||||
$length = $this->block->getDbLength();
|
||||
$length = $length == null ? "N/A" : $length;
|
||||
return $length;
|
||||
}
|
||||
|
||||
//
|
||||
public function getStaticLength(){
|
||||
$sql = "SELECT SUM(cliplength) as length FROM cc_blockcontents WHERE block_id={$this->id}";
|
||||
$r = $this->con->query($sql);
|
||||
$result = $r->fetchAll(PDO::FETCH_NUM);
|
||||
return $result[0][0];
|
||||
}
|
||||
|
||||
private function insertBlockElement($info)
|
||||
|
@ -849,6 +859,12 @@ EOT;
|
|||
CcBlockQuery::create()->findPk($this->id)->setDbType($p_blockType)->save();
|
||||
}
|
||||
|
||||
public function setLength($value){
|
||||
$this->block->setDbLength($value);
|
||||
$this->block->save($this->con);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Saves smart block criteria
|
||||
* @param array $p_criteria
|
||||
|
@ -1004,14 +1020,26 @@ EOT;
|
|||
}//for loop
|
||||
|
||||
$result = count($errors) > 0 ? 1 :0;
|
||||
$files["count"] = 0;
|
||||
$output = array("result"=>$result, "errors"=>$errors);
|
||||
if ($result == 0) {
|
||||
$this->storeCriteriaIntoDb($data);
|
||||
//get number of files that meet the criteria
|
||||
$files = $this->getListofFilesMeetCriteria();
|
||||
$output['poolCount'] = $files["count"];
|
||||
// if the block is dynamic, put null to the length
|
||||
// as it cannot be calculated
|
||||
if ($blockType == 'dynamic') {
|
||||
$this->setLength(null);
|
||||
$output['blockLength'] = "N/A";
|
||||
} else {
|
||||
$length = $this->getStaticLength();
|
||||
$this->setLength($length);
|
||||
$formatter = new LengthFormatter($length);
|
||||
$output['blockLength'] = $formatter->format();
|
||||
}
|
||||
}
|
||||
|
||||
//get number of files that meet the criteria
|
||||
$files = $this->getListofFilesMeetCriteria();
|
||||
|
||||
return array("result"=>$result, "errors"=>$errors, "poolCount"=>$files["count"]);
|
||||
return $output;
|
||||
}
|
||||
|
||||
public function storeCriteriaIntoDb($p_criteriaData){
|
||||
|
@ -1071,6 +1099,15 @@ EOT;
|
|||
$insertList = $this->getListOfFilesUnderLimit();
|
||||
$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();
|
||||
}
|
||||
return array("result"=>0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -87,6 +87,14 @@ class Application_Model_Datatables
|
|||
$r = $con->query($sql);
|
||||
$r->setFetchMode(PDO::FETCH_ASSOC);
|
||||
$results = $r->fetchAll();
|
||||
// we need to go over all items and fix length for playlist
|
||||
// in case the playlist contains dynamic block
|
||||
foreach ($results as &$r) {
|
||||
if ($r['ftype'] == 'playlist') {
|
||||
$pl = new Application_Model_Playlist($r['id']);
|
||||
$r['length'] = $pl->getLength();
|
||||
}
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
Logging::debug($e->getMessage());
|
||||
}
|
||||
|
|
|
@ -137,7 +137,6 @@ class Application_Model_Playlist
|
|||
{
|
||||
//Logging::log($this->pl->getDbMtime($format));
|
||||
//Logging::log($this->pl);
|
||||
Logging::log("5555");
|
||||
return $this->pl->getDbMtime($format);
|
||||
}
|
||||
|
||||
|
@ -252,11 +251,29 @@ EOT;
|
|||
//done, just need to set back the formated values
|
||||
return $fade;
|
||||
}
|
||||
|
||||
public function hasDynamicBlockOrWebStream(){
|
||||
$sql = "SELECT count(*) as count FROM cc_playlistcontents as pc
|
||||
JOIN cc_block as bl ON pc.type=2 AND pc.block_id=bl.id AND bl.type='dynamic'
|
||||
WHERE playlist_id={$this->id} AND (pc.type=2 OR pc.type=1)";
|
||||
$r = $this->con->query($sql);
|
||||
$result = $r->fetchAll(PDO::FETCH_NUM);
|
||||
if (intval($result[0][0]) > 0) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//aggregate column on playlistcontents cliplength column.
|
||||
public function getLength()
|
||||
{
|
||||
return $this->pl->getDbLength();
|
||||
Logging::log($this->hasDynamicBlockOrWebStream());
|
||||
if ($this->hasDynamicBlockOrWebStream()){
|
||||
return "N/A";
|
||||
} else {
|
||||
return $this->pl->getDbLength();
|
||||
}
|
||||
}
|
||||
|
||||
private function insertPlaylistElement($info)
|
||||
|
|
|
@ -16,6 +16,9 @@ class LengthFormatter {
|
|||
}
|
||||
|
||||
public function format() {
|
||||
if ($this->_length == "N/A" || $this->_length == "") {
|
||||
return "N/A";
|
||||
}
|
||||
|
||||
$pieces = explode(":", $this->_length);
|
||||
|
||||
|
|
|
@ -478,6 +478,10 @@ function callback(data, type) {
|
|||
$('#sp_pool_count_icon').removeClass('checked-icon sp-checked-icon').addClass('sp-warning-icon');
|
||||
}
|
||||
}
|
||||
//redraw library table so the length gets updated
|
||||
var dt = $('table[id="library_display"]').dataTable();
|
||||
dt.fnStandingRedraw();
|
||||
$('div[class="playlist_title"]').find("h4").html(json.blockLength);
|
||||
}
|
||||
setTimeout('removeSuccessMsg()', 5000);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue