refactor time remaining smartblock to work with playlists

This commit is contained in:
Robbt 2019-04-22 15:26:09 -04:00
parent 2af54d0b64
commit 32d3c0578b
2 changed files with 29 additions and 10 deletions

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.