From a501fe1385029c42ef05a104eda725aa024bd0b3 Mon Sep 17 00:00:00 2001 From: Ankit Agarwal Date: Tue, 7 Jan 2014 14:06:26 +0800 Subject: [PATCH] MDL-40056 events: Created Event classes to replace add_to_log() - mod_scorm Created attempt_deleted event Created interactions_viewed event Created report_viewed event Created sco_launched event Created tracks_viewed event Created user_report_viewed event Created course module related events --- mod/scorm/classes/event/attempt_deleted.php | 99 +++++++++++++++ .../course_module_instance_list_viewed.php | 37 ++++++ .../classes/event/course_module_viewed.php | 56 +++++++++ .../classes/event/interactions_viewed.php | 108 +++++++++++++++++ mod/scorm/classes/event/report_viewed.php | 100 +++++++++++++++ mod/scorm/classes/event/sco_launched.php | 101 ++++++++++++++++ mod/scorm/classes/event/tracks_viewed.php | 114 ++++++++++++++++++ .../classes/event/user_report_viewed.php | 108 +++++++++++++++++ 8 files changed, 723 insertions(+) create mode 100644 mod/scorm/classes/event/attempt_deleted.php create mode 100644 mod/scorm/classes/event/course_module_instance_list_viewed.php create mode 100644 mod/scorm/classes/event/course_module_viewed.php create mode 100644 mod/scorm/classes/event/interactions_viewed.php create mode 100644 mod/scorm/classes/event/report_viewed.php create mode 100644 mod/scorm/classes/event/sco_launched.php create mode 100644 mod/scorm/classes/event/tracks_viewed.php create mode 100644 mod/scorm/classes/event/user_report_viewed.php diff --git a/mod/scorm/classes/event/attempt_deleted.php b/mod/scorm/classes/event/attempt_deleted.php new file mode 100644 index 00000000000..8c872fbd78f --- /dev/null +++ b/mod/scorm/classes/event/attempt_deleted.php @@ -0,0 +1,99 @@ +. + +/** + * This file contains an event for when attempts are deleted. + * + * @package mod_scorm + * @copyright 2013 onwards Ankit Agarwal + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace mod_scorm\event; +defined('MOODLE_INTERNAL') || die(); + +/** + * Event for when attempts are deleted. + * + * @property-read array $other { + * Extra information about event properties. + * + * @type int attemptid Attempt id. + * } + * @package mod_scorm + * @copyright 2013 onwards Ankit Agarwal + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class attempt_deleted extends \core\event\base { + + /** + * Init method. + */ + protected function init() { + $this->data['crud'] = 'd'; + $this->data['level'] = self::LEVEL_TEACHING; + } + + /** + * Returns non-localised description of what happened. + * + * @return string + */ + public function get_description() { + return 'User with id ' . $this->userid . ' deleted attempt for scorm activity with attemptid ' . $this->other['attemptid']; + } + + /** + * Returns localised general event name. + * + * @return string + */ + public static function get_name() { + return get_string('eventattemptdeleted', 'mod_scorm'); + } + + /** + * Get URL related to the action + * + * @return \moodle_url + */ + public function get_url() { + return new \moodle_url('/mod/scorm/report.php', array('id' => $this->context->instanceid)); + } + + /** + * Replace add_to_log() statement. + * + * @return array of parameters to be passed to legacy add_to_log() function. + */ + protected function get_legacy_logdata() { + return array($this->courseid, 'scorm', 'delete attempts', 'report.php?id=' . $this->context->instanceid, + $this->other['attemptid'], $this->context->instanceid); + } + + /** + * Custom validation. + * + * @throws \coding_exception + * @return void + */ + protected function validate_data() { + if (empty($this->other['attemptid'])) { + throw new \coding_exception('The event must specify attemptid.'); + } + parent::validate_data(); + } +} diff --git a/mod/scorm/classes/event/course_module_instance_list_viewed.php b/mod/scorm/classes/event/course_module_instance_list_viewed.php new file mode 100644 index 00000000000..65e3cbfc3f6 --- /dev/null +++ b/mod/scorm/classes/event/course_module_instance_list_viewed.php @@ -0,0 +1,37 @@ +. + +/** + * mod_scorm course module instances list viewed event. + * + * @package mod_scorm + * @copyright 2013 Ankit Agarwal + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace mod_scorm\event; +defined('MOODLE_INTERNAL') || die(); + +/** + * mod_scorm course module instances list viewed event class. + * + * @package mod_scorm + * @copyright 2013 Ankit Agarwal + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class course_module_instance_list_viewed extends \core\event\course_module_instance_list_viewed { +} + diff --git a/mod/scorm/classes/event/course_module_viewed.php b/mod/scorm/classes/event/course_module_viewed.php new file mode 100644 index 00000000000..3905ee88068 --- /dev/null +++ b/mod/scorm/classes/event/course_module_viewed.php @@ -0,0 +1,56 @@ +. + +/** + * This file contains an event for when a scorm activity is viewed. + * + * @package mod_scorm + * @copyright 2013 onwards Ankit Agarwal + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace mod_scorm\event; +defined('MOODLE_INTERNAL') || die(); + +/** + * Event for when a scorm activity is viewed. + * + * @package mod_scorm + * @copyright 2013 onwards Ankit Agarwal + * @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['level'] = self::LEVEL_PARTICIPATING; + $this->data['objecttable'] = 'scorm'; + } + + /** + * Replace add_to_log() statement. + * + * @return array of parameters to be passed to legacy add_to_log() function. + */ + protected function get_legacy_logdata() { + return array($this->courseid, 'scorm', 'pre-view', 'view.php?id=' . $this->context->instanceid, $this->objectid, + $this->context->instanceid); + } +} + diff --git a/mod/scorm/classes/event/interactions_viewed.php b/mod/scorm/classes/event/interactions_viewed.php new file mode 100644 index 00000000000..6b617f6a0ba --- /dev/null +++ b/mod/scorm/classes/event/interactions_viewed.php @@ -0,0 +1,108 @@ +. + +/** + * This file contains an event for when user interactions is viewed. + * + * @package mod_scorm + * @copyright 2013 onwards Ankit Agarwal + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace mod_scorm\event; +defined('MOODLE_INTERNAL') || die(); + +/** + * Event for when a user interactions are viewed. + * + * @property-read array $other { + * Extra information about event properties. + * + * @type int attemptid Attempt id. + * @type int instanceid Instance id of the scorm activity. + * } + * @package mod_scorm + * @copyright 2013 onwards Ankit Agarwal + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class interactions_viewed extends \core\event\base { + + /** + * Init method. + */ + protected function init() { + $this->data['crud'] = 'r'; + $this->data['level'] = self::LEVEL_TEACHING; + } + + /** + * Returns non-localised description of what happened. + * + * @return string + */ + public function get_description() { + return 'User with id ' . $this->userid . ' viewed interactions for user ' . $this->relateduserid; + } + + /** + * Returns localised general event name. + * + * @return string + */ + public static function get_name() { + return get_string('eventinteractionsviewed', 'mod_scorm'); + } + + /** + * Get URL related to the action + * + * @return \moodle_url + */ + public function get_url() { + $params = array( + 'id' => $this->context->instanceid, + 'user' => $this->relateduserid, + 'attempt' => $this->other['attemptid'] + ); + return new \moodle_url('/mod/scorm/userreportinteractions.php', $params); + } + + /** + * Return the legacy event log data. + * + * @return array + */ + protected function get_legacy_logdata() { + return array($this->courseid, 'scorm', 'userreportinteractions', 'report/userreportinteractions.php?id=' . + $this->context->instanceid . '&user=' . $this->relateduserid . '&attempt=' . $this->other['attemptid'], + $this->other['instanceid'], $this->context->instanceid); + } + + /** + * Custom validation. + * + * @throws \coding_exception + * @return void + */ + protected function validate_data() { + if (empty($this->other['attemptid'])) { + throw new \coding_exception('The \\mod_scorm\\event\\interactions_viewed must specify attemptid.'); + } + if (empty($this->other['instanceid'])) { + throw new \coding_exception('The \\mod_scorm\\event\\interactions_viewed must specify instanceid of the activity.'); + } + } +} diff --git a/mod/scorm/classes/event/report_viewed.php b/mod/scorm/classes/event/report_viewed.php new file mode 100644 index 00000000000..d55b69ab8b4 --- /dev/null +++ b/mod/scorm/classes/event/report_viewed.php @@ -0,0 +1,100 @@ +. + +/** + * This file contains an event for when a scorm report is viewed. + * + * @package mod_scorm + * @copyright 2013 onwards Ankit Agarwal + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace mod_scorm\event; +defined('MOODLE_INTERNAL') || die(); + +/** + * Event for when a scorm report is viewed. + * + * @property-read array $other { + * Extra information about event properties. + * + * @string mode Mode of the report viewed. + * } + * @package mod_scorm + * @copyright 2013 onwards Ankit Agarwal + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class report_viewed extends \core\event\base { + + /** + * Init method. + */ + protected function init() { + $this->data['crud'] = 'r'; + $this->data['level'] = self::LEVEL_TEACHING; + $this->data['objecttable'] = 'scorm'; + } + + /** + * Returns non-localised description of what happened. + * + * @return string + */ + public function get_description() { + return 'User with id ' . $this->userid . ' viewed scorm report (' . $this->other['mode'] . ') with instanceid ' . + $this->objectid; + } + + /** + * Returns localised general event name. + * + * @return string + */ + public static function get_name() { + return get_string('eventreportviewed', 'mod_scorm'); + } + + /** + * Get URL related to the action + * + * @return \moodle_url + */ + public function get_url() { + return new \moodle_url('/mod/scorm/report.php', array('id' => $this->context->instanceid, 'mode' => $this->other['mode'])); + } + + /** + * Replace add_to_log() statement. + * + * @return array of parameters to be passed to legacy add_to_log() function. + */ + protected function get_legacy_logdata() { + return array($this->courseid, 'scorm', 'report', 'report.php?id=' . $this->context->instanceid . + '&mode=' . $this->other['mode'], $this->objectid, $this->context->instanceid); + } + + /** + * Custom validation. + * + * @throws \coding_exception + * @return void + */ + protected function validate_data() { + if (empty($this->other['mode'])) { + throw new \coding_exception('The event must specify mode to define which report was viewed.'); + } + } +} diff --git a/mod/scorm/classes/event/sco_launched.php b/mod/scorm/classes/event/sco_launched.php new file mode 100644 index 00000000000..72f0fce2286 --- /dev/null +++ b/mod/scorm/classes/event/sco_launched.php @@ -0,0 +1,101 @@ +. + +/** + * This file contains an event for when sco is loaded. + * + * @package mod_scorm + * @copyright 2013 onwards Ankit Agarwal + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace mod_scorm\event; +defined('MOODLE_INTERNAL') || die(); + +/** + * Event for when a sco is loaded. + * + * @property-read array $other { + * Extra information about event properties. + * + * @type string loadedcontent A reference to the content loaded. + * @type int instanceid Instance id of the scorm activity. + * } + * + * @package mod_scorm + * @copyright 2013 onwards Ankit Agarwal + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class sco_launched extends \core\event\base { + + /** + * Init method. + */ + protected function init() { + $this->data['crud'] = 'r'; + $this->data['level'] = self::LEVEL_PARTICIPATING; + $this->data['objecttable'] = 'scorm_scoes'; + } + + /** + * Returns non-localised description of what happened. + * + * @return string + */ + public function get_description() { + return 'User with id ' . $this->userid . ' launched a sco with id ' . $this->objectid; + } + + /** + * Returns localised general event name. + * + * @return string + */ + public static function get_name() { + return get_string('eventscolaunched', 'mod_scorm'); + } + + /** + * Get URL related to the action + * + * @return \moodle_url + */ + public function get_url() { + return new \moodle_url('/mod/scorm/player.php', array('id' => $this->context->instanceid, 'scoid' => $this->objectid)); + } + + /** + * Replace add_to_log() statement. + * + * @return array of parameters to be passed to legacy add_to_log() function. + */ + protected function get_legacy_logdata() { + return array($this->courseid, 'scorm', 'launch', 'view.php?id=' . $this->context->instanceid, + $this->other['loadedcontent'], $this->context->instanceid); + } + + /** + * Custom validation. + * + * @throws \coding_exception + * @return void + */ + protected function validate_data() { + if (empty($this->other['loadedcontent'])) { + throw new \coding_exception('The event mod_scorm\\event\\sco_launched must specify loadedcontent.'); + } + } +} diff --git a/mod/scorm/classes/event/tracks_viewed.php b/mod/scorm/classes/event/tracks_viewed.php new file mode 100644 index 00000000000..03ecaa1b3cd --- /dev/null +++ b/mod/scorm/classes/event/tracks_viewed.php @@ -0,0 +1,114 @@ +. + +/** + * This file contains an event for when user tracks is viewed. + * + * @package mod_scorm + * @copyright 2013 onwards Ankit Agarwal + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace mod_scorm\event; +defined('MOODLE_INTERNAL') || die(); + +/** + * Event for when a user tracks is viewed. + * + * @property-read array $other { + * Extra information about event properties. + * + * @type int attemptid Attempt id. + * @type int instanceid Instance id of the scorm activity. + * @type int scoid Sco Id for which the trackes are viewed. + * } + * @package mod_scorm + * @copyright 2013 onwards Ankit Agarwal + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class tracks_viewed extends \core\event\base { + + /** + * Init method. + */ + protected function init() { + $this->data['crud'] = 'r'; + $this->data['level'] = self::LEVEL_TEACHING; + } + + /** + * Returns non-localised description of what happened. + * + * @return string + */ + public function get_description() { + return 'User with id ' . $this->userid . ' viewed interactions for user ' . $this->relateduserid; + } + + /** + * Returns localised general event name. + * + * @return string + */ + public static function get_name() { + return get_string('eventtracksviewed', 'mod_scorm'); + } + + /** + * Get URL related to the action + * + * @return \moodle_url + */ + public function get_url() { + $params = array( + 'id' => $this->context->instanceid, + 'user' => $this->relateduserid, + 'attempt' => $this->other['attemptid'], + 'scoid' => $this->other['scoid'] + ); + return new \moodle_url('/mod/scorm/userreporttracks.php', $params); + } + + /** + * Return the legacy event log data. + * + * @return array + */ + protected function get_legacy_logdata() { + return array($this->courseid, 'scorm', 'userreporttracks', 'report/userreporttracks.php?id=' . $this->context->instanceid + . '&user=' . $this->relateduserid . '&attempt=' . $this->other['attemptid'] . '&scoid=' . $this->other['scoid'], + $this->other['instanceid'], $this->context->instanceid); + } + + /** + * Custom validation. + * + * @throws \coding_exception + * @return void + */ + protected function validate_data() { + if (empty($this->other['attemptid'])) { + throw new \coding_exception('The \\mod_scorm\\event\\tracks_viewed must specify attemptid.'); + } + if (empty($this->other['instanceid'])) { + throw new \coding_exception('The \\mod_scorm\\event\\tracks_viewed must specify instanceid of the activity.'); + } + if (empty($this->other['scoid'])) { + throw new \coding_exception('The \\mod_scorm\\event\\tracks_viewed must specify scoid for the report.'); + } + parent::validate_data(); + } +} diff --git a/mod/scorm/classes/event/user_report_viewed.php b/mod/scorm/classes/event/user_report_viewed.php new file mode 100644 index 00000000000..20b490359b6 --- /dev/null +++ b/mod/scorm/classes/event/user_report_viewed.php @@ -0,0 +1,108 @@ +. + +/** + * This file contains an event for when a user report is viewed. + * + * @package mod_scorm + * @copyright 2013 onwards Ankit Agarwal + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace mod_scorm\event; +defined('MOODLE_INTERNAL') || die(); + +/** + * Event for when a user report is viewed. + * + * @property-read array $other { + * Extra information about event properties. + * + * @type int attemptid Attempt id. + * @type int instanceid Instance id of the scorm activity. + * } + * @package mod_scorm + * @copyright 2013 onwards Ankit Agarwal + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class user_report_viewed extends \core\event\base { + + /** + * Init method. + */ + protected function init() { + $this->data['crud'] = 'r'; + $this->data['level'] = self::LEVEL_TEACHING; + } + + /** + * Returns non-localised description of what happened. + * + * @return string + */ + public function get_description() { + return 'User with id ' . $this->userid . ' viewed user report for user ' . $this->relateduserid; + } + + /** + * Returns localised general event name. + * + * @return string + */ + public static function get_name() { + return get_string('eventuserreportviewed', 'mod_scorm'); + } + + /** + * Get URL related to the action + * + * @return \moodle_url + */ + public function get_url() { + $params = array( + 'id' => $this->context->instanceid, + 'user' => $this->relateduserid, + 'attempt' => $this->other['attemptid'] + ); + return new \moodle_url('/mod/scorm/userreport.php', $params); + } + + /** + * Return the legacy event log data. + * + * @return array + */ + protected function get_legacy_logdata() { + return array($this->courseid, 'scorm', 'userreport', 'report/userreport.php?id=' . + $this->context->instanceid . '&user=' . $this->relateduserid . '&attempt=' . $this->other['attemptid'], + $this->other['instanceid'], $this->context->instanceid); + } + + /** + * Custom validation. + * + * @throws \coding_exception + * @return void + */ + protected function validate_data() { + if (empty($this->other['attemptid'])) { + throw new \coding_exception('The \\mod_scorm\\event\\user_report_viewed must specify attemptid.'); + } + if (empty($this->other['instanceid'])) { + throw new \coding_exception('The \\mod_scorm\\event\\user_report_viewed must specify instanceid of the activity.'); + } + } +}