$resetbutton = $OUTPUT->single_button($reseturl, $resetstring); } else { $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; } // Trigger a user profile viewed event. profile_view($user, $usercontext); // TODO WORK OUT WHERE THE NAV BAR IS! echo $OUTPUT->header(); echo '<div class="userprofile">'; if ($user->description && !isset($hiddenfields['description'])) { echo '<div class="description">'; if (!empty($CFG->profilesforenrolledusersonly) && !$currentuser && !$DB->record_exists('role_assignments', array('userid' => $user->id))) { echo get_string('profilenotshown', 'moodle'); } else { $user->description = file_rewrite_pluginfile_urls($user->description, 'pluginfile.php', $usercontext->id, 'user', 'profile', null); echo format_text($user->description, $user->descriptionformat); }
/** * Test profile_view function */ public function test_profile_view() { global $USER; $this->resetAfterTest(); // Course without sections. $course = $this->getDataGenerator()->create_course(); $context = context_course::instance($course->id); $user = $this->getDataGenerator()->create_user(); $usercontext = context_user::instance($user->id); $this->setUser($user); // Redirect events to the sink, so we can recover them later. $sink = $this->redirectEvents(); profile_view($user, $context, $course); $events = $sink->get_events(); $event = reset($events); // Check the event details are correct. $this->assertInstanceOf('\\core\\event\\user_profile_viewed', $event); $this->assertEquals($context, $event->get_context()); $this->assertEquals($user->id, $event->relateduserid); $this->assertEquals($course->id, $event->other['courseid']); $this->assertEquals($course->shortname, $event->other['courseshortname']); $this->assertEquals($course->fullname, $event->other['coursefullname']); profile_view($user, $usercontext); $events = $sink->get_events(); $event = array_pop($events); $sink->close(); $this->assertInstanceOf('\\core\\event\\user_profile_viewed', $event); $this->assertEquals($usercontext, $event->get_context()); $this->assertEquals($user->id, $event->relateduserid); }
$node->forceopen = false; } echo $OUTPUT->header(); echo '<div class="userprofile">'; $headerinfo = array('heading' => fullname($user), 'user' => $user, 'usercontext' => $usercontext); echo $OUTPUT->context_header($headerinfo, 2); 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. profile_view($user, $coursecontext, $course); if ($user->description && !isset($hiddenfields['description'])) { echo '<div class="description">'; if (!empty($CFG->profilesforenrolledusersonly) && !$DB->record_exists('role_assignments', array('userid' => $id))) { echo get_string('profilenotshown', 'moodle'); } else { if ($courseid == SITEID) { $user->description = file_rewrite_pluginfile_urls($user->description, 'pluginfile.php', $usercontext->id, 'user', 'profile', null); } else { // We have to make a little detour thought the course context to verify the access control for course profile. $user->description = file_rewrite_pluginfile_urls($user->description, 'pluginfile.php', $coursecontext->id, 'user', 'profile', $user->id); } $options = array('overflowdiv' => true); echo format_text($user->description, $user->descriptionformat, $options); } echo '</div>';
/** * Simulate the /user/index.php and /user/profile.php web interface page triggering events * * @param int $userid id of user * @param int $courseid id of course * @return array of warnings and status result * @since Moodle 2.9 * @throws moodle_exception */ public static function view_user_profile($userid, $courseid = 0) { global $CFG, $USER; require_once $CFG->dirroot . "/user/profile/lib.php"; $params = self::validate_parameters(self::view_user_profile_parameters(), array('userid' => $userid, 'courseid' => $courseid)); $warnings = array(); if (empty($params['userid'])) { $params['userid'] = $USER->id; } if (empty($params['courseid'])) { $params['courseid'] = SITEID; } $course = get_course($params['courseid']); $user = core_user::get_user($params['userid'], '*', MUST_EXIST); if ($user->deleted) { throw new moodle_exception('userdeleted'); } if (isguestuser($user)) { // Can not view profile of guest - thre is nothing to see there. throw new moodle_exception('invaliduserid'); } if ($course->id == SITEID) { $coursecontext = context_system::instance(); } else { $coursecontext = context_course::instance($course->id); } self::validate_context($coursecontext); $currentuser = $USER->id == $user->id; $usercontext = context_user::instance($user->id); if (!$currentuser and !has_capability('moodle/user:viewdetails', $coursecontext) and !has_capability('moodle/user:viewdetails', $usercontext)) { throw new moodle_exception('cannotviewprofile'); } // Case like user/profile.php. if ($course->id == SITEID) { profile_view($user, $usercontext); } else { // Case like user/view.php. if (!$currentuser and !can_access_course($course, $user, '', true)) { throw new moodle_exception('notenrolledprofile'); } profile_view($user, $coursecontext, $course); } $result = array(); $result['status'] = true; $result['warnings'] = $warnings; return $result; }