CC-4056: Add Show -> Prevent shows from overlapping
-done
This commit is contained in:
parent
bc93119adc
commit
cbf026412c
|
@ -138,6 +138,20 @@ class Application_Form_AddShowWhen extends Zend_Form_SubForm
|
||||||
$valid = false;
|
$valid = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Check if show is overlapping
|
||||||
|
* We will only do this check if the show is valid
|
||||||
|
* upto this point
|
||||||
|
*/
|
||||||
|
if ($valid) {
|
||||||
|
$show_start = new DateTime($start_time);
|
||||||
|
$show_end = new DateTime($end_time);
|
||||||
|
$overlapping = Application_Model_Schedule::checkOverlappingShows($show_start, $show_end);
|
||||||
|
if ($overlapping) {
|
||||||
|
$this->getElement('add_show_duration')->setErrors(array('Cannot have overlapping shows'));
|
||||||
|
$valid = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $valid;
|
return $valid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -912,4 +912,47 @@ class Application_Model_Schedule {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function checkOverlappingShows($show_start, $show_end) {
|
||||||
|
global $CC_CONFIG;
|
||||||
|
|
||||||
|
$overlapping = false;
|
||||||
|
//Set timezone to UTC to be consisent with DB
|
||||||
|
$show_start->setTimezone(new DateTimeZone('UTC'));
|
||||||
|
|
||||||
|
$con = Propel::getConnection();
|
||||||
|
$sql = "SELECT id, starts, ends FROM ".$CC_CONFIG["showInstances"]."
|
||||||
|
where starts <= '{$show_start->format('Y-m-d H:i:s')}' order by ends";
|
||||||
|
$rows = $con->query($sql);
|
||||||
|
|
||||||
|
//Set back to local timezone to do comparison
|
||||||
|
$show_start->setTimezone(new DateTimeZone(Application_Model_Preference::GetTimezone()));
|
||||||
|
|
||||||
|
foreach($rows as $row) {
|
||||||
|
$start = new DateTime($row["starts"]);
|
||||||
|
$end = new DateTime($row["ends"]);
|
||||||
|
|
||||||
|
/* When data is grabbed from the DB, the time is in UTC
|
||||||
|
* but the timezone is set locally. Comparing timestamps
|
||||||
|
* on two DateTime objects with different timezones but
|
||||||
|
* same time yeild different results.
|
||||||
|
*
|
||||||
|
* Since we cannot change the timezone back to UTC without
|
||||||
|
* changing the time, we convert each show's instance
|
||||||
|
* end time to local time via offset and then do the comparison.
|
||||||
|
*/
|
||||||
|
$offset = $show_start->getOffset();
|
||||||
|
if ($offset < 0) {
|
||||||
|
$end->sub(new DateInterval("PT".abs($offset)."S"));
|
||||||
|
} else {
|
||||||
|
$end->add(new DateInterval("PT".$offset."S"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($show_start->getTimestamp() < $end->getTimestamp()) {
|
||||||
|
$overlapping = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $overlapping;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue