Skip to content

Commit

Permalink
MDL-57793 calendar: Add recursion to satisfy COUNT rule
Browse files Browse the repository at this point in the history
* Add recursion to the creation of recurring calendar events to satisfy
  the COUNT rule, if necessary.
  • Loading branch information
junpataleta committed Apr 18, 2017
1 parent 0714bcb commit dbb49e8
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions calendar/classes/rrule_manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,20 @@ protected function create_recurring_events($event, $eventtimes) {
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);
}
}

/**
Expand Down

0 comments on commit dbb49e8

Please sign in to comment.