MDL-46710 mod_lti: fix logging and completion tracking in new windows
authorTim Lock <tim.lock@netspot.com.au>
Wed, 19 Aug 2015 22:08:14 +0000 (07:38 +0930)
committerTim Lock <tim.lock@netspot.com.au>
Thu, 24 Sep 2015 20:57:18 +0000 (06:27 +0930)
mod/lti/launch.php
mod/lti/view.php

index f6fd502..53aaf1b 100644 (file)
@@ -61,6 +61,20 @@ $context = context_module::instance($cm->id);
 require_login($course, true, $cm);
 require_capability('mod/lti:view', $context);
 
+// Mark viewed by user (if required).
+$completion = new completion_info($course);
+$completion->set_module_viewed($cm);
+
+$params = array(
+    'context' => $context,
+    'objectid' => $lti->id
+);
+$event = \mod_lti\event\course_module_viewed::create($params);
+$event->add_record_snapshot('course_modules', $cm);
+$event->add_record_snapshot('course', $course);
+$event->add_record_snapshot('lti', $lti);
+$event->trigger();
+
 $lti->cmid = $cm->id;
 lti_view($lti);
 
index bfb9b10..7d197fa 100644 (file)
@@ -102,11 +102,15 @@ $params = array(
     'context' => $context,
     'objectid' => $lti->id
 );
-$event = \mod_lti\event\course_module_viewed::create($params);
-$event->add_record_snapshot('course_modules', $cm);
-$event->add_record_snapshot('course', $course);
-$event->add_record_snapshot('lti', $lti);
-$event->trigger();
+
+// Prevent double logging when launching in a new window is configured.
+if ($launchcontainer != LTI_LAUNCH_CONTAINER_WINDOW) {
+    $event = \mod_lti\event\course_module_viewed::create($params);
+    $event->add_record_snapshot('course_modules', $cm);
+    $event->add_record_snapshot('course', $course);
+    $event->add_record_snapshot('lti', $lti);
+    $event->trigger();
+}
 
 $pagetitle = strip_tags($course->shortname.': '.format_string($lti->name));
 $PAGE->set_title($pagetitle);