CC-4553: Calendar: Can create overlapping show by repeat show's instances

-fixed
This commit is contained in:
denise 2012-10-12 14:26:54 -04:00
parent 1613353be8
commit 8f5830757f
2 changed files with 29 additions and 20 deletions

View file

@ -199,20 +199,15 @@ class Application_Form_AddShowWhen extends Zend_Form_SubForm
$repeatShowEnd->add(new DateInterval("P".$daysAdd."D")); $repeatShowEnd->add(new DateInterval("P".$daysAdd."D"));
} }
while ($repeatShowStart->getTimestamp() < $populateUntilDateTime->getTimestamp()) { while ($repeatShowStart->getTimestamp() < $populateUntilDateTime->getTimestamp()) {
//need to get each repeating show's instance id if (!$formData['add_show_id']) {
$qry = CcShowInstancesQuery::create() //this is a new show
->filterByDbStarts($repeatShowStart->format('Y-m-d H:i:s')) $overlapping = Application_Model_Schedule::checkOverlappingShows(
->filterByDbEnds($repeatShowEnd->format('Y-m-d H:i:s')) $repeatShowStart, $repeatShowEnd);
->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);
} else { } else {
$overlapping = false; $overlapping = Application_Model_Schedule::checkOverlappingShows(
$repeatShowStart, $repeatShowEnd, $update, null, $formData["add_show_id"]);
} }
if ($overlapping) { if ($overlapping) {
$valid = false; $valid = false;
$this->getElement('add_show_duration')->setErrors(array('Cannot schedule overlapping shows')); $this->getElement('add_show_duration')->setErrors(array('Cannot schedule overlapping shows'));

View file

@ -1157,14 +1157,21 @@ SQL;
} }
public static function checkOverlappingShows($show_start, $show_end, public static function checkOverlappingShows($show_start, $show_end,
$update=false, $instanceId=null) $update=false, $instanceId=null, $showId=null)
{ {
$overlapping = false; $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 /* If a show is being edited, exclude it from the query
* In both cases (new and edit) we only grab shows that * In both cases (new and edit) we only grab shows that
* are scheduled 2 days prior * are scheduled 2 days prior
*/ */
//$se = $show_end->format('Y-m-d H:i:s');
if ($update) { if ($update) {
$sql = <<<SQL $sql = <<<SQL
SELECT id, SELECT id,
@ -1175,15 +1182,21 @@ WHERE (ends <= :show_end1
OR starts <= :show_end2) OR starts <= :show_end2)
AND date(starts) >= (date(:show_end3) - INTERVAL '2 days') AND date(starts) >= (date(:show_end3) - INTERVAL '2 days')
AND modified_instance = FALSE AND modified_instance = FALSE
SQL;
if (is_null($showId)) {
$sql .= <<<SQL
AND id != :instanceId AND id != :instanceId
ORDER BY ends ORDER BY ends
SQL; SQL;
$rows = Application_Common_Database::prepareAndExecute($sql, array( $params[':instanceId'] = $instanceId;
':show_end1' => $show_end->format('Y-m-d H:i:s'), } else {
':show_end2' => $show_end->format('Y-m-d H:i:s'), $sql .= <<<SQL
':show_end3' => $show_end->format('Y-m-d H:i:s'), AND show_id != :showId
':instanceId' => $instanceId ORDER BY ends
), 'all'); SQL;
$params[':showId'] = $showId;
}
$rows = Application_Common_Database::prepareAndExecute($sql, $params, 'all');
} else { } else {
$sql = <<<SQL $sql = <<<SQL
SELECT id, SELECT id,
@ -1202,6 +1215,7 @@ SQL;
':show_end2' => $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')), 'all'); ':show_end3' => $show_end->format('Y-m-d H:i:s')), 'all');
} }
foreach ($rows as $row) { foreach ($rows as $row) {
$start = new DateTime($row["starts"], new DateTimeZone('UTC')); $start = new DateTime($row["starts"], new DateTimeZone('UTC'));
$end = new DateTime($row["ends"], new DateTimeZone('UTC')); $end = new DateTime($row["ends"], new DateTimeZone('UTC'));