Ejemplo n.º 1
0
        // Enter the course we are searching
        require_login($course);
    }
    // Get the course ready for access checks
    $courses = array($courseid => $course);
} else {
    // We are going to search for all of the users posts in all courses!
    // a general require login here as we arn't actually within any course.
    require_login();
    $PAGE->set_context(context_user::instance($user->id));
    // Now we need to get all of the courses to search.
    // All courses where the user has posted within a twf will be returned.
    $courses = twf_get_courses_user_posted_in($user, $discussionsonly);
}
$params = array('context' => $PAGE->context, 'relateduserid' => $user->id, 'other' => array('reportmode' => $mode));
$event = \mod_twf\event\user_report_viewed::create($params);
$event->trigger();
// Get the posts by the requested user that the current user can access.
$result = twf_get_posts_by_user($user, $courses, $isspecificcourse, $discussionsonly, $page * $perpage, $perpage);
// Check whether there are not posts to display.
if (empty($result->posts)) {
    // Ok no posts to display means that either the user has not posted or there
    // are no posts made by the requested user that the current user is able to
    // see.
    // In either case we need to decide whether we can show personal information
    // about the requested user to the current user so we will execute some checks
    // First check the obvious, its the current user, a specific course has been
    // provided (require_login has been called), or they have a course contact role.
    // True to any of those and the current user can see the details of the
    // requested user.
    $canviewuser = $iscurrentuser || $isspecificcourse || empty($CFG->forceloginforprofiles) || has_coursecontact_role($userid);
Ejemplo n.º 2
0
 /**
  * Test the user_report_viewed event.
  */
 public function test_user_report_viewed()
 {
     // Setup test data.
     $user = $this->getDataGenerator()->create_user();
     $course = $this->getDataGenerator()->create_course();
     $context = context_course::instance($course->id);
     $params = array('context' => $context, 'relateduserid' => $user->id, 'other' => array('reportmode' => 'discussions'));
     $event = \mod_twf\event\user_report_viewed::create($params);
     // Trigger and capture the event.
     $sink = $this->redirectEvents();
     $event->trigger();
     $events = $sink->get_events();
     $this->assertCount(1, $events);
     $event = reset($events);
     // Checking that the event contains the expected values.
     $this->assertInstanceOf('\\mod_twf\\event\\user_report_viewed', $event);
     $this->assertEquals($context, $event->get_context());
     $expected = array($course->id, 'twf', 'user report', "user.php?id={$user->id}&mode=discussions&course={$course->id}", $user->id);
     $this->assertEventLegacyLogData($expected, $event);
     $this->assertEventContextNotUsed($event);
     $this->assertNotEmpty($event->get_name());
 }