Exemplo n.º 1
0
 /**
  * Test the user report viewed event.
  *
  * It's not possible to use the moodle API to simulate the viewing of user log report, so here we
  * simply create the event and trigger it.
  */
 public function test_user_report_viewed()
 {
     $user = $this->getDataGenerator()->create_user();
     $course = $this->getDataGenerator()->create_course();
     $context = context_course::instance($course->id);
     // Trigger event for user report viewed.
     $event = \report_log\event\user_report_viewed::create(array('context' => $context, 'relateduserid' => $user->id, 'other' => array('mode' => 'today')));
     // Trigger and capture the event.
     $sink = $this->redirectEvents();
     $event->trigger();
     $events = $sink->get_events();
     $event = reset($events);
     $this->assertInstanceOf('\\report_log\\event\\user_report_viewed', $event);
     $this->assertEquals($context, $event->get_context());
     $url = 'report/log/user.php?id=' . $user->id . '&course=' . $course->id . '&mode=today';
     $expected = array($course->id, "course", "report log", $url, $course->id);
     $this->assertEventLegacyLogData($expected, $event);
     $this->assertEventContextNotUsed($event);
     $url = new moodle_url('/report/log/user.php', array('course' => $course->id, 'id' => $user->id, 'mode' => 'today'));
     $this->assertEquals($url, $event->get_url());
 }
Exemplo n.º 2
0
$PAGE->set_title("{$course->shortname}: {$stractivityreport}");
// Create the appropriate breadcrumb.
$navigationnode = array('url' => new moodle_url('/report/log/user.php', array('id' => $user->id, 'course' => $course->id, 'mode' => $mode)));
if ($mode === 'today') {
    $navigationnode['name'] = get_string('todaylogs');
} else {
    $navigationnode['name'] = get_string('alllogs');
}
$PAGE->add_report_nodes($user->id, $navigationnode);
if ($courseid == SITEID) {
    $PAGE->set_heading(fullname($user));
} else {
    $PAGE->set_heading($course->fullname);
}
// Trigger a user logs viewed event.
$event = \report_log\event\user_report_viewed::create(array('context' => $coursecontext, 'relateduserid' => $userid, 'other' => array('mode' => $mode)));
$event->trigger();
echo $OUTPUT->header();
if ($courseid != SITEID) {
    $userheading = array('user' => $user, 'usercontext' => $personalcontext);
    echo $OUTPUT->context_header($userheading, 2);
}
// Time to filter records from.
if ($mode === 'today') {
    $timefrom = usergetmidnight(time());
} else {
    $timefrom = 0;
}
$output = $PAGE->get_renderer('report_log');
$reportlog = new report_log_renderable($logreader, $course, $user->id, 0, '', -1, -1, false, false, true, false, $PAGE->url, $timefrom, '', $page, $perpage, 'timecreated DESC');
// Setup table if log reader is enabled.