From 3fdd73e83d76c1ad5982a0687e9ebc6d82e964ab Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Tue, 31 Dec 2013 15:09:03 -0800 Subject: [PATCH 1/2] MDL-40918 mod_lti: replaced 'view' and 'view all' add_to_log calls with events --- .../course_module_instance_list_viewed.php | 31 +++++++++++++++ .../classes/event/course_module_viewed.php | 39 +++++++++++++++++++ mod/lti/index.php | 6 ++- mod/lti/view.php | 8 +++- 4 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 mod/lti/classes/event/course_module_instance_list_viewed.php create mode 100644 mod/lti/classes/event/course_module_viewed.php diff --git a/mod/lti/classes/event/course_module_instance_list_viewed.php b/mod/lti/classes/event/course_module_instance_list_viewed.php new file mode 100644 index 00000000000..4f843eba5b1 --- /dev/null +++ b/mod/lti/classes/event/course_module_instance_list_viewed.php @@ -0,0 +1,31 @@ +. + +/** + * The mod_lti instance list viewed event. + * + * @package mod_lti + * @copyright 2013 Mark Nelson + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace mod_lti\event; + +defined('MOODLE_INTERNAL') || die(); + +class course_module_instance_list_viewed extends \core\event\course_module_instance_list_viewed { + // No need for any code here as everything is handled by the parent class. +} diff --git a/mod/lti/classes/event/course_module_viewed.php b/mod/lti/classes/event/course_module_viewed.php new file mode 100644 index 00000000000..8d8ed19ee95 --- /dev/null +++ b/mod/lti/classes/event/course_module_viewed.php @@ -0,0 +1,39 @@ +. + +/** + * The mod_lti course module viewed event. + * + * @package mod_lti + * @copyright 2013 Mark Nelson + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace mod_lti\event; + +defined('MOODLE_INTERNAL') || die(); + +class course_module_viewed extends \core\event\course_module_viewed { + + /** + * Init method. + */ + protected function init() { + $this->data['objecttable'] = 'lti'; + $this->data['crud'] = 'r'; + $this->data['level'] = self::LEVEL_PARTICIPATING; + } +} diff --git a/mod/lti/index.php b/mod/lti/index.php index dc564468483..65b9ad7e9f0 100644 --- a/mod/lti/index.php +++ b/mod/lti/index.php @@ -56,7 +56,11 @@ $course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST); require_login($course); $PAGE->set_pagelayout('incourse'); -add_to_log($course->id, "lti", "view all", "index.php?id=$course->id", ""); +$params = array( + 'context' => context_course::instance($course->id) +); +$event = \mod_lti\event\course_module_instance_list_viewed::create($params); +$event->trigger(); $PAGE->set_url('/mod/lti/index.php', array('id' => $course->id)); $pagetitle = strip_tags($course->shortname.': '.get_string("modulenamepluralformatted", "lti")); diff --git a/mod/lti/view.php b/mod/lti/view.php index 6735bcd0dc1..b4a80d9c507 100644 --- a/mod/lti/view.php +++ b/mod/lti/view.php @@ -96,7 +96,13 @@ require_login($course); $completion = new completion_info($course); $completion->set_module_viewed($cm); -add_to_log($course->id, "lti", "view", "view.php?id=$cm->id", "$lti->id"); +$params = array( + 'context' => $context, + 'objectid' => $lti->id +); +$event = \mod_lti\event\course_module_viewed::create($params); +$event->add_record_snapshot('lti', $lti); +$event->trigger(); $pagetitle = strip_tags($course->shortname.': '.format_string($lti->name)); $PAGE->set_title($pagetitle); From e9787bda9aa49ebdf5ec310f19a6e0fd4f7f47a4 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Tue, 31 Dec 2013 16:02:18 -0800 Subject: [PATCH 2/2] MDL-40918 mod_lti: removed the 'launch' add_to_log call This add_to_log call is unnecessary and does not need to be replaced with an event. It is called whenever we view the external tool, which will trigger the view event. There is no need for two events when this occurs. --- mod/lti/launch.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/mod/lti/launch.php b/mod/lti/launch.php index fced3b41170..de31c7a098b 100644 --- a/mod/lti/launch.php +++ b/mod/lti/launch.php @@ -59,8 +59,6 @@ $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST) require_login($course); -add_to_log($course->id, "lti", "launch", "launch.php?id=$cm->id", "$lti->id"); - $lti->cmid = $cm->id; lti_view($lti);