CC-4639: Give an option to allow smart blocks to reuse tracks if not enough tracks meet the time limit.
- done
This commit is contained in:
parent
00947f9d7e
commit
9d495ebc03
6 changed files with 99 additions and 10 deletions
|
@ -1093,6 +1093,14 @@ SQL;
|
|||
->setDbValue($p_criteriaData['etc']['sp_limit_value'])
|
||||
->setDbBlockId($this->id)
|
||||
->save();
|
||||
|
||||
// insert repeate track option
|
||||
$qry = new CcBlockcriteria();
|
||||
$qry->setDbCriteria("repeat_tracks")
|
||||
->setDbModifier("N/A")
|
||||
->setDbValue($p_criteriaData['etc']['sp_repeat_tracks'])
|
||||
->setDbBlockId($this->id)
|
||||
->save();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1105,7 +1113,7 @@ SQL;
|
|||
$this->saveSmartBlockCriteria($p_criteria);
|
||||
$insertList = $this->getListOfFilesUnderLimit();
|
||||
$this->deleteAllFilesFromBlock();
|
||||
$this->addAudioClips(array_keys($insertList));
|
||||
$this->addAudioClips(array_values($insertList));
|
||||
// update length in playlist contents.
|
||||
$this->updateBlockLengthInAllPlaylist();
|
||||
|
||||
|
@ -1134,6 +1142,7 @@ SQL;
|
|||
$info = $this->getListofFilesMeetCriteria();
|
||||
$files = $info['files'];
|
||||
$limit = $info['limit'];
|
||||
$repeat = $info['repeat_tracks'];
|
||||
|
||||
$insertList = array();
|
||||
$totalTime = 0;
|
||||
|
@ -1142,19 +1151,45 @@ SQL;
|
|||
// this moves the pointer to the first element in the collection
|
||||
$files->getFirst();
|
||||
$iterator = $files->getIterator();
|
||||
while ($iterator->valid() && $totalTime < $limit['time']) {
|
||||
|
||||
$isBlockFull = false;
|
||||
|
||||
while ($iterator->valid()) {
|
||||
$id = $iterator->current()->getDbId();
|
||||
$length = Application_Common_DateHelper::calculateLengthInSeconds($iterator->current()->getDbLength());
|
||||
$insertList[$id] = $length;
|
||||
$insertList[] = $id;
|
||||
$totalTime += $length;
|
||||
$totalItems++;
|
||||
|
||||
if ((!is_null($limit['items']) && $limit['items'] == count($insertList)) || $totalItems > 500) {
|
||||
break;
|
||||
|
||||
if ((!is_null($limit['items']) && $limit['items'] == count($insertList)) || $totalItems > 500 || $totalTime > $limit['time']) {
|
||||
$isBlockFull = true;
|
||||
break;
|
||||
}
|
||||
|
||||
$iterator->next();
|
||||
}
|
||||
|
||||
// if block is not full and reapeat_track is check, fill up more
|
||||
while (!$isBlockFull && $repeat == 1) {
|
||||
if (!$iterator->valid()) {
|
||||
$iterator->closeCursor();
|
||||
$info = $this->getListofFilesMeetCriteria();
|
||||
$files = $info['files'];
|
||||
$files->getFirst();
|
||||
$iterator = $files->getIterator();
|
||||
}
|
||||
$id = $iterator->current()->getDbId();
|
||||
$length = Application_Common_DateHelper::calculateLengthInSeconds($iterator->current()->getDbLength());
|
||||
$insertList[] = $id;
|
||||
$totalTime += $length;
|
||||
$totalItems++;
|
||||
|
||||
if ((!is_null($limit['items']) && $limit['items'] == count($insertList)) || $totalItems > 500 || $totalTime > $limit['time']) {
|
||||
break;
|
||||
}
|
||||
|
||||
$iterator->next();
|
||||
}
|
||||
|
||||
return $insertList;
|
||||
}
|
||||
|
@ -1202,6 +1237,8 @@ SQL;
|
|||
|
||||
if ($criteria == "limit") {
|
||||
$storedCrit["limit"] = array("value"=>$value, "modifier"=>$modifier);
|
||||
} else if($criteria == "repeat_tracks") {
|
||||
$storedCrit["repeat_tracks"] = array("value"=>$value);
|
||||
} else {
|
||||
$storedCrit["crit"][$criteria][] = array("criteria"=>$criteria, "value"=>$value, "modifier"=>$modifier, "extra"=>$extra, "display_name"=>$criteriaOptions[$criteria]);
|
||||
}
|
||||
|
@ -1317,6 +1354,7 @@ SQL;
|
|||
}
|
||||
// construct limit restriction
|
||||
$limits = array();
|
||||
|
||||
if (isset($storedCrit['limit'])) {
|
||||
if ($storedCrit['limit']['modifier'] == "items") {
|
||||
$limits['time'] = 1440 * 60;
|
||||
|
@ -1328,10 +1366,16 @@ SQL;
|
|||
$limits['items'] = null;
|
||||
}
|
||||
}
|
||||
|
||||
$repeatTracks = 0;
|
||||
if (isset($storedCrit['repeat_tracks'])) {
|
||||
$repeatTracks = $storedCrit['repeat_tracks']['value'];
|
||||
}
|
||||
|
||||
try {
|
||||
$out = $qry->setFormatter(ModelCriteria::FORMAT_ON_DEMAND)->find();
|
||||
|
||||
return array("files"=>$out, "limit"=>$limits, "count"=>$out->count());
|
||||
return array("files"=>$out, "limit"=>$limits, "repeat_tracks"=> $repeatTracks, "count"=>$out->count());
|
||||
} catch (Exception $e) {
|
||||
Logging::info($e);
|
||||
}
|
||||
|
@ -1377,7 +1421,7 @@ SQL;
|
|||
$output['etc'][$ele['name']] = $ele['value'];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $output;
|
||||
}
|
||||
// smart block functions end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue