From f0c5f8406cd20d78c319979ab1a122b48b15eeed Mon Sep 17 00:00:00 2001 From: Juan Leyva Date: Tue, 31 Mar 2015 13:30:30 +0200 Subject: [PATCH] MDL-49504 notes: Move note view triggering to API function --- notes/index.php | 6 +----- notes/lib.php | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/notes/index.php b/notes/index.php index 369b74ebc40f2..abab4e95c0a8e 100644 --- a/notes/index.php +++ b/notes/index.php @@ -87,11 +87,7 @@ $systemcontext = context_system::instance(); // Trigger event. -$event = \core\event\notes_viewed::create(array( - 'relateduserid' => $userid, - 'context' => $coursecontext -)); -$event->trigger(); +note_view($coursecontext, $userid); $strnotes = get_string('notes', 'notes'); if ($userid) { diff --git a/notes/lib.php b/notes/lib.php index 2585f4085072b..8e288e80981ce 100644 --- a/notes/lib.php +++ b/notes/lib.php @@ -16,6 +16,9 @@ /** * Library of functions and constants for notes + * + * @package core_notes + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ /** @@ -347,3 +350,20 @@ function note_delete_all($courseid) { function note_page_type_list($pagetype, $parentcontext, $currentcontext) { return array('notes-*' => get_string('page-notes-x', 'notes')); } + +/** + * Trigger notes viewed event + * + * @param stdClass $context context object + * @param int $userid user id (the user we are viewing the notes) + * @since Moodle 2.9 + */ +function note_view($context, $userid) { + + $event = \core\event\notes_viewed::create(array( + 'relateduserid' => $userid, + 'context' => $context + )); + $event->trigger(); +} +