Exemple #1
0
 /**
  * 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\n                    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\n                    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\n                    other['scoid']");
     } catch (Exception $e) {
         $this->assertInstanceOf('coding_exception', $e);
     }
 }
$download = optional_param('download', '', PARAM_ALPHA);
// Building the url to use for links.+ data details buildup.
$url = new moodle_url('/mod/scorm/report/userreporttracks.php', array('id' => $id, 'user' => $userid, 'attempt' => $attempt, 'scoid' => $scoid));
$cm = get_coursemodule_from_id('scorm', $id, 0, false, MUST_EXIST);
$course = get_course($cm->course);
$scorm = $DB->get_record('scorm', array('id' => $cm->instance), '*', MUST_EXIST);
$user = $DB->get_record('user', array('id' => $userid), user_picture::fields(), MUST_EXIST);
$selsco = $DB->get_record('scorm_scoes', array('id' => $scoid), '*', MUST_EXIST);
$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);
// 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');
$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("{$strattempt} {$attempt} - " . fullname($user), new moodle_url('/mod/scorm/report/userreport.php', array('id' => $id, 'user' => $userid, 'attempt' => $attempt)));
$PAGE->navbar->add($selsco->title . ' - ' . get_string('details', 'scorm'));
if ($trackdata = scorm_get_tracks($selsco->id, $userid, $attempt)) {
    if ($trackdata->status == '') {
        $trackdata->status = 'notattempted';
    }