示例#1
0
文件: lib.php 项目: janeklb/moodle
/**
 * Trigger a user profile viewed event.
 *
 * @param stdClass  $user user  object
 * @param stdClass  $context  context object (course or user)
 * @param stdClass  $course course  object
 * @since Moodle 2.9
 */
function profile_view($user, $context, $course = null)
{
    $eventdata = array('objectid' => $user->id, 'relateduserid' => $user->id, 'context' => $context);
    if (!empty($course)) {
        $eventdata['courseid'] = $course->id;
        $eventdata['other'] = array('courseid' => $course->id, 'courseshortname' => $course->shortname, 'coursefullname' => $course->fullname);
    }
    $event = \core\event\user_profile_viewed::create($eventdata);
    $event->add_record_snapshot('user', $user);
    $event->trigger();
}
示例#2
0
            $editstring = get_string('updatemymoodleoff');
            $resetbutton = $OUTPUT->single_button($reseturl, $resetstring);
        }
    }
    $url = new moodle_url("{$CFG->wwwroot}/user/profile.php", $params);
    $button = $OUTPUT->single_button($url, $editstring);
    $PAGE->set_button($resetbutton . $button);
} else {
    $USER->editing = $edit = 0;
}
// HACK WARNING!  This loads up all this page's blocks in the system context.
if ($currentpage->userid == 0) {
    $CFG->blockmanagerclass = 'my_syspage_block_manager';
}
// Trigger a user profile viewed event.
$event = \core\event\user_profile_viewed::create(array('objectid' => $user->id, 'relateduserid' => $user->id, 'context' => $usercontext));
$event->add_record_snapshot('user', $user);
$event->trigger();
// TODO WORK OUT WHERE THE NAV BAR IS!
echo $OUTPUT->header();
echo '<div class="userprofile">';
// Print the standard content of this page, the basic profile info.
echo $OUTPUT->heading(fullname($user));
if (is_mnet_remote_user($user)) {
    $sql = "SELECT h.id, h.name, h.wwwroot,\n                   a.name as application, a.display_name\n              FROM {mnet_host} h, {mnet_application} a\n             WHERE h.id = ? AND h.applicationid = a.id";
    $remotehost = $DB->get_record_sql($sql, array($user->mnethostid));
    $a = new stdclass();
    $a->remotetype = $remotehost->display_name;
    $a->remotename = $remotehost->name;
    $a->remoteurl = $remotehost->wwwroot;
    echo $OUTPUT->box(get_string('remoteuserinfo', 'mnet', $a), 'remoteuserinfo');
示例#3
0
if ($node = $PAGE->settingsnav->get('courseadmin')) {
    $node->forceopen = false;
}
echo $OUTPUT->header();
echo '<div class="userprofile">';
echo $OUTPUT->heading(fullname($user) . ' (' . format_string($course->shortname, true, array('context' => $coursecontext)) . ')');
if ($user->deleted) {
    echo $OUTPUT->heading(get_string('userdeleted'));
    if (!has_capability('moodle/user:update', $coursecontext)) {
        echo $OUTPUT->footer();
        die;
    }
}
// OK, security out the way, now we are showing the user.
// Trigger a user profile viewed event.
$event = \core\event\user_profile_viewed::create(array('objectid' => $user->id, 'relateduserid' => $user->id, 'courseid' => $course->id, 'context' => $coursecontext, 'other' => array('courseid' => $course->id, 'courseshortname' => $course->shortname, 'coursefullname' => $course->fullname)));
$event->add_record_snapshot('user', $user);
$event->trigger();
// Get the hidden field list.
if (has_capability('moodle/user:viewhiddendetails', $coursecontext)) {
    $hiddenfields = array();
} else {
    $hiddenfields = array_flip(explode(',', $CFG->hiddenuserfields));
}
if (is_mnet_remote_user($user)) {
    $sql = "SELECT h.id, h.name, h.wwwroot,\n                   a.name as application, a.display_name\n              FROM {mnet_host} h, {mnet_application} a\n             WHERE h.id = ? AND h.applicationid = a.id";
    $remotehost = $DB->get_record_sql($sql, array($user->mnethostid));
    $a = new stdclass();
    $a->remotetype = $remotehost->display_name;
    $a->remotename = $remotehost->name;
    $a->remoteurl = $remotehost->wwwroot;
示例#4
0
 public function test_user_profile_viewed()
 {
     $this->resetAfterTest();
     $this->setAdminUser();
     $user = $this->getDataGenerator()->create_user();
     $course = $this->getDataGenerator()->create_course();
     $coursecontext = context_course::instance($course->id);
     // User profile viewed in course context.
     $eventparams = array('objectid' => $user->id, 'relateduserid' => $user->id, 'courseid' => $course->id, 'context' => $coursecontext, 'other' => array('courseid' => $course->id, 'courseshortname' => $course->shortname, 'coursefullname' => $course->fullname));
     $event = \core\event\user_profile_viewed::create($eventparams);
     // Trigger and capture the event.
     $sink = $this->redirectEvents();
     $event->trigger();
     $events = $sink->get_events();
     $event = reset($events);
     $this->assertInstanceOf('\\core\\event\\user_profile_viewed', $event);
     $log = array($course->id, 'user', 'view', 'view.php?id=' . $user->id . '&course=' . $course->id, $user->id);
     $this->assertEventLegacyLogData($log, $event);
     // User profile viewed in user context.
     $usercontext = context_user::instance($user->id);
     $eventparams['context'] = $usercontext;
     unset($eventparams['courseid'], $eventparams['other']);
     $event = \core\event\user_profile_viewed::create($eventparams);
     // Trigger and capture the event.
     $sink = $this->redirectEvents();
     $event->trigger();
     $events = $sink->get_events();
     $event = reset($events);
     $this->assertInstanceOf('\\core\\event\\user_profile_viewed', $event);
     $expected = null;
     $this->assertEventLegacyLogData($expected, $event);
 }