diff --git a/airtime_mvc/application/forms/SmartBlockCriteria.php b/airtime_mvc/application/forms/SmartBlockCriteria.php index b83a6e208..693f5c342 100644 --- a/airtime_mvc/application/forms/SmartBlockCriteria.php +++ b/airtime_mvc/application/forms/SmartBlockCriteria.php @@ -159,7 +159,8 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm $this->limitOptions = array( "hours" => _("hours"), "minutes" => _("minutes"), - "items" => _("items") + "items" => _("items"), + "remaining" => _("remaining time in show") ); } return $this->limitOptions; diff --git a/airtime_mvc/application/models/Block.php b/airtime_mvc/application/models/Block.php index 37bc92341..c45a4ae01 100644 --- a/airtime_mvc/application/models/Block.php +++ b/airtime_mvc/application/models/Block.php @@ -1310,9 +1310,13 @@ SQL; } } - public function getListOfFilesUnderLimit() + /* + * + */ + + public function getListOfFilesUnderLimit($show = null) { - $info = $this->getListofFilesMeetCriteria(); + $info = $this->getListofFilesMeetCriteria($show); $files = $info['files']; $limit = $info['limit']; $repeat = $info['repeat_tracks']; @@ -1467,7 +1471,7 @@ SQL; } // this function return list of propel object - public function getListofFilesMeetCriteria() + public function getListofFilesMeetCriteria($show = null) { $storedCrit = $this->getCriteria(); @@ -1605,6 +1609,17 @@ SQL; if ($storedCrit['limit']['modifier'] == "items") { $limits['time'] = 1440 * 60; $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(); + $limits['items'] = null; + } + else { + $limits['time'] = 1440 * 60; + $limits['items'] = null; + } } else { $limits['time'] = $storedCrit['limit']['modifier'] == "hours" ? intval(floatval($storedCrit['limit']['value']) * 60 * 60) : diff --git a/airtime_mvc/application/models/Scheduler.php b/airtime_mvc/application/models/Scheduler.php index cf542dce5..ef031554f 100644 --- a/airtime_mvc/application/models/Scheduler.php +++ b/airtime_mvc/application/models/Scheduler.php @@ -207,10 +207,11 @@ final class Application_Model_Scheduler /* * @param $id * @param $type + * @param $show * * @return $files */ - private function retrieveMediaFiles($id, $type) + private function retrieveMediaFiles($id, $type, $show) { $files = array(); @@ -337,7 +338,7 @@ final class Application_Model_Scheduler } else { $defaultFadeIn = Application_Model_Preference::GetDefaultFadeIn(); $defaultFadeOut = Application_Model_Preference::GetDefaultFadeOut(); - $dynamicFiles = $bl->getListOfFilesUnderLimit(); + $dynamicFiles = $bl->getListOfFilesUnderLimit($show); foreach ($dynamicFiles as $f) { $fileId = $f['id']; $file = CcFilesQuery::create()->findPk($fileId); @@ -788,11 +789,14 @@ final class Application_Model_Scheduler Logging::debug(floatval($pend) - floatval($pstart)); } + // passing $schedule["instance"] so that the instance being scheduled + // can be used to determine the remaining time + // in the case of a fill remaining time smart block if (is_null($filesToInsert)) { $filesToInsert = array(); foreach ($mediaItems as $media) { $filesToInsert = array_merge($filesToInsert, - $this->retrieveMediaFiles($media["id"], $media["type"])); + $this->retrieveMediaFiles($media["id"], $media["type"], $schedule["instance"])); } } diff --git a/airtime_mvc/application/models/ShowInstance.php b/airtime_mvc/application/models/ShowInstance.php index 3dddf80c8..511a83d8a 100644 --- a/airtime_mvc/application/models/ShowInstance.php +++ b/airtime_mvc/application/models/ShowInstance.php @@ -476,6 +476,12 @@ SQL; return intval($ends->format('U')) - intval($starts->format('U')); } + // should return the amount of seconds remaining to be scheduled in a show instance + public function getSecondsRemaining() + { + return ($this->getDurationSecs() - $this->getTimeScheduledSecs()); + } + public function getPercentScheduled() { $durationSeconds = $this->getDurationSecs();