From ef8f87df5d3d245b874abcae2f32b90fbeef0cea Mon Sep 17 00:00:00 2001 From: denise Date: Mon, 25 Mar 2013 16:28:53 -0400 Subject: [PATCH] Show linking --- airtime_mvc/application/models/Show.php | 4 +- .../application/services/ShowService.php | 38 +++++++++++++++++-- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/airtime_mvc/application/models/Show.php b/airtime_mvc/application/models/Show.php index 8490f6295..da71f3a21 100644 --- a/airtime_mvc/application/models/Show.php +++ b/airtime_mvc/application/models/Show.php @@ -1664,7 +1664,9 @@ SQL; $showsPopUntil = Application_Model_Preference::GetShowsPopulatedUntil(); //if application is requesting shows past our previous populated until date, generate shows up until this point. if (is_null($showsPopUntil) || $showsPopUntil->getTimestamp() < $end_timestamp->getTimestamp()) { - Application_Model_Show::populateAllShowsInRange($showsPopUntil, $end_timestamp); + //Application_Model_Show::populateAllShowsInRange($showsPopUntil, $end_timestamp); + $service_show = new Application_Service_ShowService(); + $service_show->delegateInstanceCreation(null, false, $end_timestamp); Application_Model_Preference::SetShowsPopulatedUntil($end_timestamp); } diff --git a/airtime_mvc/application/services/ShowService.php b/airtime_mvc/application/services/ShowService.php index 12ae5e4ae..f44c2c64d 100644 --- a/airtime_mvc/application/services/ShowService.php +++ b/airtime_mvc/application/services/ShowService.php @@ -93,11 +93,15 @@ class Application_Service_ShowService * Receives a cc_show id and determines whether to create a * single show instance or repeating show instances */ - private function delegateInstanceCreation($isRebroadcast, $isUpdate) + public function delegateInstanceCreation($isRebroadcast=null, $isUpdate=false, $end=null) { $populateUntil = $this->getPopulateShowUntilDateTIme(); - $ccShowDays = $this->ccShow->getCcShowDays(); + if (is_null($this->ccShow)) { + $ccShowDays = $this->getShowDaysInRange($populateUntil, $end); + } else { + $ccShowDays = $this->ccShow->getCcShowDays(); + } foreach ($ccShowDays as $day) { switch ($day->getDbRepeatType()) { @@ -123,6 +127,32 @@ class Application_Service_ShowService } } + private function getShowDaysInRange($start, $end) + { + $endTimeString = $end->format("Y-m-d H:i:s"); + if (!is_null($start)) { + $startTimeString = $start->format("Y-m-d H:i:s"); + } else { + $today_timestamp = new DateTime("now", new DateTimeZone("UTC")); + $startTimeString = $today_timestamp->format("Y-m-d H:i:s"); + } + + return CcShowDaysQuery::create() + ->add("last_show", null, "=") + ->addOr("first_show", $endTimeString, "<") + ->add("last_show", $startTimeString, ">") + ->find(); + /*$sql = <<< SQL +SELECT * FROM cc_show_days +WHERE last_show IS NULL + OR first_show < :endTimeString + AND last_show > :startTimeString +SQL; + + return Application_Common_Database::prepareAndExecute($sql, + array( ':endTimeString' => $endTimeString, ':startTimeString' => $startTimeString ), 'all');*/ + } + public static function formatShowDuration($duration) { $hPos = strpos($duration, 'h'); @@ -650,7 +680,7 @@ SQL; //DateTime local $start = $this->getNextRepeatingPopulateStartDateTime($showDay); - if (isset($last_how)) { + if (isset($last_show)) { $end = new DateTime($last_show, new DateTimeZone($timezone)); } else { $end = $populateUntil; @@ -1023,7 +1053,7 @@ SQL; * * @return DateTime object */ - private function getPopulateShowUntilDateTIme() + private static function getPopulateShowUntilDateTIme() { $populateUntil = Application_Model_Preference::GetShowsPopulatedUntil();