示例#1
0
$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 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));
$usertrack = scorm_format_interactions($trackdata);
$questioncount = get_scorm_question_count($scorm->id);
$courseshortname = format_string($course->shortname, true, array('context' => context_course::instance($course->id)));
$exportfilename = $courseshortname . '-' . format_string($scorm->name, true) . '-' . get_string('interactions', 'scorm');
// Set up the table.
$table = new flexible_table('mod-scorm-userreport-interactions');
if (!$table->is_downloading($download, $exportfilename)) {
    // Print the page header.
    $strattempt = get_string('attempt', 'scorm');
    $strreport = get_string('report', 'scorm');
    $PAGE->set_title("{$course->shortname}: " . format_string($scorm->name));
示例#2
0
 /**
  * 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\n                    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\n                    other['attemptid']");
     } catch (Exception $e) {
         $this->assertInstanceOf('coding_exception', $e);
     }
 }