From 5443c1931a24f8f9ece788182efb679956bb5e0d Mon Sep 17 00:00:00 2001 From: denise Date: Fri, 24 Aug 2012 15:27:04 -0400 Subject: [PATCH] CC-4081: Calendar -> Can create overlapping show by dragging a show in "day" view -fixed --- airtime_mvc/application/models/Show.php | 33 +++++++++++++++++++ .../application/models/ShowInstance.php | 2 +- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/airtime_mvc/application/models/Show.php b/airtime_mvc/application/models/Show.php index 86e32965e..ee08dd057 100644 --- a/airtime_mvc/application/models/Show.php +++ b/airtime_mvc/application/models/Show.php @@ -172,6 +172,39 @@ class Application_Model_Show if ($deltaDay > 0) { return "Shows can have a max length of 24 hours."; } + + $showInstances = CcShowInstancesQuery::create() + ->filterByDbShowId($this->_showId) + ->find($con); + + /* Check if the show being resized and any of its repeats + * overlap with other scheduled shows + */ + foreach ($showInstances as $si) { + $startsDateTime = new DateTime($si->getDbStarts(), new DateTimeZone("UTC")); + $endsDateTime = new DateTime($si->getDbEnds(), new DateTimeZone("UTC")); + + /* The user is moving the show on the calendar from the perspective of local time. + * incase a show is moved across a time change border offsets should be added to the local + * timestamp and then converted back to UTC to avoid show time changes + */ + $startsDateTime->setTimezone(new DateTimeZone(date_default_timezone_get())); + $endsDateTime->setTimezone(new DateTimeZone(date_default_timezone_get())); + + $newStartsDateTime = Application_Model_ShowInstance::addDeltas($startsDateTime, $deltaDay, $deltaMin); + $newEndsDateTime = Application_Model_ShowInstance::addDeltas($endsDateTime, $deltaDay, $deltaMin); + + //convert our new starts/ends to UTC. + $newStartsDateTime->setTimezone(new DateTimeZone("UTC")); + $newEndsDateTime->setTimezone(new DateTimeZone("UTC")); + + $overlapping = Application_Model_Schedule::checkOverlappingShows($newStartsDateTime, + $newEndsDateTime, true, $si->getDbId()); + if ($overlapping) { + return "Cannot schedule overlapping shows.\nNote: Resizing a repeating show ". + "affects all of its repeats."; + } + } $hours = $deltaMin/60; if ($hours > 0) { diff --git a/airtime_mvc/application/models/ShowInstance.php b/airtime_mvc/application/models/ShowInstance.php index f6fd10491..2d2b18894 100644 --- a/airtime_mvc/application/models/ShowInstance.php +++ b/airtime_mvc/application/models/ShowInstance.php @@ -205,7 +205,7 @@ class Application_Model_ShowInstance * @return $newDateTime * php DateTime, $dateTime with the added time deltas. */ - private static function addDeltas($dateTime, $deltaDay, $deltaMin) + public static function addDeltas($dateTime, $deltaDay, $deltaMin) { $newDateTime = clone $dateTime;