MDL-63150 mod_url: Accept a userid override in event action
[moodle.git] / mod / url / lib.php
index 6a342f3..23d11a0 100644 (file)
@@ -379,15 +379,22 @@ function url_check_updates_since(cm_info $cm, $from, $filter = array()) {
  *
  * @param calendar_event $event
  * @param \core_calendar\action_factory $factory
+ * @param int $userid ID override for calendar events
  * @return \core_calendar\local\event\entities\action_interface|null
  */
 function mod_url_core_calendar_provide_event_action(calendar_event $event,
-                                                       \core_calendar\action_factory $factory) {
-    $cm = get_fast_modinfo($event->courseid)->instances['url'][$event->instance];
+                                                       \core_calendar\action_factory $factory, $userid = 0) {
+
+    global $USER;
+    if (empty($userid)) {
+        $userid = $USER->id;
+    }
+
+    $cm = get_fast_modinfo($event->courseid, $userid)->instances['url'][$event->instance];
 
     $completion = new \completion_info($cm->get_course());
 
-    $completiondata = $completion->get_data($cm, false);
+    $completiondata = $completion->get_data($cm, false, $userid);
 
     if ($completiondata->completionstate != COMPLETION_INCOMPLETE) {
         return null;