diff --git a/mod/glossary/classes/event/course_module_viewed.php b/mod/glossary/classes/event/course_module_viewed.php new file mode 100644 index 00000000000..77ed8cfc5ac --- /dev/null +++ b/mod/glossary/classes/event/course_module_viewed.php @@ -0,0 +1,70 @@ +. + +/** + * This file contains an event for when a glossary activity is viewed. + * + * @package mod_glossary + * @copyright 2014 Marina Glancy + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace mod_glossary\event; +defined('MOODLE_INTERNAL') || die(); + +/** + * Event for when a page activity is viewed. + * + * @package mod_glossary + * @copyright 2014 Marina Glancy + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class course_module_viewed extends \core\event\course_module_viewed { + + /** + * Init method. + */ + protected function init() { + $this->data['crud'] = 'r'; + $this->data['edulevel'] = self::LEVEL_PARTICIPATING; + $this->data['objecttable'] = 'glossary'; + } + + /** + * Get URL related to the action. + * + * @return \moodle_url + */ + public function get_url() { + $params = array('id' => $this->contextinstanceid); + if (!empty($this->other['mode'])) { + $params['mode'] = $this->other['mode']; + } + return new \moodle_url("/mod/$this->objecttable/view.php", $params); + } + + /** + * Return the legacy event log data. + * + * @return array|null + */ + public function get_legacy_logdata() { + // In moodle 2.6 and below the url was logged incorrectly, always having tab=-1 . + return array($this->courseid, $this->objecttable, 'view', + 'view.php?id=' . $this->contextinstanceid . '&tab=-1', + $this->objectid, $this->contextinstanceid); + } +} diff --git a/mod/glossary/view.php b/mod/glossary/view.php index 4bd4f83447c..43a7ba89de3 100644 --- a/mod/glossary/view.php +++ b/mod/glossary/view.php @@ -124,11 +124,6 @@ if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', $con echo $OUTPUT->header(); notice(get_string("activityiscurrentlyhidden")); } -add_to_log($course->id, "glossary", "view", "view.php?id=$cm->id&tab=$tab", $glossary->id, $cm->id); - -// Mark as viewed -$completion = new completion_info($course); -$completion->set_module_viewed($cm); /// stablishing flag variables if ( $sortorder = strtolower($sortorder) ) { @@ -229,6 +224,21 @@ default: break; } +// Trigger module viewed event. +$event = \mod_glossary\event\course_module_viewed::create(array( + 'objectid' => $glossary->id, + 'context' => $context, + 'other' => array('mode' => $mode) +)); +$event->add_record_snapshot('course', $course); +$event->add_record_snapshot('course_modules', $cm); +$event->add_record_snapshot('glossary', $glossary); +$event->trigger(); + +// Mark as viewed +$completion = new completion_info($course); +$completion->set_module_viewed($cm); + /// Printing the heading $strglossaries = get_string("modulenameplural", "glossary"); $strglossary = get_string("modulename", "glossary");