diff --git a/airtime_mvc/application/forms/AddShowWhen.php b/airtime_mvc/application/forms/AddShowWhen.php index 86018ff1a..870e79183 100644 --- a/airtime_mvc/application/forms/AddShowWhen.php +++ b/airtime_mvc/application/forms/AddShowWhen.php @@ -199,20 +199,15 @@ class Application_Form_AddShowWhen extends Zend_Form_SubForm $repeatShowEnd->add(new DateInterval("P".$daysAdd."D")); } while ($repeatShowStart->getTimestamp() < $populateUntilDateTime->getTimestamp()) { - //need to get each repeating show's instance id - $qry = CcShowInstancesQuery::create() - ->filterByDbStarts($repeatShowStart->format('Y-m-d H:i:s')) - ->filterByDbEnds($repeatShowEnd->format('Y-m-d H:i:s')) - ->find(); - $count = $qry->count(); - if ($count > 1) { - $overlapping = true; - } elseif ($count == 1) { - $instanceId = $qry->getFirst()->getDbId(); - $overlapping = Application_Model_Schedule::checkOverlappingShows($repeatShowStart, $repeatShowEnd, $update, $instanceId); + if (!$formData['add_show_id']) { + //this is a new show + $overlapping = Application_Model_Schedule::checkOverlappingShows( + $repeatShowStart, $repeatShowEnd); } else { - $overlapping = false; + $overlapping = Application_Model_Schedule::checkOverlappingShows( + $repeatShowStart, $repeatShowEnd, $update, null, $formData["add_show_id"]); } + if ($overlapping) { $valid = false; $this->getElement('add_show_duration')->setErrors(array('Cannot schedule overlapping shows')); diff --git a/airtime_mvc/application/models/Schedule.php b/airtime_mvc/application/models/Schedule.php index eff64b2ec..1102efaff 100644 --- a/airtime_mvc/application/models/Schedule.php +++ b/airtime_mvc/application/models/Schedule.php @@ -1157,14 +1157,21 @@ SQL; } public static function checkOverlappingShows($show_start, $show_end, - $update=false, $instanceId=null) + $update=false, $instanceId=null, $showId=null) { $overlapping = false; + + $params = array( + ':show_end1' => $show_end->format('Y-m-d H:i:s'), + ':show_end2' => $show_end->format('Y-m-d H:i:s'), + ':show_end3' => $show_end->format('Y-m-d H:i:s') + ); + + /* If a show is being edited, exclude it from the query * In both cases (new and edit) we only grab shows that * are scheduled 2 days prior */ - //$se = $show_end->format('Y-m-d H:i:s'); if ($update) { $sql = <<= (date(:show_end3) - INTERVAL '2 days') AND modified_instance = FALSE +SQL; + if (is_null($showId)) { + $sql .= << $show_end->format('Y-m-d H:i:s'), - ':show_end2' => $show_end->format('Y-m-d H:i:s'), - ':show_end3' => $show_end->format('Y-m-d H:i:s'), - ':instanceId' => $instanceId - ), 'all'); + $params[':instanceId'] = $instanceId; + } else { + $sql .= << $show_end->format('Y-m-d H:i:s'), ':show_end3' => $show_end->format('Y-m-d H:i:s')), 'all'); } + foreach ($rows as $row) { $start = new DateTime($row["starts"], new DateTimeZone('UTC')); $end = new DateTime($row["ends"], new DateTimeZone('UTC'));