--- /dev/null
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * 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();
+ }
+}
--- /dev/null
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * 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 {
+}
+
--- /dev/null
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * 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);
+ }
+}
+
--- /dev/null
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * 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.');
+ }
+ }
+}
--- /dev/null
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * 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.');
+ }
+ }
+}
--- /dev/null
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * 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.');
+ }
+ }
+}
--- /dev/null
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * 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();
+ }
+}
--- /dev/null
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * 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.');
+ }
+ }
+}
require_course_login($course);
$PAGE->set_pagelayout('incourse');
-add_to_log($course->id, "scorm", "view all", "index.php?id=$course->id", "");
+// Trigger instances list viewed event.
+$event = \mod_scorm\event\course_module_instance_list_viewed::create(array('context' => context_course::instance($course->id)));
+$event->trigger();
$strscorm = get_string("modulename", "scorm");
$strscorms = get_string("modulenameplural", "scorm");
$string['enter'] = 'Enter';
$string['entercourse'] = 'Enter course';
$string['errorlogs'] = 'Errors log';
+$string['eventattemptdeleted'] = 'Attempt deleted';
+$string['eventinteractionsviewed'] = 'Interactions viewed';
+$string['eventreportviewed'] = 'Report viewed';
+$string['eventscolaunched'] = 'Sco launched';
+$string['eventtracksviewed'] = 'Tracks viewed';
+$string['eventuserreportviewed'] = 'User report viewed';
$string['everyday'] = 'Every day';
$string['everytime'] = 'Every time it\'s used';
$string['exceededmaxattempts'] = 'You have reached the maximum number of attempts.';
$result = "$CFG->wwwroot/pluginfile.php/$context->id/mod_scorm/content/$scorm->revision/$launcher";
}
-add_to_log($course->id, 'scorm', 'launch', 'view.php?id='.$cm->id, $result, $cm->id);
+// Trigger a Sco launched event.
+$event = \mod_scorm\event\sco_launched::create(array(
+ 'objectid' => $sco->id,
+ 'context' => $context,
+ 'other' => array('instanceid' => $scorm->id, 'loadedcontent' => $result)
+));
+$event->add_record_snapshot('course_modules', $cm);
+$event->add_record_snapshot('scorm', $scorm);
+$event->add_record_snapshot('scorm_scoes', $sco);
+$event->trigger();
header('Content-Type: text/html; charset=UTF-8');
* Delete Scorm tracks for selected users
*
* @param array $attemptids list of attempts that need to be deleted
- * @param int $scorm instance
+ * @param stdClass $scorm instance
*
- * return bool true deleted all responses, false failed deleting an attempt - stopped here
+ * @return bool true deleted all responses, false failed deleting an attempt - stopped here
*/
function scorm_delete_responses($attemptids, $scorm) {
if (!is_array($attemptids) || empty($attemptids)) {
* Delete Scorm tracks for selected users
*
* @param int $userid ID of User
- * @param int $scormid ID of Scorm
+ * @param stdClass $scorm Scorm object
* @param int $attemptid user attempt that need to be deleted
*
- * return bool true suceeded
+ * @return bool true suceeded
*/
function scorm_delete_attempt($userid, $scorm, $attemptid) {
global $DB;
$DB->delete_records('scorm_scoes_track', array('userid' => $userid, 'scormid' => $scorm->id, 'attempt' => $attemptid));
+ $cm = get_coursemodule_from_instance('scorm', $scorm->id);
+
+ // Trigger instances list viewed event.
+ $event = \mod_scorm\event\attempt_deleted::create(array(
+ 'other' => array('attemptid' => $attemptid),
+ 'context' => context_module::instance($cm->instance),
+ 'relateduserid' => $userid
+ ));
+ $event->add_record_snapshot('course_modules', $cm);
+ $event->add_record_snapshot('scorm', $scorm);
+ $event->trigger();
+
include_once('lib.php');
scorm_update_grades($scorm, $userid, true);
return true;
exit;
}
-add_to_log($course->id, 'scorm', 'view', "player.php?cm=$cm->id&scoid=$sco->id", "$scorm->id", $cm->id);
-
-
$scoidstr = '&scoid='.$sco->id;
$modestr = '&mode='.$mode;
print_error('erroraccessingreport', 'scorm');
}
-add_to_log($course->id, 'scorm', 'report', 'report.php?id='.$cm->id, $scorm->id, $cm->id);
+// Trigger a report viewed event.
+$event = \mod_scorm\event\report_viewed::create(array(
+ 'objectid' => $scorm->id,
+ 'context' => $contextmodule,
+ 'other' => array('mode' => $mode)
+));
+$event->add_record_snapshot('course_modules', $cm);
+$event->add_record_snapshot('scorm', $scorm);
+$event->trigger();
+
$userdata = null;
if (!empty($download)) {
$noheader = true;
if ($action == 'delete' && has_capability('mod/scorm:deleteresponses', $contextmodule) && confirm_sesskey()) {
if (scorm_delete_responses($attemptids, $scorm)) { //delete responses.
- add_to_log($course->id, 'scorm', 'delete attempts', 'report.php?id=' . $cm->id, implode(",", $attemptids), $cm->id);
echo $OUTPUT->notification(get_string('scormresponsedeleted', 'scorm'), 'notifysuccess');
}
}
if ($action == 'delete' && has_capability('mod/scorm:deleteresponses', $contextmodule) && confirm_sesskey()) {
if (scorm_delete_responses($attemptids, $scorm)) { //delete responses.
- add_to_log($course->id, 'scorm', 'delete attempts', 'report.php?id=' . $cm->id, implode(",", $attemptids), $cm->id);
echo $OUTPUT->notification(get_string('scormresponsedeleted', 'scorm'), 'notifysuccess');
}
}
if ($action == 'delete' && has_capability('mod/scorm:deleteresponses', $contextmodule) && confirm_sesskey()) {
if (scorm_delete_responses($attemptids, $scorm)) { // Delete responses.
- add_to_log($course->id, 'scorm', 'delete attempts', 'report.php?id=' . $cm->id, implode(",", $attemptids), $cm->id);
echo $OUTPUT->notification(get_string('scormresponsedeleted', 'scorm'), 'notifysuccess');
}
}
$contextmodule = context_module::instance($cm->id);
require_capability('mod/scorm:viewreport', $contextmodule);
-add_to_log($course->id, 'scorm', 'userreport', 'userreport.php?id='.$id, $scorm->id, $id);
+// Trigger a user report viewed event.
+$event = \mod_scorm\event\user_report_viewed::create(array(
+ 'context' => $contextmodule,
+ 'relateduserid' => $userid,
+ 'other' => array('attemptid' => $attempt, 'instanceid' => $scorm->id)
+));
+$event->add_record_snapshot('course_modules', $cm);
+$event->add_record_snapshot('scorm', $scorm);
+$event->trigger();
// Print the page header.
$strreport = get_string('report', 'scorm');
$contextmodule = context_module::instance($cm->id);
require_capability('mod/scorm:viewreport', $contextmodule);
-add_to_log($course->id, 'scorm', 'userreportinteractions', 'userreportinteractions.php?id='.$cm->id, $scorm->id, $cm->id);
-
+// Trigger a user interactions viewed event.
+$event = \mod_scorm\event\interactions_viewed::create(array(
+ 'context' => $contextmodule,
+ 'relateduserid' => $userid,
+ 'other' => array('attemptid' => $attempt, 'instanceid' => $scorm->id)
+));
+$event->add_record_snapshot('course_modules', $cm);
+$event->add_record_snapshot('scorm', $scorm);
+$event->trigger();
$trackdata = $DB->get_records('scorm_scoes_track', array('userid' => $user->id, 'scormid' => $scorm->id,
'attempt' => $attempt));
$contextmodule = context_module::instance($cm->id);
require_capability('mod/scorm:viewreport', $contextmodule);
-add_to_log($course->id, 'scorm', 'userreporttracks', 'userreporttracks.php?id='.$id, $scorm->id, $id);
+// Trigger a tracks viewed event.
+$event = \mod_scorm\event\tracks_viewed::create(array(
+ 'context' => $contextmodule,
+ 'relateduserid' => $userid,
+ 'other' => array('attemptid' => $attempt, 'instanceid' => $scorm->id, 'scoid' => $scoid)
+));
+$event->add_record_snapshot('course_modules', $cm);
+$event->add_record_snapshot('scorm', $scorm);
+$event->trigger();
// Print the page header.
$strreport = get_string('report', 'scorm');
--- /dev/null
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * This file contains tests for scorm events.
+ *
+ * @package mod_scorm
+ * @copyright 2013 onwards Ankit Agarwal
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+global $CFG;
+require_once($CFG->dirroot . '/mod/scorm/locallib.php');
+require_once($CFG->dirroot . '/mod/scorm/lib.php');
+
+/**
+ * Test class for various events related to Scorm.
+ *
+ * @package mod_scorm
+ * @copyright 2013 onwards Ankit Agarwal
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class mod_scorm_event_testcase extends advanced_testcase {
+
+ /** @var stdClass store course object */
+ protected $eventcourse;
+
+ /** @var stdClass store user object */
+ protected $eventuser;
+
+ /** @var stdClass store scorm object */
+ protected $eventscorm;
+
+ /** @var stdClass store course module object */
+ protected $eventcm;
+
+ protected function setUp() {
+ $this->setAdminUser();
+ $this->eventcourse = $this->getDataGenerator()->create_course();
+ $this->eventuser = $this->getDataGenerator()->create_user();
+ $record = new stdClass();
+ $record->course = $this->eventcourse->id;
+ $this->eventscorm = $this->getDataGenerator()->create_module('scorm', $record);
+ $this->eventcm = get_coursemodule_from_instance('scorm', $this->eventscorm->id);
+ }
+
+ /** Tests for attempt deleted event */
+ public function test_attempt_deleted_event() {
+
+ global $USER;
+
+ $this->resetAfterTest();
+ scorm_insert_track(2, $this->eventscorm->id, 1, 4, 'cmi.core.score.raw', 10);
+ $sink = $this->redirectEvents();
+ scorm_delete_attempt(2, $this->eventscorm, 4);
+ $events = $sink->get_events();
+ $sink->close();
+ $event = reset($events);
+
+ // Verify data.
+ $this->assertCount(1, $events);
+ $this->assertInstanceOf('\mod_scorm\event\attempt_deleted', $event);
+ $this->assertEquals($USER->id, $event->userid);
+ $this->assertEquals(context_module::instance($this->eventscorm->id), $event->get_context());
+ $this->assertEquals(4, $event->other['attemptid']);
+ $this->assertEquals(2, $event->relateduserid);
+ $expected = array($this->eventcourse->id, 'scorm', 'delete attempts', 'report.php?id=' . $this->eventcm->id,
+ 4, $this->eventscorm->id);
+ $this->assertEventLegacyLogData($expected, $events[0]);
+
+ // Test event validations.
+ $this->setExpectedException('coding_exception');
+ \mod_scorm\event\attempt_deleted::create(array(
+ 'contextid' => 5,
+ 'relateduserid' => 2
+ ));
+ $this->fail('event \\mod_scorm\\event\\attempt_deleted is not validating events properly');
+ }
+
+ /**
+ * Tests for course module viewed event.
+ *
+ * There is no api involved so the best we can do is test legacy data by triggering event manually.
+ */
+ public function test_course_module_viewed_event() {
+ $this->resetAfterTest();
+ $event = \mod_scorm\event\course_module_viewed::create(array(
+ 'objectid' => $this->eventscorm->id,
+ 'context' => context_module::instance($this->eventcm->id),
+ 'courseid' => $this->eventcourse->id
+ ));
+
+ // Trigger and capture the event.
+ $sink = $this->redirectEvents();
+ $event->trigger();
+ $events = $sink->get_events();
+ $event = reset($events);
+
+ // Check that the legacy log data is valid.
+ $expected = array($this->eventcourse->id, 'scorm', 'pre-view', 'view.php?id=' . $this->eventcm->id,
+ $this->eventscorm->id, $this->eventcm->id);
+ $this->assertEventLegacyLogData($expected, $event);
+ }
+
+ /**
+ * Tests for instance list viewed event.
+ *
+ * There is no api involved so the best we can do is test legacy data by triggering event manually.
+ */
+ public function test_course_module_instance_list_viewed_event() {
+ $this->resetAfterTest();
+ $event = \mod_scorm\event\course_module_instance_list_viewed::create(array(
+ 'context' => context_course::instance($this->eventcourse->id),
+ 'courseid' => $this->eventcourse->id
+ ));
+
+ // Trigger and capture the event.
+ $sink = $this->redirectEvents();
+ $event->trigger();
+ $events = $sink->get_events();
+ $event = reset($events);
+
+ // Check that the legacy log data is valid.
+ $expected = array($this->eventcourse->id, 'scorm', 'view all', 'index.php?id=' . $this->eventcourse->id, '');
+ $this->assertEventLegacyLogData($expected, $event);
+ }
+
+ /**
+ * Tests for interactions viewed.
+ *
+ * There is no api involved so the best we can do is test legacy data by triggering event manually and test validations.
+ */
+ public function test_interactions_viewed_event() {
+ $this->resetAfterTest();
+ $event = \mod_scorm\event\interactions_viewed::create(array(
+ 'relateduserid' => 5,
+ 'context' => context_module::instance($this->eventcm->id),
+ 'courseid' => $this->eventcourse->id,
+ 'other' => array('attemptid' => 2, 'instanceid' => $this->eventscorm->id)
+ ));
+
+ // Trigger and capture the event.
+ $sink = $this->redirectEvents();
+ $event->trigger();
+ $events = $sink->get_events();
+ $event = reset($events);
+
+ // Check that the legacy log data is valid.
+ $expected = array($this->eventcourse->id, 'scorm', 'userreportinteractions', 'report/userreportinteractions.php?id=' .
+ $this->eventcm->id . '&user=5&attempt=' . 2, $this->eventscorm->id, $this->eventcm->id);
+ $this->assertEventLegacyLogData($expected, $event);
+ }
+
+ /**
+ * Tests for interactions viewed validations.
+ */
+ public function test_interactions_viewed_event_validations() {
+ $this->resetAfterTest();
+ try {
+ \mod_scorm\event\interactions_viewed::create(array(
+ 'context' => context_module::instance($this->eventcm->id),
+ 'courseid' => $this->eventcourse->id,
+ 'other' => array('attemptid' => 2)
+ ));
+ $this->fail("Event validation should not allow \\mod_scorm\\event\\interactions_viewed to be triggered without
+ other['instanceid']");
+ } catch (Exception $e) {
+ $this->assertInstanceOf('coding_exception', $e);
+ }
+ try {
+ \mod_scorm\event\interactions_viewed::create(array(
+ 'context' => context_module::instance($this->eventcm->id),
+ 'courseid' => $this->eventcourse->id,
+ 'other' => array('instanceid' => 2)
+ ));
+ $this->fail("Event validation should not allow \\mod_scorm\\event\\interactions_viewed to be triggered without
+ other['attemptid']");
+ } catch (Exception $e) {
+ $this->assertInstanceOf('coding_exception', $e);
+ }
+ }
+
+ /** Tests for report viewed.
+ *
+ * There is no api involved so the best we can do is test legacy data and validations by triggering event manually.
+ */
+ public function test_report_viewed_event() {
+ $this->resetAfterTest();
+ $event = \mod_scorm\event\report_viewed::create(array(
+ 'objectid' => $this->eventscorm->id,
+ 'context' => context_module::instance($this->eventcm->id),
+ 'courseid' => $this->eventcourse->id,
+ 'other' => array('mode' => 'basic')
+ ));
+
+ // Trigger and capture the event.
+ $sink = $this->redirectEvents();
+ $event->trigger();
+ $events = $sink->get_events();
+ $event = reset($events);
+
+ // Check that the legacy log data is valid.
+ $expected = array($this->eventcourse->id, 'scorm', 'report', 'report.php?id=' . $this->eventcm->id . '&mode=basic',
+ $this->eventscorm->id, $this->eventcm->id);
+ $this->assertEventLegacyLogData($expected, $event);
+
+ // Test validations.
+ $this->setExpectedException('coding_exception');
+ \mod_scorm\event\report_viewed::create(array(
+ 'objectid' => $this->eventscorm->id,
+ 'context' => context_module::instance($this->eventcm->id),
+ 'courseid' => $this->eventcourse->id
+ ));
+ $this->fail('Event \\mod_scorm\\event\\report_viewed is not validating "mode" properly');
+ }
+
+ /** Tests for sco launched event.
+ *
+ * There is no api involved so the best we can do is test legacy data and validations by triggering event manually.
+ */
+ public function test_sco_launched_event() {
+ $this->resetAfterTest();
+ $event = \mod_scorm\event\sco_launched::create(array(
+ 'objectid' => 2,
+ 'context' => context_module::instance($this->eventcm->id),
+ 'courseid' => $this->eventcourse->id,
+ 'other' => array('loadedcontent' => 'url_to_content_that_was_laoded.php')
+ ));
+
+ // Trigger and capture the event.
+ $sink = $this->redirectEvents();
+ $event->trigger();
+ $events = $sink->get_events();
+ $event = reset($events);
+
+ // Check that the legacy log data is valid.
+ $expected = array($this->eventcourse->id, 'scorm', 'launch', 'view.php?id=' . $this->eventcm->id,
+ 'url_to_content_that_was_laoded.php', $this->eventcm->id);
+ $this->assertEventLegacyLogData($expected, $event);
+
+ // Test validations.
+ $this->setExpectedException('coding_exception');
+ \mod_scorm\event\sco_launched::create(array(
+ 'objectid' => $this->eventscorm->id,
+ 'context' => context_module::instance($this->eventcm->id),
+ 'courseid' => $this->eventcourse->id,
+ ));
+ $this->fail('Event \\mod_scorm\\event\\sco_launched is not validating "loadedcontent" properly');
+ }
+
+ /**
+ * Tests for tracks viewed event.
+ *
+ * There is no api involved so the best we can do is test validations by triggering event manually.
+ */
+ public function test_tracks_viewed_event() {
+ $this->resetAfterTest();
+ $event = \mod_scorm\event\tracks_viewed::create(array(
+ 'relateduserid' => 5,
+ 'context' => context_module::instance($this->eventcm->id),
+ 'courseid' => $this->eventcourse->id,
+ 'other' => array('attemptid' => 2, 'instanceid' => $this->eventscorm->id, 'scoid' => 3)
+ ));
+
+ // Trigger and capture the event.
+ $sink = $this->redirectEvents();
+ $event->trigger();
+ $events = $sink->get_events();
+ $event = reset($events);
+
+ // Check that the legacy log data is valid.
+ $expected = array($this->eventcourse->id, 'scorm', 'userreporttracks', 'report/userreporttracks.php?id=' .
+ $this->eventcm->id . '&user=5&attempt=' . 2 . '&scoid=3', $this->eventscorm->id, $this->eventcm->id);
+ $this->assertEventLegacyLogData($expected, $event);
+ }
+
+ /**
+ * Tests for tracks viewed event validations.
+ */
+ public function test_tracks_viewed_event_validations() {
+ $this->resetAfterTest();
+ try {
+ \mod_scorm\event\tracks_viewed::create(array(
+ 'context' => context_module::instance($this->eventcm->id),
+ 'courseid' => $this->eventcourse->id,
+ 'other' => array('attemptid' => 2, 'scoid' => 2)
+ ));
+ $this->fail("Event validation should not allow \\mod_scorm\\event\\tracks_viewed to be triggered without
+ other['instanceid']");
+ } catch (Exception $e) {
+ $this->assertInstanceOf('coding_exception', $e);
+ }
+ try {
+ \mod_scorm\event\tracks_viewed::create(array(
+ 'context' => context_module::instance($this->eventcm->id),
+ 'courseid' => $this->eventcourse->id,
+ 'other' => array('instanceid' => 2, 'scoid' => 2)
+ ));
+ $this->fail("Event validation should not allow \\mod_scorm\\event\\tracks_viewed to be triggered without
+ other['attemptid']");
+ } catch (Exception $e) {
+ $this->assertInstanceOf('coding_exception', $e);
+ }
+
+ try {
+ \mod_scorm\event\tracks_viewed::create(array(
+ 'context' => context_module::instance($this->eventcm->id),
+ 'courseid' => $this->eventcourse->id,
+ 'other' => array('attemptid' => 2, 'instanceid' => 2)
+ ));
+ $this->fail("Event validation should not allow \\mod_scorm\\event\\tracks_viewed to be triggered without
+ other['scoid']");
+ } catch (Exception $e) {
+ $this->assertInstanceOf('coding_exception', $e);
+ }
+ }
+
+ /**
+ * Tests for userreport viewed event.
+ *
+ * There is no api involved so the best we can do is test validations and legacy log by triggering event manually.
+ */
+ public function test_user_report_viewed_event() {
+ $this->resetAfterTest();
+ $event = \mod_scorm\event\user_report_viewed::create(array(
+ 'relateduserid' => 5,
+ 'context' => context_module::instance($this->eventcm->id),
+ 'courseid' => $this->eventcourse->id,
+ 'other' => array('attemptid' => 2, 'instanceid' => $this->eventscorm->id)
+ ));
+
+ // Trigger and capture the event.
+ $sink = $this->redirectEvents();
+ $event->trigger();
+ $events = $sink->get_events();
+ $event = reset($events);
+
+ // Check that the legacy log data is valid.
+ $expected = array($this->eventcourse->id, 'scorm', 'userreport', 'report/userreport.php?id=' .
+ $this->eventcm->id . '&user=5&attempt=' . 2, $this->eventscorm->id, $this->eventcm->id);
+ $this->assertEventLegacyLogData($expected, $event);
+ }
+
+ /**
+ * Tests for userreport viewed event validations.
+ */
+ public function test_user_report_viewed_event_validations() {
+ $this->resetAfterTest();
+ try {
+ \mod_scorm\event\user_report_viewed::create(array(
+ 'context' => context_module::instance($this->eventcm->id),
+ 'courseid' => $this->eventcourse->id,
+ 'other' => array('attemptid' => 2)
+ ));
+ $this->fail("Event validation should not allow \\mod_scorm\\event\\user_report_viewed to be triggered without
+ other['instanceid']");
+ } catch (Exception $e) {
+ $this->assertInstanceOf('coding_exception', $e);
+ }
+ try {
+ \mod_scorm\event\user_report_viewed::create(array(
+ 'context' => context_module::instance($this->eventcm->id),
+ 'courseid' => $this->eventcourse->id,
+ 'other' => array('instanceid' => 2)
+ ));
+ $this->fail("Event validation should not allow \\mod_scorm\\event\\user_report_viewed to be triggered without
+ other['attemptid']");
+ } catch (Exception $e) {
+ $this->assertInstanceOf('coding_exception', $e);
+ }
+ }
+}
+
$shortname = format_string($course->shortname, true, array('context' => $context));
$pagetitle = strip_tags($shortname.': '.format_string($scorm->name));
-add_to_log($course->id, 'scorm', 'pre-view', 'view.php?id='.$cm->id, "$scorm->id", $cm->id);
+// Trigger module viewed event.
+$event = \mod_scorm\event\course_module_viewed::create(array(
+ 'objectid' => $scorm->id,
+ 'context' => $contextmodule,
+));
+$event->add_record_snapshot('scorm', $scorm);
+$event->add_record_snapshot('course_modules', $cm);
+$event->trigger();
if (empty($launch) && (has_capability('mod/scorm:skipview', $contextmodule))) {
scorm_simple_play($scorm, $USER, $contextmodule, $cm->id);