From 428b13f3d71235b21897815ef4df9efaf95431c2 Mon Sep 17 00:00:00 2001 From: Naomi Aro Date: Tue, 22 May 2012 17:51:53 +0200 Subject: [PATCH] CC-3803 : Don't allow editing of a current Record show --- .../controllers/ScheduleController.php | 47 +++++-------------- .../application/forms/AddShowLiveStream.php | 2 +- airtime_mvc/application/models/Show.php | 39 +++++++++------ 3 files changed, 37 insertions(+), 51 deletions(-) diff --git a/airtime_mvc/application/controllers/ScheduleController.php b/airtime_mvc/application/controllers/ScheduleController.php index f98c06f33..755cbc7f3 100644 --- a/airtime_mvc/application/controllers/ScheduleController.php +++ b/airtime_mvc/application/controllers/ScheduleController.php @@ -272,47 +272,25 @@ class ScheduleController extends Zend_Controller_Action } if ($showStartLocalDT->getTimestamp() <= $epochNow && - $epochNow < $showEndLocalDT->getTimestamp() && - ($isAdminOrPM || $isDJ)) { + $epochNow < $showEndLocalDT->getTimestamp() && $isAdminOrPM) { if ($instance->isRecorded()) { - if($isAdminOrPM){ - $menu["cancel_recorded"] = array("name"=> "Cancel Current Show", "icon" => "delete"); - } - } else { - if($instance->isRepeating()){ - /*$menu["edit"] = array("name"=> "Edit", "icon" => "edit", "items" => array()); - $menu["edit"]["items"]["instance"] = array("name"=> "Edit Show Instance", "icon" => "edit", "url" => "/Schedule/populate-show-instance-form"); - $menu["edit"]["items"]["all"] = array("name"=> "Edit Show", "icon" => "edit", "url" => "/Schedule/populate-show-form");*/ + $menu["cancel_recorded"] = array("name"=> "Cancel Current Show", "icon" => "delete"); + } + else { + + if (!$instance->isRebroadcast()) { $menu["edit"] = array("name"=> "Edit Show", "icon" => "edit", "_type"=>"all", "url" => "/Schedule/populate-show-form"); - }else{ - if($instance->isRebroadcast()){ - $menu["edit"] = array("name"=> "Edit Show", "icon" => "edit", "_type"=>"rebroadcast", "url" => "/Schedule/populate-show-form"); - }else{ - $menu["edit"] = array("name"=> "Edit Show", "icon" => "edit", "_type"=>"all", "url" => "/Schedule/populate-show-form"); - } - } - if($isAdminOrPM){ - $menu["cancel"] = array("name"=> "Cancel Current Show", "icon" => "delete"); } + + $menu["cancel"] = array("name"=> "Cancel Current Show", "icon" => "delete"); } } if ($epochNow < $showStartLocalDT->getTimestamp()) { - if ($isAdminOrPM || $isDJ) { - - if($instance->isRepeating()){ - /*$menu["edit"] = array("name"=> "Edit", "icon" => "edit", "items" => array()); - $menu["edit"]["items"]["instance"] = array("name"=> "Edit Show Instance", "icon" => "edit", "url" => "/Schedule/populate-show-instance-form"); - $menu["edit"]["items"]["all"] = array("name"=> "Edit Show", "icon" => "edit", "url" => "/Schedule/populate-show-form");*/ + if (!$instance->isRebroadcast() && $isAdminOrPM) { $menu["edit"] = array("name"=> "Edit Show", "icon" => "edit", "_type"=>"all", "url" => "/Schedule/populate-show-form"); - }else{ - if($instance->isRebroadcast()){ - $menu["edit"] = array("name"=> "Edit Show", "icon" => "edit", "_type"=>"rebroadcast", "url" => "/Schedule/populate-show-form"); - }else{ - $menu["edit"] = array("name"=> "Edit Show", "icon" => "edit", "_type"=>"all", "url" => "/Schedule/populate-show-form"); - } } if ($instance->getShow()->isRepeating() && $isAdminOrPM) { @@ -324,11 +302,10 @@ class ScheduleController extends Zend_Controller_Action $menu["del"]["items"]["following"] = array("name"=> "Delete This Instance and All Following", "icon" => "delete", "url" => "/schedule/cancel-show"); } - else if($isAdminOrPM){ - //window["scheduleRefetchEvents"]' - $menu["del"] = array("name"=> "Delete", "icon" => "delete", "url" => "/schedule/delete-show"); + else if ($isAdminOrPM){ + + $menu["del"] = array("name"=> "Delete", "icon" => "delete", "url" => "/schedule/delete-show"); } - } } $this->view->items = $menu; diff --git a/airtime_mvc/application/forms/AddShowLiveStream.php b/airtime_mvc/application/forms/AddShowLiveStream.php index cc90cf6d6..680de4645 100644 --- a/airtime_mvc/application/forms/AddShowLiveStream.php +++ b/airtime_mvc/application/forms/AddShowLiveStream.php @@ -14,7 +14,7 @@ class Application_Form_AddShowLiveStream extends Zend_Form_SubForm ->setDecorators(array('ViewHelper')); $this->addElement($cb_airtime_auth); - $description2 = "Specify custom authentication which will work for only for this show."; + $description2 = "Specify custom authentication which will work only for this show."; $cb_custom_auth = new Zend_Form_Element_Checkbox("cb_custom_auth"); $cb_custom_auth ->setLabel("Use Custom Authentication:") ->setDescription($description2) diff --git a/airtime_mvc/application/models/Show.php b/airtime_mvc/application/models/Show.php index 8c3d8d60c..dc8c29026 100644 --- a/airtime_mvc/application/models/Show.php +++ b/airtime_mvc/application/models/Show.php @@ -1484,32 +1484,34 @@ class Application_Model_Show { Application_Model_Preference::SetShowsPopulatedUntil($end_timestamp); } - $sql = "SELECT starts, ends, record, rebroadcast, instance_id, show_id, name, - color, background_color, file_id, cc_show_instances.id AS instance_id, - created, last_scheduled, time_filled - FROM cc_show_instances - LEFT JOIN cc_show ON cc_show.id = cc_show_instances.show_id - WHERE cc_show_instances.modified_instance = FALSE"; + $sql = "SELECT si1.starts AS starts, si1.ends AS ends, si1.record AS record, si1.rebroadcast AS rebroadcast, si2.starts AS parent_starts, + si1.instance_id AS record_id, si1.show_id AS show_id, show.name AS name, + show.color AS color, show.background_color AS background_color, si1.file_id AS file_id, si1.id AS instance_id, + si1.created AS created, si1.last_scheduled AS last_scheduled, si1.time_filled AS time_filled + FROM cc_show_instances AS si1 + LEFT JOIN cc_show_instances AS si2 ON si1.instance_id = si2.id + LEFT JOIN cc_show AS show ON show.id = si1.show_id + WHERE si1.modified_instance = FALSE"; //only want shows that are starting at the time or later. $start_string = $start_timestamp->format("Y-m-d H:i:s"); $end_string = $end_timestamp->format("Y-m-d H:i:s"); if ($onlyRecord) { - $sql = $sql." AND (starts >= '{$start_string}' AND starts < timestamp '{$end_string}')"; - $sql = $sql." AND (record = 1)"; + $sql = $sql." AND (si1.starts >= '{$start_string}' AND si1.starts < timestamp '{$end_string}')"; + $sql = $sql." AND (si1.record = 1)"; } else { - $sql = $sql." AND ((starts >= '{$start_string}' AND starts < '{$end_string}') - OR (ends > '{$start_string}' AND ends <= '{$end_string}') - OR (starts <= '{$start_string}' AND ends >= '{$end_string}'))"; + $sql = $sql." AND ((si1.starts >= '{$start_string}' AND si1.starts < '{$end_string}') + OR (si1.ends > '{$start_string}' AND si1.ends <= '{$end_string}') + OR (si1.starts <= '{$start_string}' AND si1.ends >= '{$end_string}'))"; } if (isset($excludeInstance)) { foreach($excludeInstance as $instance) { - $sql_exclude[] = "cc_show_instances.id != {$instance}"; + $sql_exclude[] = "si1.id != {$instance}"; } $exclude = join(" OR ", $sql_exclude); @@ -1517,8 +1519,8 @@ class Application_Model_Show { $sql = $sql." AND ({$exclude})"; } - //Logging::log("getShows"); - //Logging::log($sql); + Logging::debug("getShows"); + Logging::debug($sql); $result = $con->query($sql)->fetchAll(); return $result; } @@ -1594,15 +1596,22 @@ class Application_Model_Show { $options["percent"] = Application_Model_Show::getPercentScheduled($show["starts"], $show["ends"], $show["time_filled"]); } + if (isset($show["parent_starts"])) { + $parentStartsDT = new DateTime($show["parent_starts"], new DateTimeZone("UTC")); + $parentStartsEpoch = intval($parentStartsDT->format("U")); + } $startsDT = new DateTime($show["starts"], new DateTimeZone("UTC")); $endsDT = new DateTime($show["ends"], new DateTimeZone("UTC")); $startsEpoch = intval($startsDT->format("U")); $endsEpoch = intval($endsDT->format("U")); - if ($p_editable && $show["record"] && $nowEpoch < $endsEpoch) { + if ($p_editable && $show["record"] && $nowEpoch > $startsEpoch) { $options["editable"] = false; } + else if ($p_editable && $show["rebroadcast"] && $nowEpoch > $parentStartsEpoch) { + $options["editable"] = false; + } else if ($p_editable && $nowEpoch < $endsEpoch) { $options["editable"] = true; }