Merge pull request #802 from Robbt/fix-playlist-smartblock-remaining

Fix playlist smartblock remaining
This commit is contained in:
Kyle Robbertze 2019-04-22 22:43:02 +02:00 committed by GitHub
commit 162c509ecd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 11 deletions

View File

@ -83,8 +83,8 @@ $ccAcl->allow('G', 'index')
->allow('H', 'library')
->allow('H', 'playlist')
->allow('H', 'playouthistory')
->allow('H', 'listenerstat')
->allow('A', 'playouthistorytemplate')
->allow('A', 'listenerstat')
->allow('A', 'user')
->allow('A', 'systemstatus')
->allow('A', 'preference')

View File

@ -1622,7 +1622,7 @@ SQL;
// this function return list of propel object
public function getListofFilesMeetCriteria($show = null)
public function getListofFilesMeetCriteria($showLimit = null)
{
$storedCrit = $this->getCriteria();
@ -1782,9 +1782,8 @@ SQL;
$limits['items'] = $storedCrit['limit']['value'];
} elseif (($storedCrit['limit']['modifier'] == "remaining") ){
// show will be null unless being called inside a show instance
if (!(is_null($show))) {
$showInstance = new Application_Model_ShowInstance($show);
$limits['time'] = $showInstance->getSecondsRemaining();
if (!(is_null($showLimit))) {
$limits['time'] = $showLimit;
$limits['items'] = null;
}
else {
@ -1813,7 +1812,6 @@ SQL;
try {
$out = $qry->setFormatter(ModelCriteria::FORMAT_ON_DEMAND)->find();
Logging::info($qry->toString());
return array("files"=>$out, "limit"=>$limits, "repeat_tracks"=> $repeatTracks, "overflow_tracks"=> $overflowTracks, "count"=>$out->count());
} catch (Exception $e) {
@ -1823,7 +1821,6 @@ SQL;
}
public static function organizeSmartPlaylistCriteria($p_criteria)
{
Logging::info($p_criteria);
$fieldNames = array('sp_criteria_field', 'sp_criteria_modifier', 'sp_criteria_value', 'sp_criteria_extra', 'sp_criteria_datetime_select', 'sp_criteria_extra_datetime_select');
$output = array();
foreach ($p_criteria as $ele) {
@ -1862,7 +1859,6 @@ SQL;
$output['etc'][$ele['name']] = $ele['value'];
}
}
Logging::info($output);
return $output;
}
public static function getAllBlockFiles()

View File

@ -213,6 +213,10 @@ final class Application_Model_Scheduler
*/
private function retrieveMediaFiles($id, $type, $show)
{
// if there is a show we need to set a show limit to pass to smart blocks in case they use time remaining
$showInstance = new Application_Model_ShowInstance($show);
$showLimit = $showInstance->getSecondsRemaining();
$files = array();
if ($type === "audioclip") {
$file = CcFilesQuery::create()->findPK($id, $this->con);
@ -241,7 +245,8 @@ final class Application_Model_Scheduler
} elseif ($type === "playlist") {
$pl = new Application_Model_Playlist($id);
$contents = $pl->getContents();
// because the time remaining is not updated until after the schedule inserts we need to track it for
// the entire add vs. querying on the smartblock level
foreach ($contents as $plItem) {
if ($plItem['type'] == 0) {
$data["id"] = $plItem['item_id'];
@ -278,7 +283,7 @@ final class Application_Model_Scheduler
} else {
$defaultFadeIn = Application_Model_Preference::GetDefaultFadeIn();
$defaultFadeOut = Application_Model_Preference::GetDefaultFadeOut();
$dynamicFiles = $bl->getListOfFilesUnderLimit($show);
$dynamicFiles = $bl->getListOfFilesUnderLimit($showLimit);
foreach ($dynamicFiles as $f) {
$fileId = $f['id'];
$file = CcFilesQuery::create()->findPk($fileId);
@ -301,6 +306,9 @@ final class Application_Model_Scheduler
}
}
}
// if this is a playlist it might contain multiple time remaining smart blocks
// since the schedule isn't updated until after this insert we need to keep tally
$showLimit -= $this->timeLengthOfFiles($files);
}
} elseif ($type == "stream") {
//need to return
@ -337,7 +345,7 @@ final class Application_Model_Scheduler
} else {
$defaultFadeIn = Application_Model_Preference::GetDefaultFadeIn();
$defaultFadeOut = Application_Model_Preference::GetDefaultFadeOut();
$dynamicFiles = $bl->getListOfFilesUnderLimit($show);
$dynamicFiles = $bl->getListOfFilesUnderLimit($showLimit);
foreach ($dynamicFiles as $f) {
$fileId = $f['id'];
$file = CcFilesQuery::create()->findPk($fileId);
@ -993,6 +1001,7 @@ final class Application_Model_Scheduler
$this->calculateCrossfades($instanceId);
}
}//for each instance
}//for each schedule location
$endProfile = microtime(true);
@ -1294,6 +1303,20 @@ final class Application_Model_Scheduler
throw $e;
}
}
/*
* This is used to determine the duration of a files array
*
*
*/
public function timeLengthOfFiles($files) {
$timeLength = 0;
foreach ($files as $file) {
$timeLength += Application_Common_DateHelper::playlistTimeToSeconds($file['cliplength']);
$timeLength += $file['fadein'];
$timeLength += $file['fadeout'];
}
return $timeLength;
}
/*
* Used for cancelling the current show instance.