Commit d24b8e52 authored by Jetha Chan's avatar Jetha Chan
Browse files

MDL-45893 user_menu: revised based on action_menu

parent 272fec36
...@@ -1034,6 +1034,7 @@ $string['locktimeout'] = 'The operation timed out while waiting for a lock.'; ...@@ -1034,6 +1034,7 @@ $string['locktimeout'] = 'The operation timed out while waiting for a lock.';
$string['log_excel_date_format'] = 'yyyy mmmm d h:mm'; $string['log_excel_date_format'] = 'yyyy mmmm d h:mm';
$string['loggedinas'] = 'You are logged in as {$a}'; $string['loggedinas'] = 'You are logged in as {$a}';
$string['loggedinasguest'] = 'You are currently using guest access'; $string['loggedinasguest'] = 'You are currently using guest access';
$string['loggedinfrom'] = 'from {$a}';
$string['loggedinnot'] = 'You are not logged in.'; $string['loggedinnot'] = 'You are not logged in.';
$string['login'] = 'Log in'; $string['login'] = 'Log in';
$string['loginalready'] = 'You are already logged in'; $string['loginalready'] = 'You are already logged in';
...@@ -1548,6 +1549,7 @@ $string['rolemappings'] = 'Role mappings'; ...@@ -1548,6 +1549,7 @@ $string['rolemappings'] = 'Role mappings';
$string['rolerenaming'] = 'Role renaming'; $string['rolerenaming'] = 'Role renaming';
$string['rolerenaming_help'] = 'This setting allows the displayed names for roles used in the course to be changed. Only the displayed name is changed - role permissions are not affected. New role names will appear on the course participants page and elsewhere within the course. If the renamed role is one that the administrator has selected as a course manager role, then the new role name will also appear as part of the course listings.'; $string['rolerenaming_help'] = 'This setting allows the displayed names for roles used in the course to be changed. Only the displayed name is changed - role permissions are not affected. New role names will appear on the course participants page and elsewhere within the course. If the renamed role is one that the administrator has selected as a course manager role, then the new role name will also appear as part of the course listings.';
$string['roles'] = 'Roles'; $string['roles'] = 'Roles';
$string['roleviewas'] = 'You are viewing as a {$a}';
$string['rss'] = 'RSS'; $string['rss'] = 'RSS';
$string['rssarticles'] = 'Number of RSS recent articles'; $string['rssarticles'] = 'Number of RSS recent articles';
$string['rsserror'] = 'Error reading RSS data'; $string['rsserror'] = 'Error reading RSS data';
...@@ -1905,6 +1907,7 @@ $string['usernamenotfound'] = 'The username was not found in the database'; ...@@ -1905,6 +1907,7 @@ $string['usernamenotfound'] = 'The username was not found in the database';
$string['usernameoremail'] = 'Enter either username or email address'; $string['usernameoremail'] = 'Enter either username or email address';
$string['usernotconfirmed'] = 'Could not confirm {$a}'; $string['usernotconfirmed'] = 'Could not confirm {$a}';
$string['userpic'] = 'User picture'; $string['userpic'] = 'User picture';
$string['userrevert'] = 'Revert to your own account';
$string['users'] = 'Users'; $string['users'] = 'Users';
$string['userselectorautoselectunique'] = 'If only one user matches the search, select them automatically'; $string['userselectorautoselectunique'] = 'If only one user matches the search, select them automatically';
$string['userselectorpreserveselected'] = 'Keep selected users, even if they no longer match the search'; $string['userselectorpreserveselected'] = 'Keep selected users, even if they no longer match the search';
......
...@@ -2897,6 +2897,137 @@ EOD; ...@@ -2897,6 +2897,137 @@ EOD;
return html_writer::tag('ul', implode("\n", $lis), $attrs); return html_writer::tag('ul', implode("\n", $lis), $attrs);
} }
/**
* Construct a user menu, returning HTML that can be echoed out by a
* layout file.
*
* @param stdClass $user A user object, usually $USER.
* @param bool $withlinks true if a dropdown should be built.
* @return string HTML fragment.
*/
public function user_menu($user = null, $withlinks = null) {
global $USER, $CFG;
if (is_null($user)) {
$user = $USER;
}
// Note: this behaviour is intended to match that of core_renderer::login_info,
// but should not be considered to be good practice; layout options are
// intended to be theme-specific. Please don't copy this snippet anywhere else.
if (is_null($withlinks)) {
$withlinks = empty($this->page->layout_options['nologinlinks']);
}
$returnstr = "";
// If during initial install, return the empty return string.
if (during_initial_install()) {
return $returnstr;
}
// If not logged in, show the typical not-logged-in string.
if (!isloggedin()) {
$returnstr = get_string('loggedinnot', 'moodle');
$loginpage = ((string)$this->page->url === get_login_url());
if (!$loginpage) {
$loginurl = get_login_url();
$returnstr .= " (<a href=\"$loginurl\">" . get_string('login') . '</a>)';
}
return html_writer::tag(
'span',
$returnstr
);
}
// Get some navigation opts.
require_once($CFG->dirroot . '/user/lib.php');
$opts = user_get_user_navigation_info($user, $this->page, $this->page->course);
$avatarclasses = "avatars";
$avatarcontents = html_writer::span($opts->metadata['useravatar'], 'avatar current');
$usertextcontents = $opts->metadata['userfullname'];
// Other user.
if ($opts->metadata['asotheruser']) {
$avatarcontents .= html_writer::span(
$opts->metadata['realuseravatar'],
'avatar realuser'
);
$usertextcontents = $opts->metadata['realuserfullname'];
$usertextcontents .= html_writer::tag(
'span',
get_string(
'loggedinas',
'moodle',
html_writer::span(
$opts->metadata['userfullname'],
'value'
)
),
array('class' => 'meta viewingas')
);
}
// Role.
if ($opts->metadata['asotherrole']) {
$role = core_text::strtolower(preg_replace('#[ ]+#', '-', trim($opts->metadata['rolename'])));
$usertextcontents .= html_writer::span(
get_string(
'roleviewas',
'moodle',
html_writer::span(
$opts->metadata['rolename'],
'value'
)
),
'meta role role-' . $role
);
}
// MNet.
if ($opts->metadata['asmnetuser']) {
$mnet = strtolower(preg_replace('#[ ]+#', '-', trim($opts->metadata['mnetidprovidername'])));
$usertextcontents .= html_writer::span(
get_string(
'loggedinfrom',
'moodle',
html_writer::span(
$opts->metadata['mnetidprovidername'],
'value'
)
),
'meta mnet mnet-' . $mnet
);
}
$returnstr .= html_writer::span(
html_writer::span($avatarcontents, $avatarclasses) . html_writer::span($usertextcontents, 'usertext'),
'userbutton'
);
$am = new action_menu();
$am->initialise_js($this->page);
$am->set_menu_trigger($returnstr);
$am->set_alignment(action_menu::TR, action_menu::BR);
if ($withlinks) {
foreach ($opts->navitems as $key => $value) {
$al = new action_menu_link_secondary(
$value->url,
new pix_icon($value->pix, $value->title, null),
$value->title,
array('class' => 'icon')
);
$am->add($al);
}
}
return html_writer::div(
$this->render($am),
'usermenu'
);
}
/** /**
* Return the navbar content so that it can be echoed out by the layout * Return the navbar content so that it can be echoed out by the layout
* *
......
...@@ -66,7 +66,7 @@ echo $OUTPUT->doctype() ?> ...@@ -66,7 +66,7 @@ echo $OUTPUT->doctype() ?>
<div id="page-header" class="clearfix"> <div id="page-header" class="clearfix">
<h1 class="headermain"><?php echo $PAGE->heading ?></h1> <h1 class="headermain"><?php echo $PAGE->heading ?></h1>
<div class="headermenu"><?php <div class="headermenu"><?php
echo $OUTPUT->login_info(); echo $OUTPUT->user_menu();
echo $OUTPUT->lang_menu(); echo $OUTPUT->lang_menu();
echo $PAGE->headingmenu; echo $PAGE->headingmenu;
?></div> ?></div>
......
...@@ -80,9 +80,7 @@ echo $OUTPUT->doctype() ?> ...@@ -80,9 +80,7 @@ echo $OUTPUT->doctype() ?>
<?php if ($hasheading) { ?> <?php if ($hasheading) { ?>
<h1 class="headermain"><?php echo $PAGE->heading ?></h1> <h1 class="headermain"><?php echo $PAGE->heading ?></h1>
<div class="headermenu"><?php <div class="headermenu"><?php
if ($haslogininfo) { echo $OUTPUT->user_menu();
echo $OUTPUT->login_info();
}
if (!empty($PAGE->layout_options['langmenu'])) { if (!empty($PAGE->layout_options['langmenu'])) {
echo $OUTPUT->lang_menu(); echo $OUTPUT->lang_menu();
} }
......
...@@ -192,6 +192,94 @@ a.skip:active {position: static;display: block;} ...@@ -192,6 +192,94 @@ a.skip:active {position: static;display: block;}
.headermenu {float:right;margin:10px;font-size:0.8em;text-align:right;} .headermenu {float:right;margin:10px;font-size:0.8em;text-align:right;}
#course-header {clear:both;} #course-header {clear:both;}
/**
* User menu
*/
.usermenu {
border: 1px solid #333;
padding: 4px 6px;
margin: 0.5em 0em;
}
.usermenu .toggle-display {
outline: none;
}
.usermenu .userbutton {
background: #fff;
color: #000;
display: inline-block;
font-size: 15px;
}
.usermenu .userbutton > * {
display: inline-block;
vertical-align: middle;
}
.usermenu .userbutton .avatars {
display: inline-block;
vertical-align: middle;
}
.usermenu .userbutton .usertext {
display: inline-block;
text-align: left;
}
.usermenu .userbutton .usertext .meta{
display: block;
font-size: 12px;
}
.usermenu .userbutton .usertext .meta .value {
font-weight: bold;
}
.usermenu .moodle-actionmenu .toggle-display.textmenu .caret {
display: none;
}
.jsenabled .usermenu .moodle-actionmenu[data-enhanced] .toggle-display.textmenu {
margin-left: 0;
padding-left: 0;
}
.jsenabled.dir-rtl .usermenu .moodle-actionmenu[data-enhanced] .toggle-display.textmenu {
margin-right: 0;
margin-left: 4px;
}
.jsenabled .usermenu .moodle-actionmenu[data-enhanced] .toggle-display.textmenu .caret {
display: inline-block;
margin-top: 0;
vertical-align: middle;
}
.userloggedinas .usermenu .userbutton .avatars .avatar {
display: inline-block;
vertical-align:middle;
overflow: hidden;
}
.userloggedinas .usermenu .userbutton .avatars .avatar img {
width: inherit;
height: inherit;
}
.userloggedinas .usermenu .userbutton .avatars .avatar.current {
position: relative;
top: 4px;
left: 4px;
width: 20px;
height: 20px;
margin-top: 11px;
border: 1px solid #ddd;
border-radius: 10px;
box-shadow: -2px -2px 16px rgba(0,0,0,0.25);
}
.dir-ltr .usermenu .userbutton .avatars {
margin-right: 6px;
}
.dir-rtl .usermenu .userbutton {
margin-right: -4px;
}
.dir-rtl .usermenu .userbutton .avatars {
margin-left: 6px;
}
.dir-ltr.userloggedinas .usermenu .userbutton .avatars .avatar.current {
margin-right: -34px;
}
.dir-rtl.userloggedinas .usermenu .userbutton .avatars .avatar.current {
margin-left: -22px;
}
/** /**
* Navbar * Navbar
*/ */
......
...@@ -50,7 +50,7 @@ echo $OUTPUT->doctype() ?> ...@@ -50,7 +50,7 @@ echo $OUTPUT->doctype() ?>
<?php echo $OUTPUT->custom_menu(); ?> <?php echo $OUTPUT->custom_menu(); ?>
<ul class="nav pull-right"> <ul class="nav pull-right">
<li><?php echo $OUTPUT->page_heading_menu(); ?></li> <li><?php echo $OUTPUT->page_heading_menu(); ?></li>
<li class="navbar-text"><?php echo $OUTPUT->login_info() ?></li> <li class="navbar-text"><?php echo $OUTPUT->user_menu() ?></li>
</ul> </ul>
</div> </div>
</div> </div>
......
...@@ -51,7 +51,7 @@ echo $OUTPUT->doctype() ?> ...@@ -51,7 +51,7 @@ echo $OUTPUT->doctype() ?>
<?php echo $OUTPUT->custom_menu(); ?> <?php echo $OUTPUT->custom_menu(); ?>
<ul class="nav pull-right"> <ul class="nav pull-right">
<li><?php echo $OUTPUT->page_heading_menu(); ?></li> <li><?php echo $OUTPUT->page_heading_menu(); ?></li>
<li class="navbar-text"><?php echo $OUTPUT->login_info() ?></li> <li class="navbar-text"><?php echo $OUTPUT->user_menu() ?></li>
</ul> </ul>
</div> </div>
</div> </div>
......
...@@ -56,7 +56,7 @@ echo $OUTPUT->doctype() ?> ...@@ -56,7 +56,7 @@ echo $OUTPUT->doctype() ?>
<?php echo $OUTPUT->custom_menu(); ?> <?php echo $OUTPUT->custom_menu(); ?>
<ul class="nav pull-right"> <ul class="nav pull-right">
<li><?php echo $OUTPUT->page_heading_menu(); ?></li> <li><?php echo $OUTPUT->page_heading_menu(); ?></li>
<li class="navbar-text"><?php echo $OUTPUT->login_info() ?></li> <li class="navbar-text"><?php echo $OUTPUT->user_menu(); ?></li>
</ul> </ul>
</div> </div>
</div> </div>
......
...@@ -60,7 +60,7 @@ echo $OUTPUT->doctype() ?> ...@@ -60,7 +60,7 @@ echo $OUTPUT->doctype() ?>
<?php echo $OUTPUT->custom_menu(); ?> <?php echo $OUTPUT->custom_menu(); ?>
<ul class="nav pull-right"> <ul class="nav pull-right">
<li><?php echo $OUTPUT->page_heading_menu(); ?></li> <li><?php echo $OUTPUT->page_heading_menu(); ?></li>
<li class="navbar-text"><?php echo $OUTPUT->login_info() ?></li> <li class="navbar-text"><?php echo $OUTPUT->user_menu(); ?></li>
</ul> </ul>
</div> </div>
</div> </div>
...@@ -75,6 +75,7 @@ echo $OUTPUT->doctype() ?> ...@@ -75,6 +75,7 @@ echo $OUTPUT->doctype() ?>
<div class="breadcrumb-button"><?php echo $OUTPUT->page_heading_button(); ?></div> <div class="breadcrumb-button"><?php echo $OUTPUT->page_heading_button(); ?></div>
</div> </div>
<?php echo $OUTPUT->page_heading(); ?> <?php echo $OUTPUT->page_heading(); ?>
<?php echo $OUTPUT->user_menu(); ?>
<div id="course-header"> <div id="course-header">
<?php echo $OUTPUT->course_header(); ?> <?php echo $OUTPUT->course_header(); ?>
</div> </div>
......
...@@ -344,3 +344,101 @@ div#dock { ...@@ -344,3 +344,101 @@ div#dock {
border-right: 0px none; border-right: 0px none;
} }
} }
// Usermenu
.usermenu {
> .moodle-actionmenu > .menubar {
display: block;
margin: 2px 0px;
li {
display: block;
}
}
.toggle-display {
color: #777;
outline: none;
}
.userbutton {
.avatars{
display: inline-block;
height: 35px;
vertical-align: middle;
margin-right: 6px;
}
.usertext {
display: inline-block;
vertical-align: middle;
line-height: 1em;
.meta {
display: block;
font-size: 12px;
.value {
font-weight: bold;
}
}
}
}
.moodle-actionmenu[data-enhanced].show .menu a {
white-space: nowrap;
}
}
.userloggedinas .usermenu .userbutton .avatars {
.avatar {
&.current {
position: relative;
top: 4px;
left: 4px;
width: 20px;
height: 20px;
margin-top: 11px;
border: 1px solid #fff;
border-radius: 50%;
box-shadow: -2px -2px 16px rgba(0,0,0,0.25);
}
img {
width: inherit;
height: inherit;
}
display: inline-block;
overflow: hidden;
}
}
.jsenabled .usermenu .moodle-actionmenu[data-enhanced] .toggle-display.textmenu .caret {
margin-top: 0;
vertical-align: middle;
}
.dir-ltr {
.usermenu {
.userbutton {
margin-right: 4px;
.avatars{
margin-right: 6px;
}
}
}
&.userloggedinas .usermenu .userbutton .avatars {
.avatar {
&.current {
margin-right: -34px;
}
}
}
}
.dir-rtl {
.usermenu {
.userbutton {
margin-left: 4px;
.avatars{
margin-left: 6px;
}
}
}
&.userloggedinas .usermenu .userbutton .avatars {
.avatar {
&.current {
margin-left: -22px;
}
}
}
}
\ No newline at end of file
...@@ -440,6 +440,18 @@ ...@@ -440,6 +440,18 @@
} }
.nav-collapse.active { .nav-collapse.active {
height: auto; height: auto;
.usermenu .moodle-actionmenu[data-enhanced] {
.toggle-display {
display: none;
}
.menu {
display: block;
li {
margin: 0 0.5em;
}
}
}
} }
.path-mod-data .box > table > tbody > tr > td { .path-mod-data .box > table > tbody > tr > td {
display: block; display: block;
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -53,7 +53,7 @@ echo $OUTPUT->doctype() ?> ...@@ -53,7 +53,7 @@ echo $OUTPUT->doctype() ?>
<?php echo $OUTPUT->custom_menu(); ?> <?php echo $OUTPUT->custom_menu(); ?>
<ul class="nav pull-right"> <ul class="nav pull-right">
<li><?php echo $OUTPUT->page_heading_menu(); ?></li> <li><?php echo $OUTPUT->page_heading_menu(); ?></li>
<li class="navbar-text"><?php echo $OUTPUT->login_info() ?></li> <li class="navbar-text"><?php echo $OUTPUT->user_menu() ?></li>
</ul> </ul>
</div> </div>
</div> </div>
......
...@@ -54,7 +54,7 @@ echo $OUTPUT->doctype() ?> ...@@ -54,7 +54,7 @@ echo $OUTPUT->doctype() ?>
<?php echo $OUTPUT->custom_menu(); ?> <?php echo $OUTPUT->custom_menu(); ?>
<ul class="nav pull-right"> <ul class="nav pull-right">
<li><?php echo $OUTPUT->page_heading_menu(); ?></li> <li><?php echo $OUTPUT->page_heading_menu(); ?></li>
<li class="navbar-text"><?php echo $OUTPUT->login_info() ?></li> <li class="navbar-text"><?php echo $OUTPUT->user_menu() ?></li>
</ul> </ul>
</div> </div>
</div> </div>
......
...@@ -65,7 +65,7 @@ echo $OUTPUT->doctype() ?> ...@@ -65,7 +65,7 @@ echo $OUTPUT->doctype() ?>
<?php echo $OUTPUT->custom_menu(); ?> <?php echo $OUTPUT->custom_menu(); ?>
<ul class="nav pull-right"> <ul class="nav pull-right">
<li><?php echo $OUTPUT->page_heading_menu(); ?></li> <li><?php echo $OUTPUT->page_heading_menu(); ?></li>
<li class="navbar-text"><?php echo $OUTPUT->login_info() ?></li> <li class="navbar-text"><?php echo $OUTPUT->user_menu() ?></li>
</ul> </ul>
</div> </div>
</div> </div>
......
...@@ -614,3 +614,167 @@ function user_count_login_failures($user, $reset = true) { ...@@ -614,3 +614,167 @@ function user_count_login_failures($user, $reset = true) {
return $count; return $count;
} }
/**
* Get a list of essential user navigation items.
*
* @param stdclass $user user object.
* @param moodle_page $page page object.
* @return stdClass $returnobj navigation information object, where:
*
* $returnobj->navitems array array of links where each link is a
* stdClass with fields url, title, and
* pix
* $returnobj->metadata array array of useful user metadata to be
* used when constructing navigation;
* fields include:
*
* ROLE FIELDS
* asotherrole bool whether viewing as another role
* rolename string name of the role
*
* USER FIELDS
* These fields are for the currently-logged in user, or for
* the user that the real user is currently logged in as.
*
* userid int the id of the user in question
* userfullname string the user's full name
* userprofileurl moodle_url the url of the user's profile
* useravatar string a HTML fragment - the rendered
* user_picture for this user
*
* "REAL USER" FIELDS
* These fields are for when asotheruser is true, and
* correspond to the underlying "real user".
*
* asotheruser bool whether viewing as another user
* realuserid int the id of the user in question
* realuserfullname string the user's full name
* realuserprofileurl moodle_url the url of the user's profile
* realuseravatar string a HTML fragment - the rendered
* user_picture for this user
*
* MNET PROVIDER FIELDS
* asmnetuser bool whether viewing as a user from an
* MNet provider
* mnetidprovidername string name of the MNet provider
* mnetidproviderwwwroot string URL of the MNet provider
*/
function user_get_user_navigation_info($user, $page) {
global $OUTPUT, $DB;