From dbb49e8d48f2f10c6aee54dd0a6028156a86afdd Mon Sep 17 00:00:00 2001 From: Jun Pataleta Date: Fri, 17 Mar 2017 13:27:20 +0800 Subject: [PATCH] MDL-57793 calendar: Add recursion to satisfy COUNT rule * Add recursion to the creation of recurring calendar events to satisfy the COUNT rule, if necessary. --- calendar/classes/rrule_manager.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/calendar/classes/rrule_manager.php b/calendar/classes/rrule_manager.php index 78cee59681d..ea8e1846375 100644 --- a/calendar/classes/rrule_manager.php +++ b/calendar/classes/rrule_manager.php @@ -721,6 +721,20 @@ class rrule_manager { unset($cloneevent->id); \calendar_event::create($cloneevent, false); } + + // If COUNT rule is defined and the number of the generated event times is less than the the COUNT rule, + // repeat the processing until the COUNT rule is satisfied. + if ($count !== false && $count > 0) { + // Set count to the remaining counts. + $this->count = $count; + // Clone the original event, but set the timestart to the last generated event time. + $tmpevent = clone($event); + $tmpevent->timestart = end($eventtimes); + // Generate the additional event times. + $additionaleventtimes = $this->generate_recurring_event_times($tmpevent); + // Create the additional events. + $this->create_recurring_events($event, $additionaleventtimes); + } } /**