From 90e331bcdc4ec479391ef5920170ea9668f7d875 Mon Sep 17 00:00:00 2001 From: Tobias Reischmann Date: Thu, 28 Mar 2019 13:17:32 +0100 Subject: [PATCH] MDL-65206 calendar: Enable update of location in repeated events. The location is now updated in repeated events if it is altered in one event and the option 'Also apply changes to the other X events in this repeat series' is selected. If the location is not altered but some other details, then manual changes of the location in other events will not be overriden. --- calendar/lib.php | 75 ++++++++++++++++++++++-------------------------- 1 file changed, 35 insertions(+), 40 deletions(-) diff --git a/calendar/lib.php b/calendar/lib.php index fd6078a38be..34b0db5ba97 100644 --- a/calendar/lib.php +++ b/calendar/lib.php @@ -608,49 +608,44 @@ class calendar_event { $updaterepeated = (!empty($this->properties->repeatid) && !empty($this->properties->repeateditall)); if ($updaterepeated) { - // Update all. + + $sqlset = 'name = ?, + description = ?, + timeduration = ?, + timemodified = ?, + groupid = ?, + courseid = ?'; + + // Note: Group and course id may not be set. If not, keep their current values. + $params = [ + $this->properties->name, + $this->properties->description, + $this->properties->timeduration, + time(), + isset($this->properties->groupid) ? $this->properties->groupid : $event->groupid, + isset($this->properties->courseid) ? $this->properties->courseid : $event->courseid, + ]; + + // Note: Only update start date, if it was changed by the user. if ($this->properties->timestart != $event->timestart) { $timestartoffset = $this->properties->timestart - $event->timestart; - $sql = "UPDATE {event} - SET name = ?, - description = ?, - timestart = timestart + ?, - timeduration = ?, - timemodified = ?, - groupid = ?, - courseid = ? - WHERE repeatid = ?"; - // Note: Group and course id may not be set. If not, keep their current values. - $params = [ - $this->properties->name, - $this->properties->description, - $timestartoffset, - $this->properties->timeduration, - time(), - isset($this->properties->groupid) ? $this->properties->groupid : $event->groupid, - isset($this->properties->courseid) ? $this->properties->courseid : $event->courseid, - $event->repeatid - ]; - } else { - $sql = "UPDATE {event} - SET name = ?, - description = ?, - timeduration = ?, - timemodified = ?, - groupid = ?, - courseid = ? - WHERE repeatid = ?"; - // Note: Group and course id may not be set. If not, keep their current values. - $params = [ - $this->properties->name, - $this->properties->description, - $this->properties->timeduration, - time(), - isset($this->properties->groupid) ? $this->properties->groupid : $event->groupid, - isset($this->properties->courseid) ? $this->properties->courseid : $event->courseid, - $event->repeatid - ]; + $sqlset .= ', timestart = timestart + ?'; + $params[] = $timestartoffset; } + + // Note: Only update location, if it was changed by the user. + $updatelocation = (!empty($this->properties->location) && $this->properties->location !== $event->location); + if ($updatelocation) { + $sqlset .= ', location = ?'; + $params[] = $this->properties->location; + } + + // Update all. + $sql = "UPDATE {event} + SET $sqlset + WHERE repeatid = ?"; + + $params[] = $event->repeatid; $DB->execute($sql, $params); // Trigger an update event for each of the calendar event.