diff --git a/lang/en/moodle.php b/lang/en/moodle.php index ccae4de1e4f..387d43961a2 100644 --- a/lang/en/moodle.php +++ b/lang/en/moodle.php @@ -717,6 +717,7 @@ $string['eventcoursedeleted'] = 'Course deleted'; $string['eventcoursemodulecreated'] = 'Course module created'; $string['eventcoursemoduledeleted'] = 'Course module deleted'; $string['eventcoursemoduleupdated'] = 'Course module updated'; +$string['eventcoursemoduleviewed'] = 'Course module viewed'; $string['eventcourseresetended'] = 'Course reset ended'; $string['eventcourseresetstarted'] = 'Course reset started'; $string['eventcourserestored'] = 'Course restored'; diff --git a/lib/classes/event/course_module_viewed.php b/lib/classes/event/course_module_viewed.php new file mode 100644 index 00000000000..7b45a259f1a --- /dev/null +++ b/lib/classes/event/course_module_viewed.php @@ -0,0 +1,101 @@ +. + +/** + * Course module viewed event. + * + * @package core + * @copyright 2013 onwards Ankit Agarwal + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace core\event; +defined('MOODLE_INTERNAL') || die(); + +/** + * Abstract Course module viewed event class. + * + * Class for event to be triggered when a course module is viewed. + * + * @package core + * @copyright 2013 onwards Ankit Agarwal + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +abstract class course_module_viewed extends base { + + /** + * Init method. + * + * Please override this in extending class and specify objecttable. + * + * @return void + */ + protected function init() { + $this->data['crud'] = 'r'; + $this->data['level'] = self::LEVEL_PARTICIPATING; + } + + /** + * Returns description of what happened. + * + * @return string + */ + public function get_description() { + return "User with id '$this->userid' viewed course module '$this->objecttable' with instance id '$this->objectid'"; + } + + /** + * Return localised event name. + * + * @return string + */ + public static function get_name() { + return get_string('eventcoursemoduleviewed', 'core'); + } + + /** + * Get URL related to the action. + * + * @return \moodle_url + */ + public function get_url() { + return new \moodle_url("/mod/$this->objecttable/view.php", array('id' => $this->context->instanceid)); + } + + /** + * Return the legacy event log data. + * + * @return array|null + */ + protected function get_legacy_logdata() { + return array($this->courseid, $this->objecttable, 'view', 'view.php?id=' . $this->context->instanceid, $this->objectid, + $this->context->instanceid); + } + + /** + * Custom validation. + * + * @throws \coding_exception + * @return void + */ + protected function validate_data() { + // Make sure this class is never used without proper object details. + if (empty($this->objectid) || empty($this->objecttable)) { + throw new \coding_exception('course_module_viewed event must define objectid and object table.'); + } + } + +}