From 7f775105e216653d7a0e4b0f0493888e4bfba549 Mon Sep 17 00:00:00 2001 From: naomiaro Date: Mon, 4 Apr 2011 00:02:35 -0400 Subject: [PATCH] adding end date check in get shows just incase nobody checks calendar for a while. preferences had to be updated because there will be no user id if the daemon process updates the date pouplated until pref. --- application/controllers/ApiController.php | 5 +++- application/forms/AddShowRebroadcastDates.php | 2 +- application/models/Preference.php | 27 ++++++++++++++++--- application/models/Shows.php | 17 ++++++------ 4 files changed, 37 insertions(+), 14 deletions(-) diff --git a/application/controllers/ApiController.php b/application/controllers/ApiController.php index 04368b94c..1b0e8ac51 100644 --- a/application/controllers/ApiController.php +++ b/application/controllers/ApiController.php @@ -257,7 +257,10 @@ class ApiController extends Zend_Controller_Action } $today_timestamp = date("Y-m-d H:i:s"); - $this->view->shows = Show::getShows($today_timestamp, null, $excludeInstance=NULL, $onlyRecord=TRUE); + $now = new DateTime($today_timestamp); + $end_timestamp = $now->add(new DateInterval("PT2H")); + $end_timestamp = $end_timestamp->format("Y-m-d H:i:s"); + $this->view->shows = Show::getShows($today_timestamp, $end_timestamp, $excludeInstance=NULL, $onlyRecord=TRUE); } public function uploadRecordedAction() diff --git a/application/forms/AddShowRebroadcastDates.php b/application/forms/AddShowRebroadcastDates.php index 6cc86b134..22e28a1a3 100644 --- a/application/forms/AddShowRebroadcastDates.php +++ b/application/forms/AddShowRebroadcastDates.php @@ -165,7 +165,7 @@ class Application_Form_AddShowRebroadcastDates extends Zend_Form_SubForm $show_end->add(new DateInterval("PT$duration[0]H")); $show_end->add(new DateInterval("PT$duration[1]M")); - $show_end->add(new DateInterval("PT1H"));//min time to wait until a rebroadcast + $show_end->add(new DateInterval("PT1H"));//min time to wait until a rebroadcast $rebroad_start = $formData['add_show_start_date']."".$formData['add_show_rebroadcast_time_'.$i]; $rebroad_start = new DateTime($rebroad_start); diff --git a/application/models/Preference.php b/application/models/Preference.php index 0ca748ebb..400e99d8a 100644 --- a/application/models/Preference.php +++ b/application/models/Preference.php @@ -6,19 +6,38 @@ class Application_Model_Preference public static function SetValue($key, $value){ global $CC_CONFIG, $CC_DBC; - $auth = Zend_Auth::getInstance(); - $id = $auth->getIdentity()->id; + //called from a daemon process + if(!Zend_Auth::getInstance()->hasIdentity()) { + $id = NULL; + } + else { + $auth = Zend_Auth::getInstance(); + $id = $auth->getIdentity()->id; + } + + $key = pg_escape_string($key); + $value = pg_escape_string($value); //Check if key already exists $sql = "SELECT COUNT(*) FROM cc_pref" ." WHERE keystr = '$key'"; $result = $CC_DBC->GetOne($sql); - if ($result == 1){ + if ($result == 1 && is_null($id)){ + $sql = "UPDATE cc_pref" + ." SET subjid = NULL, valstr = '$value'" + ." WHERE keystr = '$key'"; + } + else if ($result == 1 && !is_null($id)){ $sql = "UPDATE cc_pref" ." SET subjid = $id, valstr = '$value'" ." WHERE keystr = '$key'"; - } else { + } + else if(is_null($id)) { + $sql = "INSERT INTO cc_pref (keystr, valstr)" + ." VALUES ('$key', '$value')"; + } + else { $sql = "INSERT INTO cc_pref (subjid, keystr, valstr)" ." VALUES ($id, '$key', '$value')"; } diff --git a/application/models/Shows.php b/application/models/Shows.php index a7ee8d232..ac682bc7f 100644 --- a/application/models/Shows.php +++ b/application/models/Shows.php @@ -275,6 +275,14 @@ class Show { { global $CC_DBC; + $showsPopUntil = Application_Model_Preference::GetShowsPopulatedUntil(); + + //if application is requesting shows past our previous populated until date, generate shows up until this point. + if ($showsPopUntil == "" || strtotime($showsPopUntil) < strtotime($end_timestamp)) { + Show::populateAllShowsInRange($showsPopUntil, $end_timestamp); + Application_Model_Preference::SetShowsPopulatedUntil($end_timestamp); + } + $sql = "SELECT starts, ends, record, rebroadcast, soundcloud_id, instance_id, show_id, name, description, color, background_color, cc_show_instances.id AS instance_id FROM cc_show_instances @@ -283,7 +291,7 @@ class Show { //only want shows that are starting at the time or later. if ($onlyRecord) { - $sql = $sql." WHERE (starts >= '{$start_timestamp}' AND starts < timestamp '{$start_timestamp}' + interval '2 hours')"; + $sql = $sql." WHERE (starts >= '{$start_timestamp}' AND starts < timestamp '{$end_timestamp}')"; $sql = $sql." AND (record = 1)"; } else { @@ -525,13 +533,6 @@ class Show { public static function getFullCalendarEvents($start, $end, $editable=false) { $events = array(); - $showsPopUntil = Application_Model_Preference::GetShowsPopulatedUntil(); - - //if fullcalendar is requesting shows past our previous populated until date, generate shows up until this point. - if ($showsPopUntil == "" || strtotime($showsPopUntil) < strtotime($end)) { - Show::populateAllShowsInRange($showsPopUntil, $end); - Application_Model_Preference::SetShowsPopulatedUntil($end); - } $shows = Show::getShows($start, $end);