navigation MDL-22723 Fixed issue when loading 2+ users not including the current user

This commit is contained in:
Sam Hemelryk 2010-06-10 07:29:02 +00:00
parent 25aad2c4bc
commit 5d07e95756
3 changed files with 26 additions and 5 deletions

View File

@ -1636,7 +1636,15 @@ class global_navigation extends navigation_node {
*/
public function extend_for_user($user) {
$this->extendforuser[] = $user;
$this->page->settingsnav->extend_for_user($user->id);
}
/**
* Returns all of the users the navigation is being extended for
*
* @return array
*/
public function get_extending_users() {
return $this->extendforuser;
}
/**
* Adds the given course to the navigation structure.
@ -2942,7 +2950,9 @@ class settings_navigation extends navigation_node {
return false;
}
if (count($this->userstoextendfor) > 0) {
$navusers = $this->page->navigation->get_extending_users();
if (count($this->userstoextendfor) > 0 || count($navusers) > 0) {
$usernode = null;
foreach ($this->userstoextendfor as $userid) {
$node = $this->generate_user_settings($courseid, $userid, 'userviewingsettings');
@ -2950,6 +2960,12 @@ class settings_navigation extends navigation_node {
$usernode = $node;
}
}
foreach ($navusers as $user) {
$node = $this->generate_user_settings($courseid, $user->id, 'userviewingsettings');
if (is_null($usernode)) {
$usernode = $node;
}
}
$this->generate_user_settings($courseid, $USER->id);
} else {
$usernode = $this->generate_user_settings($courseid, $USER->id);
@ -3030,8 +3046,13 @@ class settings_navigation extends navigation_node {
$fullname = fullname($user, has_capability('moodle/site:viewfullnames', $this->page->context));
$key = $gstitle;
if ($gstitle != 'usercurrentsettings') {
$key .= $userid;
}
// Add a user setting branch
$usersetting = $this->add(get_string($gstitle, 'moodle', $fullname), null, self::TYPE_CONTAINER, null, $gstitle);
$usersetting = $this->add(get_string($gstitle, 'moodle', $fullname), null, self::TYPE_CONTAINER, null, $key);
$usersetting->id = 'usersettings';
// Check if the user has been deleted

View File

@ -110,7 +110,7 @@ $PAGE->set_heading("$SITE->shortname: $strpublicprofile");
if (!$currentuser) {
$PAGE->navigation->extend_for_user($user);
if ($node = $PAGE->settingsnav->get('userviewingsettings')) {
if ($node = $PAGE->settingsnav->get('userviewingsettings'.$user->id)) {
$node->forceopen = true;
}
} else if ($node = $PAGE->settingsnav->get('usercurrentsettings', navigation_node::TYPE_CONTAINER)) {

View File

@ -151,7 +151,7 @@ if ($currentuser) {
if (!$currentuser) {
$PAGE->navigation->extend_for_user($user);
if ($node = $PAGE->settingsnav->get('userviewingsettings')) {
if ($node = $PAGE->settingsnav->get('userviewingsettings'.$user->id)) {
$node->forceopen = true;
}
} else if ($node = $PAGE->settingsnav->get('usercurrentsettings', navigation_node::TYPE_CONTAINER)) {