From 6f9254e655588d6d3f90fd0d5fdfb21a52238c83 Mon Sep 17 00:00:00 2001 From: drigato Date: Thu, 28 Nov 2013 17:17:00 -0500 Subject: [PATCH 01/14] CC-5405: When editing a single show instance from a repeating series, should not create a new cc_show Create a new cc_show_day rule instead of a new cc_show --- .../controllers/ScheduleController.php | 3 +- airtime_mvc/application/models/Show.php | 6 +- .../application/models/airtime/CcShow.php | 59 ++++++- .../application/services/ShowFormService.php | 12 +- .../application/services/ShowService.php | 148 +++++++++++++----- .../schedule/full-calendar-functions.js | 2 +- 6 files changed, 181 insertions(+), 49 deletions(-) diff --git a/airtime_mvc/application/controllers/ScheduleController.php b/airtime_mvc/application/controllers/ScheduleController.php index f18fc9fff..ed13d68d1 100644 --- a/airtime_mvc/application/controllers/ScheduleController.php +++ b/airtime_mvc/application/controllers/ScheduleController.php @@ -183,6 +183,7 @@ class ScheduleController extends Zend_Controller_Action $deltaDay = $this->_getParam('day'); $deltaMin = $this->_getParam('min'); $showId = $this->_getParam('showId'); + $instanceId = $this->_getParam('instanceId'); $userInfo = Zend_Auth::getInstance()->getStorage()->read(); $user = new Application_Model_User($userInfo->id); @@ -195,7 +196,7 @@ class ScheduleController extends Zend_Controller_Action return false; } - $error = $show->resizeShow($deltaDay, $deltaMin); + $error = $show->resizeShow($deltaDay, $deltaMin, $instanceId); } if (isset($error)) { diff --git a/airtime_mvc/application/models/Show.php b/airtime_mvc/application/models/Show.php index 123a26a99..1b8253ad8 100644 --- a/airtime_mvc/application/models/Show.php +++ b/airtime_mvc/application/models/Show.php @@ -172,16 +172,16 @@ SQL; $show->delete(); } - public function resizeShow($deltaDay, $deltaMin) + public function resizeShow($deltaDay, $deltaMin, $instanceId) { $con = Propel::getConnection(); if ($deltaDay > 0) { return _("Shows can have a max length of 24 hours."); } - + $utc = new DateTimeZone("UTC"); - + $nowDateTime = new DateTime("now", $utc); $showInstances = CcShowInstancesQuery::create() diff --git a/airtime_mvc/application/models/airtime/CcShow.php b/airtime_mvc/application/models/airtime/CcShow.php index 028ec6fea..c58042006 100644 --- a/airtime_mvc/application/models/airtime/CcShow.php +++ b/airtime_mvc/application/models/airtime/CcShow.php @@ -15,8 +15,20 @@ */ class CcShow extends BaseCcShow { - public function getCcShowDays(){ - return CcShowDaysQuery::create()->filterByDbShowId($this->getDbId())->find(); + /* + * Returns all cc_show_day rules that belong to a cc_show and that are + * repeating. + * We do this because editing a single instance from a repeating sequence + * creates a new rule in cc_show_days with the same cc_show id and a repeat + * type of -1 (non-repeating). + * So when the entire cc_show is updated after that, the single edited + * instance can remain separate from the rest of the instances + */ + public function getRepeatingCcShowDays(){ + return CcShowDaysQuery::create() + ->filterByDbShowId($this->id) + ->filterByDbRepeatType(-1, Criteria::NOT_EQUAL) + ->find(); } /** @@ -54,6 +66,49 @@ class CcShow extends BaseCcShow { return $this->collCcShowDayss[0]; } + /** + * + * A repeating show may have a rule in cc_show_days with a repeat type + * of -1 (not repeating). This happens when a single instances was edited + * from the repeating sequence. + * + * When the repeating show gets edited in this case, we want to exclude all + * the edited instances from the update. We do this by not returning any of + * the cc_show_day rules with a -1 repeat type. + */ + public function getFirstRepeatingCcShowDay() + { + return CcShowDaysQuery::create() + ->filterByDbShowId($this->id) + ->filterByDbRepeatType(-1, Criteria::NOT_EQUAL) + ->orderByDbFirstShow() + ->findOne(); + } + + /** + * + * In order to determine if a show is repeating we need to check each + * cc_show_day entry and check if there are any non -1 repeat types. + * Because editing a single instances creates a new cc_show_day rule + * with a -1 (non repeating) repeat type we need to check all cc_show_day + * entries + */ + public function isRepeating() + { + //get ALL cc_show_day entries + $ccShowDays = CcShowDaysQuery::create() + ->filterByDbShowId($this->id) + ->find(); + + foreach ($ccShowDays as $day) { + if ($day->getDbRepeatType() >= 0) { + return true; + } + } + + return false; + } + /** * Gets an array of CcShowInstances objects which contain a foreign key that references this object. * diff --git a/airtime_mvc/application/services/ShowFormService.php b/airtime_mvc/application/services/ShowFormService.php index 0fa705f2a..85b9868c0 100644 --- a/airtime_mvc/application/services/ShowFormService.php +++ b/airtime_mvc/application/services/ShowFormService.php @@ -124,7 +124,11 @@ class Application_Service_ShowFormService private function populateFormWhen($form) { - $ccShowDay = $this->ccShow->getFirstCcShowDay(); + if ($this->ccShow->isRepeating()) { + $ccShowDay = $this->ccShow->getFirstRepeatingCcShowDay(); + } else { + $ccShowDay = $this->ccShow->getFirstCcShowDay(); + } $showStart = $ccShowDay->getLocalStartDateAndTime(); $showEnd = $ccShowDay->getLocalEndDateAndTime($showStart); @@ -198,7 +202,11 @@ class Application_Service_ShowFormService */ private function populateFormRepeats($form, $nextFutureShowStart) { - $ccShowDays = $this->ccShow->getCcShowDays(); + if ($this->ccShow->isRepeating()) { + $ccShowDays = $this->ccShow->getRepeatingCcShowDays(); + } else { + $ccShowDays = $this->ccShow->getCcShowDayss(); + } $days = array(); foreach ($ccShowDays as $ccShowDay) { diff --git a/airtime_mvc/application/services/ShowService.php b/airtime_mvc/application/services/ShowService.php index 303236e9f..5dc505882 100644 --- a/airtime_mvc/application/services/ShowService.php +++ b/airtime_mvc/application/services/ShowService.php @@ -55,11 +55,13 @@ class Application_Service_ShowService throw new Exception("Permission denied"); } + $showId = $showData["add_show_id"]; + /****** UPDATE SCHEDULE START TIME ******/ //get the ccShow object to which this instance belongs //so we can get the original start date and time - $oldCcShow = CcShowQuery::create() - ->findPk($showData["add_show_id"]); + $this->ccShow = CcShowQuery::create() + ->findPk($showId); //DateTime in shows's local time $newStartDateTime = new DateTime($showData["add_show_start_date"]." ". @@ -68,52 +70,78 @@ class Application_Service_ShowService $ccShowInstanceOrig = CcShowInstancesQuery::create() ->findPk($showData["add_show_instance_id"]); - $diff = $this->calculateShowStartDiff($newStartDateTime, - $ccShowInstanceOrig->getLocalStartDateTime()); - if ($diff > 0) { + //convert original start time into the show's local timezone + $origLocalStartDateTime = $ccShowInstanceOrig->getLocalStartDateTime(); + + $diff = $this->calculateShowStartDiff($newStartDateTime, + $origLocalStartDateTime); + + if ($diff != 0) { Application_Service_SchedulerService::updateScheduleStartTime( array($showData["add_show_instance_id"]), $diff); } /****** UPDATE SCHEDULE START TIME ENDS******/ - $this->setCcShow($showData); + /* + * Set the new cc_show_day record + * Associates it with the current show_id and sets it to non-repeating + */ $this->setCcShowDays($showData); - $this->setCcShowHosts($showData); - $this->delegateInstanceCreation(); - //get the new instance id - $ccShowInstance = CcShowInstancesQuery::create() - ->filterByDbShowId($this->ccShow->getDbId()) + /* + * In the case where an instance is being edited for a second + * (or third, fourth, etc.) time we need to delete the old + * cc_show_day record + * + * Since we don't store the cc_show_day ids we need to use the + * original start time from cc_show_instances, convert it to the show's + * local timezone, and find the record in cc_show_days + * + * *** There is a flaw here: We have to assume the show timezone has + * *** not changed (make timezone readonly??) + */ + $origCcShowDay = CcShowDaysQuery::create() + ->filterByDbShowId($showId) + ->filterByDbRepeatType(-1) + ->filterByDbFirstShow($origLocalStartDateTime->format("Y-m-d")) + ->filterByDbStartTime($origLocalStartDateTime->format("H:i:s")) + ->delete(); + + // DO WE NEED THIS? + $this->setCcShowHosts($showData); + + /* + * We need to find the new show day rule we just created by passing + * in the first show and start time in case multiple single + * instances have been edited out of the repeating sequence. + */ + $showDay = CcShowDaysQuery::create() + ->filterByDbShowId($showId) + ->filterByDbRepeatType(-1) + ->filterByDbFirstShow($showData["add_show_start_date"]) + ->filterByDbStartTime($showData["add_show_start_time"]) ->findOne(); - $newInstanceId = $ccShowInstance->getDbId(); + $ccShowInstance = $this->createNonRepeatingInstance($showDay, + $this->getPopulateShowUntilDateTIme()); //update cc_schedule with the new instance id - $ccSchedules = CcScheduleQuery::create() - ->filterByDbInstanceId($showData["add_show_instance_id"]) - ->find(); - - foreach ($ccSchedules as $ccSchedule) { - $ccSchedule->setDbInstanceId($newInstanceId); - $ccSchedule->save(); - } - $con = Propel::getConnection(CcShowInstancesPeer::DATABASE_NAME); + $selectCriteria = new Criteria(); + $selectCriteria->add(CcSchedulePeer::INSTANCE_ID, $showData["add_show_instance_id"]); + $updateCriteria = new Criteria(); + $updateCriteria->add(CcSchedulePeer::INSTANCE_ID, $ccShowInstance->getDbId()); + BasePeer::doUpdate($selectCriteria, $updateCriteria, $con); + + $ccShowInstance + ->setDbLastScheduled(gmdate("Y-m-d H:i:s")) + ->save(); $ccShowInstance->updateDbTimeFilled($con); //delete the edited instance from the repeating sequence $ccShowInstanceOrig->setDbModifiedInstance(true)->save(); - $service_showForm = new Application_Service_ShowFormService($showData["add_show_id"]); - list($start, $end) = $service_showForm->getNextFutureRepeatShowTime(); - $oldCcShowDay = $oldCcShow->getFirstCcShowDay(); - $oldCcShowDay - ->setDbFirstShow( - $start->setTimezone(new DateTimeZone( - $oldCcShowDay->getDbTimezone()))->format("Y-m-d")) - ->save(); - $con->commit(); Application_Model_RabbitMq::PushSchedule(); } catch (Exception $e) { @@ -131,7 +159,7 @@ class Application_Service_ShowService */ private function storeOrigLocalShowInfo() { - $this->origCcShowDay = $this->ccShow->getFirstCcShowDay(); + $this->origCcShowDay = $this->ccShow->getFirstRepeatingCcShowDay(); $this->oldShowTimezone = $this->origCcShowDay->getDbTimezone(); @@ -165,7 +193,7 @@ class Application_Service_ShowService $this->deleteRebroadcastInstances(); - $this->deleteCcShowDays(); + //$this->deleteCcShowDays(); $this->deleteCcShowHosts(); if ($this->isRebroadcast) { //delete entry in cc_show_rebroadcast @@ -225,7 +253,11 @@ class Application_Service_ShowService if (is_null($this->ccShow)) { $ccShowDays = $this->getShowDaysInRange($populateUntil, $end); } else { - $ccShowDays = $this->ccShow->getCcShowDays(); + if ($this->ccShow->isRepeating()) { + $ccShowDays = $this->ccShow->getRepeatingCcShowDays(); + } else { + $ccShowDays = $this->ccShow->getCcShowDayss(); + } } if (!is_null($end)) { @@ -372,7 +404,7 @@ SQL; $daysAdded = array(); //CcShowDay object - $currentShowDay = $this->ccShow->getFirstCcShowDay(); + $currentShowDay = $this->ccShow->getFirstRepeatingCcShowDay(); //new end date in users' local time $endDateTime = $this->calculateEndDate($showData); @@ -420,7 +452,12 @@ SQL; //repeat type is the same, check if the days of the week are the same $repeatingDaysChanged = false; - $ccShowDays = $this->ccShow->getCcShowDays(); + if ($this->ccShow->isRepeating()) { + $ccShowDays = $this->ccShow->getRepeatingCcShowDays(); + } else { + $ccShowDays = $this->ccShow->getCcShowDayss(); + } + $showDays = array(); foreach ($ccShowDays as $day) { $showDays[] = $day->getDbDay(); @@ -710,6 +747,7 @@ SQL; $ccShowDay = CcShowDaysQuery::create() ->filterByDbShowId($showId) ->filterByDbDay($dayOfWeek) + ->filterByDbRepeatType(-1, Criteria::NOT_EQUAL) ->findOne(); if (isset($ccShowDay)) { @@ -725,10 +763,10 @@ SQL; } //remove the old repeating deleted instances. - CcShowInstancesQuery::create() + /*CcShowInstancesQuery::create() ->filterByDbShowId($showId) ->filterByDbModifiedInstance(true) - ->delete(); + ->delete();*/ } return false; @@ -915,6 +953,7 @@ SQL; $this->createRebroadcastInstances($showDay, $start, $ccShowInstance->getDbId()); } } + return $ccShowInstance; } /** @@ -971,6 +1010,9 @@ SQL; if ($this->isUpdate) { if ($this->hasInstance($utcStartDateTime)) { $ccShowInstance = $this->getInstance($utcStartDateTime); + if ($ccShowInstance->getDbModifiedInstance()) { + continue; + } $newInstance = false; $updateScheduleStatus = true; } else { @@ -1259,12 +1301,13 @@ SQL; $temp = clone($starts); $temp->setTimezone(new DateTimeZone($this->oldShowTimezone)); $temp->setTime($this->localShowStartHour, $this->localShowStartMin); + $temp->setTimezone(new DateTimeZone("UTC")); $ccShowInstance = CcShowInstancesQuery::create() ->filterByDbStarts($temp->format("Y-m-d H:i:s"), Criteria::EQUAL) ->filterByDbShowId($this->ccShow->getDbId(), Criteria::EQUAL) - ->filterByDbModifiedInstance(false, Criteria::EQUAL) + //->filterByDbModifiedInstance(false, Criteria::EQUAL) ->filterByDbRebroadcast(0, Criteria::EQUAL) ->limit(1) ->find(); @@ -1369,7 +1412,16 @@ SQL; // Don't set day for monthly repeat type, it's invalid if ($showData['add_show_repeats'] && $showData['add_show_repeat_type'] == 2) { - $showDay = new CcShowDays(); + + if ($this->isUpdate) { + $showDay = CcShowDaysQuery::create() + ->filterByDbShowId($showId) + ->filterByDbRepeatType($showData['add_show_repeat_type']) + ->findOne(); + } else { + $showDay = new CcShowDays(); + } + $showDay->setDbFirstShow($startDateTime->format("Y-m-d")); $showDay->setDbLastShow($endDate); $showDay->setDbStartTime($startDateTime->format("H:i:s")); @@ -1395,7 +1447,22 @@ SQL; $startDateTimeClone->add(new DateInterval("P".$daysAdd."D")); } if (is_null($endDate) || $startDateTimeClone->getTimestamp() <= $endDateTime->getTimestamp()) { - $showDay = new CcShowDays(); + + if ($this->isUpdate) { + $showDay = CcShowDaysQuery::create() + ->filterByDbShowId($showId) + ->filterByDbRepeatType($showData['add_show_repeat_type']) + ->filterByDbDay($day) + ->findOne(); + if (!$showDay) { + //if no show day object was found it is because a new + //repeating day of the week was added + $showDay = new CcShowDays(); + } + } else { + $showDay = new CcShowDays(); + } + $showDay->setDbFirstShow($startDateTimeClone->format("Y-m-d")); $showDay->setDbLastShow($endDate); $showDay->setDbStartTime($startDateTimeClone->format("H:i")); @@ -1562,6 +1629,7 @@ SQL; $repeatInfo = CcShowDaysQuery::create() ->filterByDbShowId($showId) ->filterByDbDay($day) + ->filterByDbRepeatType(-1, Criteria::NOT_EQUAL) ->findOne(); $repeatInfo->setDbNextPopDate($nextInfo[0]) diff --git a/airtime_mvc/public/js/airtime/schedule/full-calendar-functions.js b/airtime_mvc/public/js/airtime/schedule/full-calendar-functions.js index 53b725dd6..423dd1ff4 100644 --- a/airtime_mvc/public/js/airtime/schedule/full-calendar-functions.js +++ b/airtime_mvc/public/js/airtime/schedule/full-calendar-functions.js @@ -332,7 +332,7 @@ function eventResize( event, dayDelta, minuteDelta, revertFunc, jsEvent, ui, vie var url = baseUrl+'Schedule/resize-show/format/json'; $.post(url, - {day: dayDelta, min: minuteDelta, showId: event.showId}, + {day: dayDelta, min: minuteDelta, showId: event.showId, instanceId: event.id}, function(json){ if(json.show_error == true){ alertShowErrorAndReload(); From b4f016681e11481486de8e3305882bcbd08dc0d0 Mon Sep 17 00:00:00 2001 From: drigato Date: Mon, 2 Dec 2013 07:19:31 -0500 Subject: [PATCH 02/14] CC-5405: When editing a single show instance from a repeating series, should not create a new cc_show - Fixed resizing repeating shows to not include edited instances - Fixed context menu on repeating shows with edited instances - Fixed populated the show form when editing a single instance --- airtime_mvc/application/models/Show.php | 108 ++++++++++++++---- .../application/models/airtime/CcShow.php | 38 ++++++ .../application/services/CalendarService.php | 11 +- .../application/services/ShowService.php | 16 ++- 4 files changed, 146 insertions(+), 27 deletions(-) diff --git a/airtime_mvc/application/models/Show.php b/airtime_mvc/application/models/Show.php index 1b8253ad8..e725bc7a0 100644 --- a/airtime_mvc/application/models/Show.php +++ b/airtime_mvc/application/models/Show.php @@ -184,16 +184,84 @@ SQL; $nowDateTime = new DateTime("now", $utc); - $showInstances = CcShowInstancesQuery::create() - ->filterByDbShowId($this->_showId) - ->find($con); + //keep track of cc_show_day entries we need to update + $showDayIds = array(); + + /* + * If the resized show is an edited instance of a repeating show we + * need to treat it as a separate show and not resize the other instances + * + * Also, if the resized show has edited instances, we need to exclude + * those from the resize + */ + $ccShow = CcShowQuery::create()->findPk($this->_showId); + if ($ccShow->isRepeating()) { + + //convert instance to local timezone + $ccShowInstance = CcShowInstancesQuery::create()->findPk($instanceId); + $startsDT = new DateTime($ccShowInstance->getDbStarts(), + new DateTimeZone("UTC")); + $timezone = $ccShow->getFirstCcShowDay()->getDbTimezone(); + $startsDT->setTimezone(new DateTimeZone($timezone)); + + /* Get cc_show_day for the current instance. If we don't find one + * we know it is a repeat interval of one of cc_show_days first + * show and we can assume we aren't resizing a modified instance + */ + $ccShowDay = CcShowDaysQuery::create() + ->filterByDbFirstShow($startsDT->format("Y-m-d")) + ->filterByDbStartTime($startsDT->format("H:i:s")) + ->filterByDbShowId($this->_showId) + ->findOne(); + + /* Check if this cc_show_day rule is non-repeating. If it is, then + * we know this instance was edited out of the repeating sequence + */ + if (!$ccShowDay || $ccShowDay->getDbRepeatType() != -1) { + $ccShowDays = $ccShow->getRepeatingCcShowDays(); + foreach ($ccShowDays as $day) { + array_push($showDayIds, $day->getDbId()); + } + + $excludeIds = $ccShow->getEditedRepeatingInstanceIds(); + + //exlcude edited instances from resize + $showInstances = CcShowInstancesQuery::create() + ->filterByDbShowId($this->_showId) + ->filterByDbModifiedInstance(false) + ->filterByDbId($excludeIds, criteria::NOT_IN) + ->find(); + } elseif ($ccShowDay->getDbRepeatType() == -1) { + array_push($showDayIds, $ccShowDay->getDbId()); + + //treat edited instance as separate show for resize + $showInstances = CcShowInstancesQuery::create() + ->filterByDbId($instanceId) + ->find(); + } + } else { + $ccShowDays = $ccShow->getCcShowDayss(); + foreach ($ccShowDays as $day) { + array_push($showDayIds, $day->getDbId()); + } + + $showInstances = CcShowInstancesQuery::create() + ->filterByDbShowId($this->_showId) + ->find($con); + } /* Check two things: 1. If the show being resized and any of its repeats end in the past 2. If the show being resized and any of its repeats overlap with other scheduled shows */ + //keep track of instance ids for update show instances start/end times + $instanceIds = array(); + + //check if new show time overlaps with any other shows foreach ($showInstances as $si) { + array_push($instanceIds, $si->getDbId()); + $startsDateTime = new DateTime($si->getDbStarts(), new DateTimeZone("UTC")); $endsDateTime = new DateTime($si->getDbEnds(), new DateTimeZone("UTC")); @@ -204,19 +272,19 @@ SQL; $startsDateTime->setTimezone(new DateTimeZone(date_default_timezone_get())); $endsDateTime->setTimezone(new DateTimeZone(date_default_timezone_get())); - $newStartsDateTime = Application_Model_ShowInstance::addDeltas($startsDateTime, $deltaDay, $deltaMin); + //$newStartsDateTime = Application_Model_ShowInstance::addDeltas($startsDateTime, $deltaDay, $deltaMin); $newEndsDateTime = Application_Model_ShowInstance::addDeltas($endsDateTime, $deltaDay, $deltaMin); - + if ($newEndsDateTime->getTimestamp() < $nowDateTime->getTimestamp()) { return _("End date/time cannot be in the past"); } //convert our new starts/ends to UTC. - $newStartsDateTime->setTimezone($utc); + //$newStartsDateTime->setTimezone($utc); $newEndsDateTime->setTimezone($utc); $overlapping = Application_Model_Schedule::checkOverlappingShows( - $newStartsDateTime, $newEndsDateTime, true, $si->getDbId()); + $startsDateTime, $newEndsDateTime, true, $si->getDbId()); if ($overlapping) { return _("Cannot schedule overlapping shows.\nNote: Resizing a repeating show ". @@ -231,36 +299,30 @@ SQL; //current timesamp in UTC. $current_timestamp = gmdate("Y-m-d H:i:s"); - $sql_gen = << :current_timestamp1) - AND ((ends + :deltaDay2::INTERVAL + :interval2::INTERVAL - starts) <= interval '24:00') -SQL; + $sql_gen = "UPDATE cc_show_instances ". + "SET ends = (ends + :deltaDay1::INTERVAL + :interval1::INTERVAL) ". + "WHERE (id IN (".implode($instanceIds, ",").") ". + "AND ends > :current_timestamp1) ". + "AND ((ends + :deltaDay2::INTERVAL + :interval2::INTERVAL - starts) <= interval '24:00')"; Application_Common_Database::prepareAndExecute($sql_gen, array( ':deltaDay1' => "$deltaDay days", ':interval1' => "$hours:$mins", - ':show_id1' => $this->_showId, ':current_timestamp1' => $current_timestamp, ':deltaDay2' => "$deltaDay days", ':interval2' => "$hours:$mins" ), "execute"); - $sql_gen = << "$deltaDay days", ':interval3' => "$hours:$mins", - ':show_id2' => $this->_showId, ':deltaDay4' => "$deltaDay days", ':interval4' => "$hours:$mins" ), "execute"); @@ -279,7 +341,7 @@ SQL; $instances = CcShowInstancesQuery::create() ->filterByDbEnds($current_timestamp, Criteria::GREATER_THAN) - ->filterByDbShowId($this->_showId) + ->filterByDbId($instanceIds, Criteria::IN) ->find($con); foreach ($instances as $instance) { diff --git a/airtime_mvc/application/models/airtime/CcShow.php b/airtime_mvc/application/models/airtime/CcShow.php index c58042006..99c5aaa75 100644 --- a/airtime_mvc/application/models/airtime/CcShow.php +++ b/airtime_mvc/application/models/airtime/CcShow.php @@ -109,6 +109,44 @@ class CcShow extends BaseCcShow { return false; } + /** + * Returns all cc_show_instances that have been edited out of + * a repeating sequence + */ + public function getEditedRepeatingInstanceIds() + { + //get cc_show_days that have been edited (not repeating) + $ccShowDays = CcShowDaysQuery::create() + ->filterByDbShowId($this->id) + ->filterByDbRepeatType(-1) + ->find(); + + $startsUTC = array(); + + $utc = new DateTimeZone("UTC"); + foreach ($ccShowDays as $day) { + //convert to UTC + $starts = new DateTime( + $day->getDbFirstShow()." ".$day->getDbStartTime(), + new DateTimeZone($day->getDbTimezone()) + ); + $starts->setTimezone($utc); + array_push($startsUTC, $starts->format("Y-m-d H:i:s")); + } + + $excludeInstances = CcShowInstancesQuery::create() + ->filterByDbShowId($this->id) + ->filterByDbStarts($startsUTC, criteria::IN) + ->find(); + + $excludeIds = array(); + foreach ($excludeInstances as $instance) { + array_push($excludeIds, $instance->getDbId()); + } + + return $excludeIds; + } + /** * Gets an array of CcShowInstances objects which contain a foreign key that references this object. * diff --git a/airtime_mvc/application/services/CalendarService.php b/airtime_mvc/application/services/CalendarService.php index 3c3a85b6c..45c42a837 100644 --- a/airtime_mvc/application/services/CalendarService.php +++ b/airtime_mvc/application/services/CalendarService.php @@ -126,7 +126,15 @@ class Application_Service_CalendarService } } - $isRepeating = $this->ccShow->getFirstCcShowDay()->isRepeating(); + $excludeIds = $this->ccShow->getEditedRepeatingInstanceIds(); + + $isRepeating = true; + $populateInstance = false; + if (in_array($this->ccShowInstance->getDbId(), $excludeIds)) { + $populateInstance = true; + $isRepeating = false; + } + if (!$this->ccShowInstance->isRebroadcast() && $isAdminOrPM) { if ($isRepeating) { $menu["edit"] = array( @@ -143,6 +151,7 @@ class Application_Service_CalendarService "name" => _("Edit This Instance"), "icon" => "edit", "url" => $baseUrl."Schedule/populate-repeating-show-instance-form"); + } else { $menu["edit"] = array( "name"=> _("Edit Show"), diff --git a/airtime_mvc/application/services/ShowService.php b/airtime_mvc/application/services/ShowService.php index 5dc505882..472601dfc 100644 --- a/airtime_mvc/application/services/ShowService.php +++ b/airtime_mvc/application/services/ShowService.php @@ -159,7 +159,11 @@ class Application_Service_ShowService */ private function storeOrigLocalShowInfo() { - $this->origCcShowDay = $this->ccShow->getFirstRepeatingCcShowDay(); + if ($this->ccShow->isRepeating()) { + $this->origCcShowDay = $this->ccShow->getFirstRepeatingCcShowDay(); + } else { + $this->origCcShowDay = $this->ccShow->getFirstCcShowDay(); + } $this->oldShowTimezone = $this->origCcShowDay->getDbTimezone(); @@ -404,7 +408,11 @@ SQL; $daysAdded = array(); //CcShowDay object - $currentShowDay = $this->ccShow->getFirstRepeatingCcShowDay(); + if ($this->ccShow->isRepeating()) { + $currentShowDay = $this->ccShow->getFirstRepeatingCcShowDay(); + } else { + $currentShowDay = $this->ccShow->getFirstCcShowDay(); + } //new end date in users' local time $endDateTime = $this->calculateEndDate($showData); @@ -1387,6 +1395,8 @@ SQL; */ private function setCcShowDays($showData) { + Logging::info($showData); + Logging::info($this->repeatType); $showId = $this->ccShow->getDbId(); $startDateTime = new DateTime($showData['add_show_start_date']." ".$showData['add_show_start_time']); @@ -1451,7 +1461,7 @@ SQL; if ($this->isUpdate) { $showDay = CcShowDaysQuery::create() ->filterByDbShowId($showId) - ->filterByDbRepeatType($showData['add_show_repeat_type']) + ->filterByDbRepeatType($this->repeatType) ->filterByDbDay($day) ->findOne(); if (!$showDay) { From d967e36c453671f7228a7360fc692fdf404f7bd2 Mon Sep 17 00:00:00 2001 From: drigato Date: Mon, 2 Dec 2013 13:13:41 -0500 Subject: [PATCH 03/14] Fixed minor bugs --- .../application/services/CalendarService.php | 6 ++- .../application/services/ShowService.php | 37 +++++++++++++------ 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/airtime_mvc/application/services/CalendarService.php b/airtime_mvc/application/services/CalendarService.php index 45c42a837..edb76ebf5 100644 --- a/airtime_mvc/application/services/CalendarService.php +++ b/airtime_mvc/application/services/CalendarService.php @@ -151,7 +151,11 @@ class Application_Service_CalendarService "name" => _("Edit This Instance"), "icon" => "edit", "url" => $baseUrl."Schedule/populate-repeating-show-instance-form"); - + } elseif ($populateInstance) { + $menu["edit"] = array( + "name" => _("Edit Show"), + "icon" => "edit", + "url" => $baseUrl."Schedule/populate-repeating-show-instance-form"); } else { $menu["edit"] = array( "name"=> _("Edit Show"), diff --git a/airtime_mvc/application/services/ShowService.php b/airtime_mvc/application/services/ShowService.php index 472601dfc..b2bb071a2 100644 --- a/airtime_mvc/application/services/ShowService.php +++ b/airtime_mvc/application/services/ShowService.php @@ -83,12 +83,6 @@ class Application_Service_ShowService } /****** UPDATE SCHEDULE START TIME ENDS******/ - /* - * Set the new cc_show_day record - * Associates it with the current show_id and sets it to non-repeating - */ - $this->setCcShowDays($showData); - /* * In the case where an instance is being edited for a second * (or third, fourth, etc.) time we need to delete the old @@ -108,6 +102,18 @@ class Application_Service_ShowService ->filterByDbStartTime($origLocalStartDateTime->format("H:i:s")) ->delete(); + /* + * Set the new cc_show_day record + * Associates it with the current show_id and sets it to non-repeating + */ + $this->setCcShowDays($showData); + + /* + * Set the new cc_show_day record + * Associates it with the current show_id and sets it to non-repeating + */ + $this->setCcShowDays($showData); + // DO WE NEED THIS? $this->setCcShowHosts($showData); @@ -120,7 +126,7 @@ class Application_Service_ShowService ->filterByDbShowId($showId) ->filterByDbRepeatType(-1) ->filterByDbFirstShow($showData["add_show_start_date"]) - ->filterByDbStartTime($showData["add_show_start_time"]) + ->filterByDbStartTime($showData["add_show_start_time"].":00") ->findOne(); $ccShowInstance = $this->createNonRepeatingInstance($showDay, @@ -138,6 +144,7 @@ class Application_Service_ShowService ->setDbLastScheduled(gmdate("Y-m-d H:i:s")) ->save(); $ccShowInstance->updateDbTimeFilled($con); + $ccShowInstance->updateScheduleStatus($con); //delete the edited instance from the repeating sequence $ccShowInstanceOrig->setDbModifiedInstance(true)->save(); @@ -190,6 +197,7 @@ class Application_Service_ShowService $this->setCcShow($showData); $daysAdded = array(); + if ($this->isUpdate) { $daysAdded = $this->delegateInstanceCleanup($showData); @@ -456,7 +464,8 @@ SQL; //and the repeat type changed if ($currentRepeatType != -1 && $this->repeatType != $currentRepeatType) { $this->deleteAllInstances($showId); - } else { + // when repeating by day of the month (1st, 2nd, etc.) we do not store the repeat week days + } elseif ($currentRepeatType != 2) { //repeat type is the same, check if the days of the week are the same $repeatingDaysChanged = false; @@ -1018,7 +1027,9 @@ SQL; if ($this->isUpdate) { if ($this->hasInstance($utcStartDateTime)) { $ccShowInstance = $this->getInstance($utcStartDateTime); - if ($ccShowInstance->getDbModifiedInstance()) { + // don't update instances that have been edited out of the repeating sequence + if ($ccShowInstance->getDbModifiedInstance() || + in_array($ccShowInstance->getDbId(), $this->ccShow->getEditedRepeatingInstanceIds())) { continue; } $newInstance = false; @@ -1114,6 +1125,11 @@ SQL; */ if ($this->isUpdate && $this->hasInstance($utcStartDateTime)) { $ccShowInstance = $this->getInstance($utcStartDateTime); + // don't update instances that have been edited out of the repeating sequence + if ($ccShowInstance->getDbModifiedInstance() || + in_array($ccShowInstance->getDbId(), $this->ccShow->getEditedRepeatingInstanceIds())) { + continue; + } $newInstance = false; $updateScheduleStatus = true; } else { @@ -1395,8 +1411,6 @@ SQL; */ private function setCcShowDays($showData) { - Logging::info($showData); - Logging::info($this->repeatType); $showId = $this->ccShow->getDbId(); $startDateTime = new DateTime($showData['add_show_start_date']." ".$showData['add_show_start_time']); @@ -1424,6 +1438,7 @@ SQL; if ($showData['add_show_repeats'] && $showData['add_show_repeat_type'] == 2) { if ($this->isUpdate) { + //Logging::info(CcShowDaysQuery::create()->find()); $showDay = CcShowDaysQuery::create() ->filterByDbShowId($showId) ->filterByDbRepeatType($showData['add_show_repeat_type']) From bc695e69d1bd6c9fbc67640cc696bad34b2ab18d Mon Sep 17 00:00:00 2001 From: drigato Date: Mon, 2 Dec 2013 13:28:25 -0500 Subject: [PATCH 04/14] Copy/paste error Was setting cc_show_days twice --- airtime_mvc/application/services/ShowService.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/airtime_mvc/application/services/ShowService.php b/airtime_mvc/application/services/ShowService.php index b2bb071a2..32b018f6a 100644 --- a/airtime_mvc/application/services/ShowService.php +++ b/airtime_mvc/application/services/ShowService.php @@ -108,12 +108,6 @@ class Application_Service_ShowService */ $this->setCcShowDays($showData); - /* - * Set the new cc_show_day record - * Associates it with the current show_id and sets it to non-repeating - */ - $this->setCcShowDays($showData); - // DO WE NEED THIS? $this->setCcShowHosts($showData); @@ -1438,7 +1432,6 @@ SQL; if ($showData['add_show_repeats'] && $showData['add_show_repeat_type'] == 2) { if ($this->isUpdate) { - //Logging::info(CcShowDaysQuery::create()->find()); $showDay = CcShowDaysQuery::create() ->filterByDbShowId($showId) ->filterByDbRepeatType($showData['add_show_repeat_type']) From a465b5a7702c7b4ec5392b0b990b250222922c77 Mon Sep 17 00:00:00 2001 From: drigato Date: Thu, 28 Nov 2013 17:17:00 -0500 Subject: [PATCH 05/14] CC-5405: When editing a single show instance from a repeating series, should not create a new cc_show Create a new cc_show_day rule instead of a new cc_show --- .../controllers/ScheduleController.php | 3 +- airtime_mvc/application/models/Show.php | 6 +- .../application/models/airtime/CcShow.php | 59 ++++++- .../application/services/ShowFormService.php | 12 +- .../application/services/ShowService.php | 148 +++++++++++++----- .../schedule/full-calendar-functions.js | 2 +- 6 files changed, 181 insertions(+), 49 deletions(-) diff --git a/airtime_mvc/application/controllers/ScheduleController.php b/airtime_mvc/application/controllers/ScheduleController.php index f18fc9fff..ed13d68d1 100644 --- a/airtime_mvc/application/controllers/ScheduleController.php +++ b/airtime_mvc/application/controllers/ScheduleController.php @@ -183,6 +183,7 @@ class ScheduleController extends Zend_Controller_Action $deltaDay = $this->_getParam('day'); $deltaMin = $this->_getParam('min'); $showId = $this->_getParam('showId'); + $instanceId = $this->_getParam('instanceId'); $userInfo = Zend_Auth::getInstance()->getStorage()->read(); $user = new Application_Model_User($userInfo->id); @@ -195,7 +196,7 @@ class ScheduleController extends Zend_Controller_Action return false; } - $error = $show->resizeShow($deltaDay, $deltaMin); + $error = $show->resizeShow($deltaDay, $deltaMin, $instanceId); } if (isset($error)) { diff --git a/airtime_mvc/application/models/Show.php b/airtime_mvc/application/models/Show.php index 123a26a99..1b8253ad8 100644 --- a/airtime_mvc/application/models/Show.php +++ b/airtime_mvc/application/models/Show.php @@ -172,16 +172,16 @@ SQL; $show->delete(); } - public function resizeShow($deltaDay, $deltaMin) + public function resizeShow($deltaDay, $deltaMin, $instanceId) { $con = Propel::getConnection(); if ($deltaDay > 0) { return _("Shows can have a max length of 24 hours."); } - + $utc = new DateTimeZone("UTC"); - + $nowDateTime = new DateTime("now", $utc); $showInstances = CcShowInstancesQuery::create() diff --git a/airtime_mvc/application/models/airtime/CcShow.php b/airtime_mvc/application/models/airtime/CcShow.php index 028ec6fea..c58042006 100644 --- a/airtime_mvc/application/models/airtime/CcShow.php +++ b/airtime_mvc/application/models/airtime/CcShow.php @@ -15,8 +15,20 @@ */ class CcShow extends BaseCcShow { - public function getCcShowDays(){ - return CcShowDaysQuery::create()->filterByDbShowId($this->getDbId())->find(); + /* + * Returns all cc_show_day rules that belong to a cc_show and that are + * repeating. + * We do this because editing a single instance from a repeating sequence + * creates a new rule in cc_show_days with the same cc_show id and a repeat + * type of -1 (non-repeating). + * So when the entire cc_show is updated after that, the single edited + * instance can remain separate from the rest of the instances + */ + public function getRepeatingCcShowDays(){ + return CcShowDaysQuery::create() + ->filterByDbShowId($this->id) + ->filterByDbRepeatType(-1, Criteria::NOT_EQUAL) + ->find(); } /** @@ -54,6 +66,49 @@ class CcShow extends BaseCcShow { return $this->collCcShowDayss[0]; } + /** + * + * A repeating show may have a rule in cc_show_days with a repeat type + * of -1 (not repeating). This happens when a single instances was edited + * from the repeating sequence. + * + * When the repeating show gets edited in this case, we want to exclude all + * the edited instances from the update. We do this by not returning any of + * the cc_show_day rules with a -1 repeat type. + */ + public function getFirstRepeatingCcShowDay() + { + return CcShowDaysQuery::create() + ->filterByDbShowId($this->id) + ->filterByDbRepeatType(-1, Criteria::NOT_EQUAL) + ->orderByDbFirstShow() + ->findOne(); + } + + /** + * + * In order to determine if a show is repeating we need to check each + * cc_show_day entry and check if there are any non -1 repeat types. + * Because editing a single instances creates a new cc_show_day rule + * with a -1 (non repeating) repeat type we need to check all cc_show_day + * entries + */ + public function isRepeating() + { + //get ALL cc_show_day entries + $ccShowDays = CcShowDaysQuery::create() + ->filterByDbShowId($this->id) + ->find(); + + foreach ($ccShowDays as $day) { + if ($day->getDbRepeatType() >= 0) { + return true; + } + } + + return false; + } + /** * Gets an array of CcShowInstances objects which contain a foreign key that references this object. * diff --git a/airtime_mvc/application/services/ShowFormService.php b/airtime_mvc/application/services/ShowFormService.php index 0fa705f2a..85b9868c0 100644 --- a/airtime_mvc/application/services/ShowFormService.php +++ b/airtime_mvc/application/services/ShowFormService.php @@ -124,7 +124,11 @@ class Application_Service_ShowFormService private function populateFormWhen($form) { - $ccShowDay = $this->ccShow->getFirstCcShowDay(); + if ($this->ccShow->isRepeating()) { + $ccShowDay = $this->ccShow->getFirstRepeatingCcShowDay(); + } else { + $ccShowDay = $this->ccShow->getFirstCcShowDay(); + } $showStart = $ccShowDay->getLocalStartDateAndTime(); $showEnd = $ccShowDay->getLocalEndDateAndTime($showStart); @@ -198,7 +202,11 @@ class Application_Service_ShowFormService */ private function populateFormRepeats($form, $nextFutureShowStart) { - $ccShowDays = $this->ccShow->getCcShowDays(); + if ($this->ccShow->isRepeating()) { + $ccShowDays = $this->ccShow->getRepeatingCcShowDays(); + } else { + $ccShowDays = $this->ccShow->getCcShowDayss(); + } $days = array(); foreach ($ccShowDays as $ccShowDay) { diff --git a/airtime_mvc/application/services/ShowService.php b/airtime_mvc/application/services/ShowService.php index 303236e9f..5dc505882 100644 --- a/airtime_mvc/application/services/ShowService.php +++ b/airtime_mvc/application/services/ShowService.php @@ -55,11 +55,13 @@ class Application_Service_ShowService throw new Exception("Permission denied"); } + $showId = $showData["add_show_id"]; + /****** UPDATE SCHEDULE START TIME ******/ //get the ccShow object to which this instance belongs //so we can get the original start date and time - $oldCcShow = CcShowQuery::create() - ->findPk($showData["add_show_id"]); + $this->ccShow = CcShowQuery::create() + ->findPk($showId); //DateTime in shows's local time $newStartDateTime = new DateTime($showData["add_show_start_date"]." ". @@ -68,52 +70,78 @@ class Application_Service_ShowService $ccShowInstanceOrig = CcShowInstancesQuery::create() ->findPk($showData["add_show_instance_id"]); - $diff = $this->calculateShowStartDiff($newStartDateTime, - $ccShowInstanceOrig->getLocalStartDateTime()); - if ($diff > 0) { + //convert original start time into the show's local timezone + $origLocalStartDateTime = $ccShowInstanceOrig->getLocalStartDateTime(); + + $diff = $this->calculateShowStartDiff($newStartDateTime, + $origLocalStartDateTime); + + if ($diff != 0) { Application_Service_SchedulerService::updateScheduleStartTime( array($showData["add_show_instance_id"]), $diff); } /****** UPDATE SCHEDULE START TIME ENDS******/ - $this->setCcShow($showData); + /* + * Set the new cc_show_day record + * Associates it with the current show_id and sets it to non-repeating + */ $this->setCcShowDays($showData); - $this->setCcShowHosts($showData); - $this->delegateInstanceCreation(); - //get the new instance id - $ccShowInstance = CcShowInstancesQuery::create() - ->filterByDbShowId($this->ccShow->getDbId()) + /* + * In the case where an instance is being edited for a second + * (or third, fourth, etc.) time we need to delete the old + * cc_show_day record + * + * Since we don't store the cc_show_day ids we need to use the + * original start time from cc_show_instances, convert it to the show's + * local timezone, and find the record in cc_show_days + * + * *** There is a flaw here: We have to assume the show timezone has + * *** not changed (make timezone readonly??) + */ + $origCcShowDay = CcShowDaysQuery::create() + ->filterByDbShowId($showId) + ->filterByDbRepeatType(-1) + ->filterByDbFirstShow($origLocalStartDateTime->format("Y-m-d")) + ->filterByDbStartTime($origLocalStartDateTime->format("H:i:s")) + ->delete(); + + // DO WE NEED THIS? + $this->setCcShowHosts($showData); + + /* + * We need to find the new show day rule we just created by passing + * in the first show and start time in case multiple single + * instances have been edited out of the repeating sequence. + */ + $showDay = CcShowDaysQuery::create() + ->filterByDbShowId($showId) + ->filterByDbRepeatType(-1) + ->filterByDbFirstShow($showData["add_show_start_date"]) + ->filterByDbStartTime($showData["add_show_start_time"]) ->findOne(); - $newInstanceId = $ccShowInstance->getDbId(); + $ccShowInstance = $this->createNonRepeatingInstance($showDay, + $this->getPopulateShowUntilDateTIme()); //update cc_schedule with the new instance id - $ccSchedules = CcScheduleQuery::create() - ->filterByDbInstanceId($showData["add_show_instance_id"]) - ->find(); - - foreach ($ccSchedules as $ccSchedule) { - $ccSchedule->setDbInstanceId($newInstanceId); - $ccSchedule->save(); - } - $con = Propel::getConnection(CcShowInstancesPeer::DATABASE_NAME); + $selectCriteria = new Criteria(); + $selectCriteria->add(CcSchedulePeer::INSTANCE_ID, $showData["add_show_instance_id"]); + $updateCriteria = new Criteria(); + $updateCriteria->add(CcSchedulePeer::INSTANCE_ID, $ccShowInstance->getDbId()); + BasePeer::doUpdate($selectCriteria, $updateCriteria, $con); + + $ccShowInstance + ->setDbLastScheduled(gmdate("Y-m-d H:i:s")) + ->save(); $ccShowInstance->updateDbTimeFilled($con); //delete the edited instance from the repeating sequence $ccShowInstanceOrig->setDbModifiedInstance(true)->save(); - $service_showForm = new Application_Service_ShowFormService($showData["add_show_id"]); - list($start, $end) = $service_showForm->getNextFutureRepeatShowTime(); - $oldCcShowDay = $oldCcShow->getFirstCcShowDay(); - $oldCcShowDay - ->setDbFirstShow( - $start->setTimezone(new DateTimeZone( - $oldCcShowDay->getDbTimezone()))->format("Y-m-d")) - ->save(); - $con->commit(); Application_Model_RabbitMq::PushSchedule(); } catch (Exception $e) { @@ -131,7 +159,7 @@ class Application_Service_ShowService */ private function storeOrigLocalShowInfo() { - $this->origCcShowDay = $this->ccShow->getFirstCcShowDay(); + $this->origCcShowDay = $this->ccShow->getFirstRepeatingCcShowDay(); $this->oldShowTimezone = $this->origCcShowDay->getDbTimezone(); @@ -165,7 +193,7 @@ class Application_Service_ShowService $this->deleteRebroadcastInstances(); - $this->deleteCcShowDays(); + //$this->deleteCcShowDays(); $this->deleteCcShowHosts(); if ($this->isRebroadcast) { //delete entry in cc_show_rebroadcast @@ -225,7 +253,11 @@ class Application_Service_ShowService if (is_null($this->ccShow)) { $ccShowDays = $this->getShowDaysInRange($populateUntil, $end); } else { - $ccShowDays = $this->ccShow->getCcShowDays(); + if ($this->ccShow->isRepeating()) { + $ccShowDays = $this->ccShow->getRepeatingCcShowDays(); + } else { + $ccShowDays = $this->ccShow->getCcShowDayss(); + } } if (!is_null($end)) { @@ -372,7 +404,7 @@ SQL; $daysAdded = array(); //CcShowDay object - $currentShowDay = $this->ccShow->getFirstCcShowDay(); + $currentShowDay = $this->ccShow->getFirstRepeatingCcShowDay(); //new end date in users' local time $endDateTime = $this->calculateEndDate($showData); @@ -420,7 +452,12 @@ SQL; //repeat type is the same, check if the days of the week are the same $repeatingDaysChanged = false; - $ccShowDays = $this->ccShow->getCcShowDays(); + if ($this->ccShow->isRepeating()) { + $ccShowDays = $this->ccShow->getRepeatingCcShowDays(); + } else { + $ccShowDays = $this->ccShow->getCcShowDayss(); + } + $showDays = array(); foreach ($ccShowDays as $day) { $showDays[] = $day->getDbDay(); @@ -710,6 +747,7 @@ SQL; $ccShowDay = CcShowDaysQuery::create() ->filterByDbShowId($showId) ->filterByDbDay($dayOfWeek) + ->filterByDbRepeatType(-1, Criteria::NOT_EQUAL) ->findOne(); if (isset($ccShowDay)) { @@ -725,10 +763,10 @@ SQL; } //remove the old repeating deleted instances. - CcShowInstancesQuery::create() + /*CcShowInstancesQuery::create() ->filterByDbShowId($showId) ->filterByDbModifiedInstance(true) - ->delete(); + ->delete();*/ } return false; @@ -915,6 +953,7 @@ SQL; $this->createRebroadcastInstances($showDay, $start, $ccShowInstance->getDbId()); } } + return $ccShowInstance; } /** @@ -971,6 +1010,9 @@ SQL; if ($this->isUpdate) { if ($this->hasInstance($utcStartDateTime)) { $ccShowInstance = $this->getInstance($utcStartDateTime); + if ($ccShowInstance->getDbModifiedInstance()) { + continue; + } $newInstance = false; $updateScheduleStatus = true; } else { @@ -1259,12 +1301,13 @@ SQL; $temp = clone($starts); $temp->setTimezone(new DateTimeZone($this->oldShowTimezone)); $temp->setTime($this->localShowStartHour, $this->localShowStartMin); + $temp->setTimezone(new DateTimeZone("UTC")); $ccShowInstance = CcShowInstancesQuery::create() ->filterByDbStarts($temp->format("Y-m-d H:i:s"), Criteria::EQUAL) ->filterByDbShowId($this->ccShow->getDbId(), Criteria::EQUAL) - ->filterByDbModifiedInstance(false, Criteria::EQUAL) + //->filterByDbModifiedInstance(false, Criteria::EQUAL) ->filterByDbRebroadcast(0, Criteria::EQUAL) ->limit(1) ->find(); @@ -1369,7 +1412,16 @@ SQL; // Don't set day for monthly repeat type, it's invalid if ($showData['add_show_repeats'] && $showData['add_show_repeat_type'] == 2) { - $showDay = new CcShowDays(); + + if ($this->isUpdate) { + $showDay = CcShowDaysQuery::create() + ->filterByDbShowId($showId) + ->filterByDbRepeatType($showData['add_show_repeat_type']) + ->findOne(); + } else { + $showDay = new CcShowDays(); + } + $showDay->setDbFirstShow($startDateTime->format("Y-m-d")); $showDay->setDbLastShow($endDate); $showDay->setDbStartTime($startDateTime->format("H:i:s")); @@ -1395,7 +1447,22 @@ SQL; $startDateTimeClone->add(new DateInterval("P".$daysAdd."D")); } if (is_null($endDate) || $startDateTimeClone->getTimestamp() <= $endDateTime->getTimestamp()) { - $showDay = new CcShowDays(); + + if ($this->isUpdate) { + $showDay = CcShowDaysQuery::create() + ->filterByDbShowId($showId) + ->filterByDbRepeatType($showData['add_show_repeat_type']) + ->filterByDbDay($day) + ->findOne(); + if (!$showDay) { + //if no show day object was found it is because a new + //repeating day of the week was added + $showDay = new CcShowDays(); + } + } else { + $showDay = new CcShowDays(); + } + $showDay->setDbFirstShow($startDateTimeClone->format("Y-m-d")); $showDay->setDbLastShow($endDate); $showDay->setDbStartTime($startDateTimeClone->format("H:i")); @@ -1562,6 +1629,7 @@ SQL; $repeatInfo = CcShowDaysQuery::create() ->filterByDbShowId($showId) ->filterByDbDay($day) + ->filterByDbRepeatType(-1, Criteria::NOT_EQUAL) ->findOne(); $repeatInfo->setDbNextPopDate($nextInfo[0]) diff --git a/airtime_mvc/public/js/airtime/schedule/full-calendar-functions.js b/airtime_mvc/public/js/airtime/schedule/full-calendar-functions.js index 53b725dd6..423dd1ff4 100644 --- a/airtime_mvc/public/js/airtime/schedule/full-calendar-functions.js +++ b/airtime_mvc/public/js/airtime/schedule/full-calendar-functions.js @@ -332,7 +332,7 @@ function eventResize( event, dayDelta, minuteDelta, revertFunc, jsEvent, ui, vie var url = baseUrl+'Schedule/resize-show/format/json'; $.post(url, - {day: dayDelta, min: minuteDelta, showId: event.showId}, + {day: dayDelta, min: minuteDelta, showId: event.showId, instanceId: event.id}, function(json){ if(json.show_error == true){ alertShowErrorAndReload(); From ef8af1b72471b0b6c3702a396d603423a6d886a7 Mon Sep 17 00:00:00 2001 From: drigato Date: Mon, 2 Dec 2013 07:19:31 -0500 Subject: [PATCH 06/14] CC-5405: When editing a single show instance from a repeating series, should not create a new cc_show - Fixed resizing repeating shows to not include edited instances - Fixed context menu on repeating shows with edited instances - Fixed populated the show form when editing a single instance --- airtime_mvc/application/models/Show.php | 108 ++++++++++++++---- .../application/models/airtime/CcShow.php | 38 ++++++ .../application/services/CalendarService.php | 11 +- .../application/services/ShowService.php | 16 ++- 4 files changed, 146 insertions(+), 27 deletions(-) diff --git a/airtime_mvc/application/models/Show.php b/airtime_mvc/application/models/Show.php index 1b8253ad8..e725bc7a0 100644 --- a/airtime_mvc/application/models/Show.php +++ b/airtime_mvc/application/models/Show.php @@ -184,16 +184,84 @@ SQL; $nowDateTime = new DateTime("now", $utc); - $showInstances = CcShowInstancesQuery::create() - ->filterByDbShowId($this->_showId) - ->find($con); + //keep track of cc_show_day entries we need to update + $showDayIds = array(); + + /* + * If the resized show is an edited instance of a repeating show we + * need to treat it as a separate show and not resize the other instances + * + * Also, if the resized show has edited instances, we need to exclude + * those from the resize + */ + $ccShow = CcShowQuery::create()->findPk($this->_showId); + if ($ccShow->isRepeating()) { + + //convert instance to local timezone + $ccShowInstance = CcShowInstancesQuery::create()->findPk($instanceId); + $startsDT = new DateTime($ccShowInstance->getDbStarts(), + new DateTimeZone("UTC")); + $timezone = $ccShow->getFirstCcShowDay()->getDbTimezone(); + $startsDT->setTimezone(new DateTimeZone($timezone)); + + /* Get cc_show_day for the current instance. If we don't find one + * we know it is a repeat interval of one of cc_show_days first + * show and we can assume we aren't resizing a modified instance + */ + $ccShowDay = CcShowDaysQuery::create() + ->filterByDbFirstShow($startsDT->format("Y-m-d")) + ->filterByDbStartTime($startsDT->format("H:i:s")) + ->filterByDbShowId($this->_showId) + ->findOne(); + + /* Check if this cc_show_day rule is non-repeating. If it is, then + * we know this instance was edited out of the repeating sequence + */ + if (!$ccShowDay || $ccShowDay->getDbRepeatType() != -1) { + $ccShowDays = $ccShow->getRepeatingCcShowDays(); + foreach ($ccShowDays as $day) { + array_push($showDayIds, $day->getDbId()); + } + + $excludeIds = $ccShow->getEditedRepeatingInstanceIds(); + + //exlcude edited instances from resize + $showInstances = CcShowInstancesQuery::create() + ->filterByDbShowId($this->_showId) + ->filterByDbModifiedInstance(false) + ->filterByDbId($excludeIds, criteria::NOT_IN) + ->find(); + } elseif ($ccShowDay->getDbRepeatType() == -1) { + array_push($showDayIds, $ccShowDay->getDbId()); + + //treat edited instance as separate show for resize + $showInstances = CcShowInstancesQuery::create() + ->filterByDbId($instanceId) + ->find(); + } + } else { + $ccShowDays = $ccShow->getCcShowDayss(); + foreach ($ccShowDays as $day) { + array_push($showDayIds, $day->getDbId()); + } + + $showInstances = CcShowInstancesQuery::create() + ->filterByDbShowId($this->_showId) + ->find($con); + } /* Check two things: 1. If the show being resized and any of its repeats end in the past 2. If the show being resized and any of its repeats overlap with other scheduled shows */ + //keep track of instance ids for update show instances start/end times + $instanceIds = array(); + + //check if new show time overlaps with any other shows foreach ($showInstances as $si) { + array_push($instanceIds, $si->getDbId()); + $startsDateTime = new DateTime($si->getDbStarts(), new DateTimeZone("UTC")); $endsDateTime = new DateTime($si->getDbEnds(), new DateTimeZone("UTC")); @@ -204,19 +272,19 @@ SQL; $startsDateTime->setTimezone(new DateTimeZone(date_default_timezone_get())); $endsDateTime->setTimezone(new DateTimeZone(date_default_timezone_get())); - $newStartsDateTime = Application_Model_ShowInstance::addDeltas($startsDateTime, $deltaDay, $deltaMin); + //$newStartsDateTime = Application_Model_ShowInstance::addDeltas($startsDateTime, $deltaDay, $deltaMin); $newEndsDateTime = Application_Model_ShowInstance::addDeltas($endsDateTime, $deltaDay, $deltaMin); - + if ($newEndsDateTime->getTimestamp() < $nowDateTime->getTimestamp()) { return _("End date/time cannot be in the past"); } //convert our new starts/ends to UTC. - $newStartsDateTime->setTimezone($utc); + //$newStartsDateTime->setTimezone($utc); $newEndsDateTime->setTimezone($utc); $overlapping = Application_Model_Schedule::checkOverlappingShows( - $newStartsDateTime, $newEndsDateTime, true, $si->getDbId()); + $startsDateTime, $newEndsDateTime, true, $si->getDbId()); if ($overlapping) { return _("Cannot schedule overlapping shows.\nNote: Resizing a repeating show ". @@ -231,36 +299,30 @@ SQL; //current timesamp in UTC. $current_timestamp = gmdate("Y-m-d H:i:s"); - $sql_gen = << :current_timestamp1) - AND ((ends + :deltaDay2::INTERVAL + :interval2::INTERVAL - starts) <= interval '24:00') -SQL; + $sql_gen = "UPDATE cc_show_instances ". + "SET ends = (ends + :deltaDay1::INTERVAL + :interval1::INTERVAL) ". + "WHERE (id IN (".implode($instanceIds, ",").") ". + "AND ends > :current_timestamp1) ". + "AND ((ends + :deltaDay2::INTERVAL + :interval2::INTERVAL - starts) <= interval '24:00')"; Application_Common_Database::prepareAndExecute($sql_gen, array( ':deltaDay1' => "$deltaDay days", ':interval1' => "$hours:$mins", - ':show_id1' => $this->_showId, ':current_timestamp1' => $current_timestamp, ':deltaDay2' => "$deltaDay days", ':interval2' => "$hours:$mins" ), "execute"); - $sql_gen = << "$deltaDay days", ':interval3' => "$hours:$mins", - ':show_id2' => $this->_showId, ':deltaDay4' => "$deltaDay days", ':interval4' => "$hours:$mins" ), "execute"); @@ -279,7 +341,7 @@ SQL; $instances = CcShowInstancesQuery::create() ->filterByDbEnds($current_timestamp, Criteria::GREATER_THAN) - ->filterByDbShowId($this->_showId) + ->filterByDbId($instanceIds, Criteria::IN) ->find($con); foreach ($instances as $instance) { diff --git a/airtime_mvc/application/models/airtime/CcShow.php b/airtime_mvc/application/models/airtime/CcShow.php index c58042006..99c5aaa75 100644 --- a/airtime_mvc/application/models/airtime/CcShow.php +++ b/airtime_mvc/application/models/airtime/CcShow.php @@ -109,6 +109,44 @@ class CcShow extends BaseCcShow { return false; } + /** + * Returns all cc_show_instances that have been edited out of + * a repeating sequence + */ + public function getEditedRepeatingInstanceIds() + { + //get cc_show_days that have been edited (not repeating) + $ccShowDays = CcShowDaysQuery::create() + ->filterByDbShowId($this->id) + ->filterByDbRepeatType(-1) + ->find(); + + $startsUTC = array(); + + $utc = new DateTimeZone("UTC"); + foreach ($ccShowDays as $day) { + //convert to UTC + $starts = new DateTime( + $day->getDbFirstShow()." ".$day->getDbStartTime(), + new DateTimeZone($day->getDbTimezone()) + ); + $starts->setTimezone($utc); + array_push($startsUTC, $starts->format("Y-m-d H:i:s")); + } + + $excludeInstances = CcShowInstancesQuery::create() + ->filterByDbShowId($this->id) + ->filterByDbStarts($startsUTC, criteria::IN) + ->find(); + + $excludeIds = array(); + foreach ($excludeInstances as $instance) { + array_push($excludeIds, $instance->getDbId()); + } + + return $excludeIds; + } + /** * Gets an array of CcShowInstances objects which contain a foreign key that references this object. * diff --git a/airtime_mvc/application/services/CalendarService.php b/airtime_mvc/application/services/CalendarService.php index 3c3a85b6c..45c42a837 100644 --- a/airtime_mvc/application/services/CalendarService.php +++ b/airtime_mvc/application/services/CalendarService.php @@ -126,7 +126,15 @@ class Application_Service_CalendarService } } - $isRepeating = $this->ccShow->getFirstCcShowDay()->isRepeating(); + $excludeIds = $this->ccShow->getEditedRepeatingInstanceIds(); + + $isRepeating = true; + $populateInstance = false; + if (in_array($this->ccShowInstance->getDbId(), $excludeIds)) { + $populateInstance = true; + $isRepeating = false; + } + if (!$this->ccShowInstance->isRebroadcast() && $isAdminOrPM) { if ($isRepeating) { $menu["edit"] = array( @@ -143,6 +151,7 @@ class Application_Service_CalendarService "name" => _("Edit This Instance"), "icon" => "edit", "url" => $baseUrl."Schedule/populate-repeating-show-instance-form"); + } else { $menu["edit"] = array( "name"=> _("Edit Show"), diff --git a/airtime_mvc/application/services/ShowService.php b/airtime_mvc/application/services/ShowService.php index 5dc505882..472601dfc 100644 --- a/airtime_mvc/application/services/ShowService.php +++ b/airtime_mvc/application/services/ShowService.php @@ -159,7 +159,11 @@ class Application_Service_ShowService */ private function storeOrigLocalShowInfo() { - $this->origCcShowDay = $this->ccShow->getFirstRepeatingCcShowDay(); + if ($this->ccShow->isRepeating()) { + $this->origCcShowDay = $this->ccShow->getFirstRepeatingCcShowDay(); + } else { + $this->origCcShowDay = $this->ccShow->getFirstCcShowDay(); + } $this->oldShowTimezone = $this->origCcShowDay->getDbTimezone(); @@ -404,7 +408,11 @@ SQL; $daysAdded = array(); //CcShowDay object - $currentShowDay = $this->ccShow->getFirstRepeatingCcShowDay(); + if ($this->ccShow->isRepeating()) { + $currentShowDay = $this->ccShow->getFirstRepeatingCcShowDay(); + } else { + $currentShowDay = $this->ccShow->getFirstCcShowDay(); + } //new end date in users' local time $endDateTime = $this->calculateEndDate($showData); @@ -1387,6 +1395,8 @@ SQL; */ private function setCcShowDays($showData) { + Logging::info($showData); + Logging::info($this->repeatType); $showId = $this->ccShow->getDbId(); $startDateTime = new DateTime($showData['add_show_start_date']." ".$showData['add_show_start_time']); @@ -1451,7 +1461,7 @@ SQL; if ($this->isUpdate) { $showDay = CcShowDaysQuery::create() ->filterByDbShowId($showId) - ->filterByDbRepeatType($showData['add_show_repeat_type']) + ->filterByDbRepeatType($this->repeatType) ->filterByDbDay($day) ->findOne(); if (!$showDay) { From a164416c84461f4cfa9e81457875b5f5ba43e3d6 Mon Sep 17 00:00:00 2001 From: drigato Date: Mon, 2 Dec 2013 13:13:41 -0500 Subject: [PATCH 07/14] Fixed minor bugs --- .../application/services/CalendarService.php | 6 ++- .../application/services/ShowService.php | 37 +++++++++++++------ 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/airtime_mvc/application/services/CalendarService.php b/airtime_mvc/application/services/CalendarService.php index 45c42a837..edb76ebf5 100644 --- a/airtime_mvc/application/services/CalendarService.php +++ b/airtime_mvc/application/services/CalendarService.php @@ -151,7 +151,11 @@ class Application_Service_CalendarService "name" => _("Edit This Instance"), "icon" => "edit", "url" => $baseUrl."Schedule/populate-repeating-show-instance-form"); - + } elseif ($populateInstance) { + $menu["edit"] = array( + "name" => _("Edit Show"), + "icon" => "edit", + "url" => $baseUrl."Schedule/populate-repeating-show-instance-form"); } else { $menu["edit"] = array( "name"=> _("Edit Show"), diff --git a/airtime_mvc/application/services/ShowService.php b/airtime_mvc/application/services/ShowService.php index 472601dfc..b2bb071a2 100644 --- a/airtime_mvc/application/services/ShowService.php +++ b/airtime_mvc/application/services/ShowService.php @@ -83,12 +83,6 @@ class Application_Service_ShowService } /****** UPDATE SCHEDULE START TIME ENDS******/ - /* - * Set the new cc_show_day record - * Associates it with the current show_id and sets it to non-repeating - */ - $this->setCcShowDays($showData); - /* * In the case where an instance is being edited for a second * (or third, fourth, etc.) time we need to delete the old @@ -108,6 +102,18 @@ class Application_Service_ShowService ->filterByDbStartTime($origLocalStartDateTime->format("H:i:s")) ->delete(); + /* + * Set the new cc_show_day record + * Associates it with the current show_id and sets it to non-repeating + */ + $this->setCcShowDays($showData); + + /* + * Set the new cc_show_day record + * Associates it with the current show_id and sets it to non-repeating + */ + $this->setCcShowDays($showData); + // DO WE NEED THIS? $this->setCcShowHosts($showData); @@ -120,7 +126,7 @@ class Application_Service_ShowService ->filterByDbShowId($showId) ->filterByDbRepeatType(-1) ->filterByDbFirstShow($showData["add_show_start_date"]) - ->filterByDbStartTime($showData["add_show_start_time"]) + ->filterByDbStartTime($showData["add_show_start_time"].":00") ->findOne(); $ccShowInstance = $this->createNonRepeatingInstance($showDay, @@ -138,6 +144,7 @@ class Application_Service_ShowService ->setDbLastScheduled(gmdate("Y-m-d H:i:s")) ->save(); $ccShowInstance->updateDbTimeFilled($con); + $ccShowInstance->updateScheduleStatus($con); //delete the edited instance from the repeating sequence $ccShowInstanceOrig->setDbModifiedInstance(true)->save(); @@ -190,6 +197,7 @@ class Application_Service_ShowService $this->setCcShow($showData); $daysAdded = array(); + if ($this->isUpdate) { $daysAdded = $this->delegateInstanceCleanup($showData); @@ -456,7 +464,8 @@ SQL; //and the repeat type changed if ($currentRepeatType != -1 && $this->repeatType != $currentRepeatType) { $this->deleteAllInstances($showId); - } else { + // when repeating by day of the month (1st, 2nd, etc.) we do not store the repeat week days + } elseif ($currentRepeatType != 2) { //repeat type is the same, check if the days of the week are the same $repeatingDaysChanged = false; @@ -1018,7 +1027,9 @@ SQL; if ($this->isUpdate) { if ($this->hasInstance($utcStartDateTime)) { $ccShowInstance = $this->getInstance($utcStartDateTime); - if ($ccShowInstance->getDbModifiedInstance()) { + // don't update instances that have been edited out of the repeating sequence + if ($ccShowInstance->getDbModifiedInstance() || + in_array($ccShowInstance->getDbId(), $this->ccShow->getEditedRepeatingInstanceIds())) { continue; } $newInstance = false; @@ -1114,6 +1125,11 @@ SQL; */ if ($this->isUpdate && $this->hasInstance($utcStartDateTime)) { $ccShowInstance = $this->getInstance($utcStartDateTime); + // don't update instances that have been edited out of the repeating sequence + if ($ccShowInstance->getDbModifiedInstance() || + in_array($ccShowInstance->getDbId(), $this->ccShow->getEditedRepeatingInstanceIds())) { + continue; + } $newInstance = false; $updateScheduleStatus = true; } else { @@ -1395,8 +1411,6 @@ SQL; */ private function setCcShowDays($showData) { - Logging::info($showData); - Logging::info($this->repeatType); $showId = $this->ccShow->getDbId(); $startDateTime = new DateTime($showData['add_show_start_date']." ".$showData['add_show_start_time']); @@ -1424,6 +1438,7 @@ SQL; if ($showData['add_show_repeats'] && $showData['add_show_repeat_type'] == 2) { if ($this->isUpdate) { + //Logging::info(CcShowDaysQuery::create()->find()); $showDay = CcShowDaysQuery::create() ->filterByDbShowId($showId) ->filterByDbRepeatType($showData['add_show_repeat_type']) From 02453c52eed2ce854acda51d3ff0850eeb75858f Mon Sep 17 00:00:00 2001 From: drigato Date: Mon, 2 Dec 2013 13:28:25 -0500 Subject: [PATCH 08/14] Copy/paste error Was setting cc_show_days twice --- airtime_mvc/application/services/ShowService.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/airtime_mvc/application/services/ShowService.php b/airtime_mvc/application/services/ShowService.php index b2bb071a2..32b018f6a 100644 --- a/airtime_mvc/application/services/ShowService.php +++ b/airtime_mvc/application/services/ShowService.php @@ -108,12 +108,6 @@ class Application_Service_ShowService */ $this->setCcShowDays($showData); - /* - * Set the new cc_show_day record - * Associates it with the current show_id and sets it to non-repeating - */ - $this->setCcShowDays($showData); - // DO WE NEED THIS? $this->setCcShowHosts($showData); @@ -1438,7 +1432,6 @@ SQL; if ($showData['add_show_repeats'] && $showData['add_show_repeat_type'] == 2) { if ($this->isUpdate) { - //Logging::info(CcShowDaysQuery::create()->find()); $showDay = CcShowDaysQuery::create() ->filterByDbShowId($showId) ->filterByDbRepeatType($showData['add_show_repeat_type']) From 6c71b170244c677cb19e1688615e327f0323618a Mon Sep 17 00:00:00 2001 From: drigato Date: Wed, 4 Dec 2013 10:05:32 -0500 Subject: [PATCH 09/14] CC-5595: Improper day of week comparison Need to convert show instance start time to the show's local timezone before getting the repeat day of week --- airtime_mvc/application/services/ShowService.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/airtime_mvc/application/services/ShowService.php b/airtime_mvc/application/services/ShowService.php index 32b018f6a..b8a89e18f 100644 --- a/airtime_mvc/application/services/ShowService.php +++ b/airtime_mvc/application/services/ShowService.php @@ -743,14 +743,23 @@ SQL; */ else if (count($ccShowInstances) >= 1) { $lastShowDays = array(); + + //get the show's timezone + $ccShow = CcShowQuery::create()->findPk($showId); + if ($ccShow->isRepeating()) { + $showTimezone = $ccShow->getFirstRepeatingCcShowDay()->getDbTimezone(); + } else { + $showTimezone = $ccShow->getFirstCcShowDay()->getDbTimezone(); + } + /* Creates an array where the key is the day of the week (monday, * tuesday, etc.) and the value is the last show date for each * day of the week. We will use this array to update the last_show * for each cc_show_days entry of a cc_show */ foreach ($ccShowInstances as $instance) { - $instanceStartDT = new DateTime($instance->getDbStarts(), - new DateTimeZone("UTC")); + $instanceStartDT = $instance->getDbStarts(null); + $instanceStartDT->setTimezone(new DateTimeZone($showTimezone)); $lastShowDays[$instanceStartDT->format("w")] = $instanceStartDT; } From 22595c1098112233d88685d476a3fc0b947bc382 Mon Sep 17 00:00:00 2001 From: drigato Date: Wed, 4 Dec 2013 11:36:38 -0500 Subject: [PATCH 10/14] CC-5596: Can Recreate an Instance in a Location that has been modified Fixed by updating the modified instance's start/end time and leaving as a placeholder for future show updates --- airtime_mvc/application/services/ShowService.php | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/airtime_mvc/application/services/ShowService.php b/airtime_mvc/application/services/ShowService.php index b8a89e18f..992ddd0aa 100644 --- a/airtime_mvc/application/services/ShowService.php +++ b/airtime_mvc/application/services/ShowService.php @@ -1030,11 +1030,6 @@ SQL; if ($this->isUpdate) { if ($this->hasInstance($utcStartDateTime)) { $ccShowInstance = $this->getInstance($utcStartDateTime); - // don't update instances that have been edited out of the repeating sequence - if ($ccShowInstance->getDbModifiedInstance() || - in_array($ccShowInstance->getDbId(), $this->ccShow->getEditedRepeatingInstanceIds())) { - continue; - } $newInstance = false; $updateScheduleStatus = true; } else { @@ -1128,11 +1123,6 @@ SQL; */ if ($this->isUpdate && $this->hasInstance($utcStartDateTime)) { $ccShowInstance = $this->getInstance($utcStartDateTime); - // don't update instances that have been edited out of the repeating sequence - if ($ccShowInstance->getDbModifiedInstance() || - in_array($ccShowInstance->getDbId(), $this->ccShow->getEditedRepeatingInstanceIds())) { - continue; - } $newInstance = false; $updateScheduleStatus = true; } else { From b78fa994f775bec6c3c845dd23095e690b004034 Mon Sep 17 00:00:00 2001 From: drigato Date: Wed, 4 Dec 2013 12:20:16 -0500 Subject: [PATCH 11/14] CC-5405: When editing a single show instance from a repeating series, should not create a new cc_show Removed redundant timestamp var Removed redundant DateTime object creation --- airtime_mvc/application/models/Show.php | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/airtime_mvc/application/models/Show.php b/airtime_mvc/application/models/Show.php index e725bc7a0..02db117ce 100644 --- a/airtime_mvc/application/models/Show.php +++ b/airtime_mvc/application/models/Show.php @@ -199,8 +199,7 @@ SQL; //convert instance to local timezone $ccShowInstance = CcShowInstancesQuery::create()->findPk($instanceId); - $startsDT = new DateTime($ccShowInstance->getDbStarts(), - new DateTimeZone("UTC")); + $startsDT = $ccShowInstance->getDbStarts(null); $timezone = $ccShow->getFirstCcShowDay()->getDbTimezone(); $startsDT->setTimezone(new DateTimeZone($timezone)); @@ -262,8 +261,8 @@ SQL; foreach ($showInstances as $si) { array_push($instanceIds, $si->getDbId()); - $startsDateTime = new DateTime($si->getDbStarts(), new DateTimeZone("UTC")); - $endsDateTime = new DateTime($si->getDbEnds(), new DateTimeZone("UTC")); + $startsDateTime = $si->getDbStarts(null); + $endsDateTime = $si->getDbEnds(null); /* The user is moving the show on the calendar from the perspective of local time. * incase a show is moved across a time change @@ -296,9 +295,6 @@ SQL; $hours = ($hours > 0) ? floor($hours) : ceil($hours); $mins = abs($deltaMin % 60); - //current timesamp in UTC. - $current_timestamp = gmdate("Y-m-d H:i:s"); - $sql_gen = "UPDATE cc_show_instances ". "SET ends = (ends + :deltaDay1::INTERVAL + :interval1::INTERVAL) ". "WHERE (id IN (".implode($instanceIds, ",").") ". @@ -309,7 +305,7 @@ SQL; array( ':deltaDay1' => "$deltaDay days", ':interval1' => "$hours:$mins", - ':current_timestamp1' => $current_timestamp, + ':current_timestamp1' => $nowDateTime->format("Y-m-d H:i:s"), ':deltaDay2' => "$deltaDay days", ':interval2' => "$hours:$mins" ), "execute"); @@ -340,7 +336,7 @@ SQL; CcShowInstancesPeer::clearInstancePool(); $instances = CcShowInstancesQuery::create() - ->filterByDbEnds($current_timestamp, Criteria::GREATER_THAN) + ->filterByDbEnds($nowDateTime->format("Y-m-d H:i:s"), Criteria::GREATER_THAN) ->filterByDbId($instanceIds, Criteria::IN) ->find($con); From 463d286ac50097b8633307e7db9be0644be3e4f7 Mon Sep 17 00:00:00 2001 From: drigato Date: Wed, 4 Dec 2013 14:00:31 -0500 Subject: [PATCH 12/14] CC-5405: When editing a single show instance from a repeating series, should not create a new cc_show Refactored cc_show->isRepeating() function --- airtime_mvc/application/models/airtime/CcShow.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/airtime_mvc/application/models/airtime/CcShow.php b/airtime_mvc/application/models/airtime/CcShow.php index 99c5aaa75..91874eed6 100644 --- a/airtime_mvc/application/models/airtime/CcShow.php +++ b/airtime_mvc/application/models/airtime/CcShow.php @@ -95,15 +95,14 @@ class CcShow extends BaseCcShow { */ public function isRepeating() { - //get ALL cc_show_day entries + //get all cc_show_day entries that are repeating $ccShowDays = CcShowDaysQuery::create() ->filterByDbShowId($this->id) + ->filterByDbRepeatType(0, Criteria::GREATER_EQUAL) ->find(); - foreach ($ccShowDays as $day) { - if ($day->getDbRepeatType() >= 0) { - return true; - } + if (!$ccShowDays->isEmpty()) { + return true; } return false; From 7f8f084c9807947aa5e52ea3ae67e25730a3c198 Mon Sep 17 00:00:00 2001 From: drigato Date: Wed, 4 Dec 2013 14:17:19 -0500 Subject: [PATCH 13/14] CC-5405: When editing a single show instance from a repeating series, should not create a new cc_show Refactored cc_show_day->getLocalEndDateAndTime() function --- airtime_mvc/application/models/airtime/CcShowDays.php | 7 +++---- airtime_mvc/application/services/ShowFormService.php | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/airtime_mvc/application/models/airtime/CcShowDays.php b/airtime_mvc/application/models/airtime/CcShowDays.php index 215ebdcf8..2f187bf44 100644 --- a/airtime_mvc/application/models/airtime/CcShowDays.php +++ b/airtime_mvc/application/models/airtime/CcShowDays.php @@ -40,8 +40,7 @@ class CcShowDays extends BaseCcShowDays { ); //set timezone to that of the show - $dt->setTimezone(new DateTimeZone($this->getDbTimezone())); - + //$dt->setTimezone(new DateTimeZone($this->getDbTimezone())); return $dt; } @@ -50,9 +49,9 @@ class CcShowDays extends BaseCcShowDays { * Returns the end of a show in the timezone it was created in * @param DateTime $startDateTime first show in show's local time */ - public function getLocalEndDateAndTime($showStart) + public function getLocalEndDateAndTime() { - $startDateTime = clone $showStart; + $startDateTime = $this->getLocalStartDateAndTime(); $duration = explode(":", $this->getDbDuration()); return $startDateTime->add(new DateInterval('PT'.$duration[0].'H'.$duration[1].'M')); diff --git a/airtime_mvc/application/services/ShowFormService.php b/airtime_mvc/application/services/ShowFormService.php index 85b9868c0..1d513587d 100644 --- a/airtime_mvc/application/services/ShowFormService.php +++ b/airtime_mvc/application/services/ShowFormService.php @@ -131,7 +131,7 @@ class Application_Service_ShowFormService } $showStart = $ccShowDay->getLocalStartDateAndTime(); - $showEnd = $ccShowDay->getLocalEndDateAndTime($showStart); + $showEnd = $ccShowDay->getLocalEndDateAndTime(); //check if the first show is in the past if ($ccShowDay->isShowStartInPast()) { From 49ed0cf0f18c46d5f863bbfdfe4dcde18f1dd780 Mon Sep 17 00:00:00 2001 From: drigato Date: Wed, 4 Dec 2013 14:28:16 -0500 Subject: [PATCH 14/14] CC-5405: When editing a single show instance from a repeating series, should not create a new cc_show Removed redundant function call to update last_scheduled column on a cc_show_instance --- airtime_mvc/application/services/ShowService.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/airtime_mvc/application/services/ShowService.php b/airtime_mvc/application/services/ShowService.php index 992ddd0aa..76c60b80b 100644 --- a/airtime_mvc/application/services/ShowService.php +++ b/airtime_mvc/application/services/ShowService.php @@ -134,9 +134,6 @@ class Application_Service_ShowService $updateCriteria->add(CcSchedulePeer::INSTANCE_ID, $ccShowInstance->getDbId()); BasePeer::doUpdate($selectCriteria, $updateCriteria, $con); - $ccShowInstance - ->setDbLastScheduled(gmdate("Y-m-d H:i:s")) - ->save(); $ccShowInstance->updateDbTimeFilled($con); $ccShowInstance->updateScheduleStatus($con);