예제 #1
0
 /**
  * Test to ensure that event data is being stored correctly.
  */
 public function test_course_module_viewed()
 {
     global $USER;
     // Generate user data.
     $this->setAdminUser();
     $eventdata = array();
     $eventdata['objectid'] = $this->randchoice->id;
     $eventdata['context'] = $this->context;
     $eventdata['courseid'] = $this->course->id;
     $eventdata['other']['content'] = 'pageresourceview';
     // This is fired in a page view so we can't run this through a function.
     $event = \mod_randchoice\event\course_module_viewed::create($eventdata);
     // Redirect event.
     $sink = $this->redirectEvents();
     $event->trigger();
     $event = $sink->get_events();
     // Data checking.
     $this->assertCount(1, $event);
     $this->assertInstanceOf('\\mod_randchoice\\event\\course_module_viewed', $event[0]);
     $this->assertEquals($USER->id, $event[0]->userid);
     $this->assertEquals(context_module::instance($this->randchoice->cmid), $event[0]->get_context());
     $expected = array($this->course->id, "randchoice", "view", 'view.php?id=' . $this->context->instanceid, $this->randchoice->id, $this->context->instanceid);
     $this->assertEventLegacyLogData($expected, $event[0]);
     $this->assertEventContextNotUsed($event[0]);
     $sink->close();
 }
예제 #2
0
echo $OUTPUT->header();
echo $OUTPUT->heading(format_string($randchoice->name), 2, null);
if ($notify and confirm_sesskey()) {
    if ($notify === 'randchoicesaved') {
        echo $OUTPUT->notification(get_string('randchoicesaved', 'randchoice'), 'notifysuccess');
    } else {
        if ($notify === 'mustchooseone') {
            echo $OUTPUT->notification(get_string('mustchooseone', 'randchoice'), 'notifyproblem');
        }
    }
}
/// Display the randchoice and possibly results
$eventdata = array();
$eventdata['objectid'] = $randchoice->id;
$eventdata['context'] = $context;
$event = \mod_randchoice\event\course_module_viewed::create($eventdata);
$event->add_record_snapshot('course_modules', $cm);
$event->add_record_snapshot('course', $course);
$event->trigger();
/// Check to see if groups are being used in this randchoice
$groupmode = groups_get_activity_groupmode($cm);
if ($groupmode) {
    groups_get_activity_group($cm, true);
    groups_print_activity_menu($cm, $CFG->wwwroot . '/mod/randchoice/view.php?id=' . $id);
}
// Check if we want to include responses from inactive users.
$onlyactive = $randchoice->includeinactive ? false : true;
$allresponses = randchoice_get_response_data($randchoice, $cm, $groupmode, $onlyactive);
// Big function, approx 6 SQL calls per user.
if (has_capability('mod/randchoice:readresponses', $context)) {
    randchoice_show_reportlink($allresponses, $cm);