$scorm = $DB->get_record('scorm', array('id' => $cm->instance), '*', MUST_EXIST); $user = $DB->get_record('user', array('id' => $userid), user_picture::fields(), MUST_EXIST); // Get list of attempts this user has made. $attemptids = scorm_get_all_attempts($scorm->id, $userid); $PAGE->set_url($url); // END of url setting + data buildup. // Checking login +logging +getting context. require_login($course, false, $cm); $contextmodule = context_module::instance($cm->id); require_capability('mod/scorm:viewreport', $contextmodule); // Check user has group access. if (!groups_user_groups_visible($course, $userid, $cm)) { throw new moodle_exception('nopermissiontoshow'); } // 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'); $strattempt = get_string('attempt', 'scorm'); $PAGE->set_title("{$course->shortname}: " . format_string($scorm->name)); $PAGE->set_heading($course->fullname); $PAGE->navbar->add($strreport, new moodle_url('/mod/scorm/report.php', array('id' => $cm->id))); $PAGE->navbar->add(fullname($user) . " - {$strattempt} {$attempt}"); echo $OUTPUT->header(); echo $OUTPUT->heading(format_string($scorm->name)); // End of Print the page header. $currenttab = 'scoes'; require $CFG->dirroot . '/mod/scorm/report/userreporttabs.php';
/** * 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\n 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\n other['attemptid']"); } catch (Exception $e) { $this->assertInstanceOf('coding_exception', $e); } }