mirror of
https://github.com/moodle/moodle.git
synced 2025-03-14 12:40:01 +01:00
MDL-45896 navigation: Created a user context header.
Part of MDL-45774
This commit is contained in:
parent
50e0d9ff5c
commit
261bdb24d9
@ -3075,6 +3075,85 @@ class tabobject implements renderable {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Renderable for the main page header.
|
||||
*
|
||||
* @package core
|
||||
* @category output
|
||||
* @since 2.9
|
||||
* @copyright 2015 Adrian Greeve <adrian@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class context_header implements renderable {
|
||||
|
||||
/**
|
||||
* @var stdClass $imagedata Image information to retrieve a picture for the header.
|
||||
*/
|
||||
public $imagedata;
|
||||
/**
|
||||
* @var array $additionalbuttons Additional buttons for the header e.g. Messaging button for the user header.
|
||||
* array elements - title => alternate text for the image, or if no image is available the button text.
|
||||
* url => Link for the button to head to. Should be a moodle_url.
|
||||
* image => location to the image, or name of the image in /pix/t/{image name}.
|
||||
* linkattributes => additional attributes for the <a href> element.
|
||||
* page => page object. Don't include if the image is an external image.
|
||||
*/
|
||||
public $additionalbuttons;
|
||||
/**
|
||||
* @var $subheading Secondary information to show with the header.
|
||||
*/
|
||||
public $subheading;
|
||||
|
||||
public $shownavbar;
|
||||
public $showbutton;
|
||||
|
||||
public $type = 'generic';
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param object $imagedata Information needed to include a picture in the header.
|
||||
* @param string $additionalbuttons Buttons for the header e.g. Messaging button for the user header.
|
||||
* @param string $subheading Secondary text for the header.
|
||||
* @param bool $shownavbar Switch for showing the navigation bar.
|
||||
* @param bool $showbutton Switch for showing the editing button for the page.
|
||||
*/
|
||||
public function __construct($imagedata = null, $additionalbuttons = null, $subheading = null, $shownavbar = true,
|
||||
$showbutton = true, $type = null) {
|
||||
// Check to see if the image id is for a user or something else (course, module);
|
||||
$this->imagedata = $imagedata;
|
||||
$this->additionalbuttons = $additionalbuttons;
|
||||
$this->subheading = $subheading;
|
||||
$this->shownavbar = $shownavbar;
|
||||
$this->showbutton = $showbutton;
|
||||
if (isset($this->additionalbuttons)) {
|
||||
$this->format_button_images();
|
||||
}
|
||||
if (!empty($type)) {
|
||||
$this->type = $type;
|
||||
}
|
||||
}
|
||||
|
||||
protected function format_button_images() {
|
||||
|
||||
foreach ($this->additionalbuttons as $buttontype => $button) {
|
||||
$page = $button['page'];
|
||||
if (!isset($button['image'])) {
|
||||
$this->additionalbuttons[$buttontype]['formattedimage'] = $button['title'];
|
||||
} else {
|
||||
// TODO Check to see if this is an external url or an internal image.
|
||||
$internalimage = $page->theme->resolve_image_location('t/' . $button['image'], 'moodle');
|
||||
if (!$internalimage) {
|
||||
$this->additionalbuttons[$buttontype]['formattedimage'] = $button['image'];
|
||||
} else {
|
||||
$this->additionalbuttons[$buttontype]['formattedimage'] = 't/' . $button['image'];
|
||||
}
|
||||
}
|
||||
$this->additionalbuttons[$buttontype]['linkattributes'] = array_merge($button['linkattributes'], array('class' => 'btn'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores tabs list
|
||||
*
|
||||
|
@ -3998,6 +3998,114 @@ EOD;
|
||||
$html .= html_writer::end_tag('div');
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the header bar.
|
||||
*
|
||||
* @since Moodle 2.9
|
||||
* @return string HTML for the header bar.
|
||||
*/
|
||||
public function context_header() {
|
||||
global $DB;
|
||||
$context = $this->page->context;
|
||||
$imagedata = null;
|
||||
$subheader = null;
|
||||
$userbuttons = null;
|
||||
$type = 'generic';
|
||||
if ($context->contextlevel == CONTEXT_USER) {
|
||||
$imagedata = $DB->get_record('user', array('id' => $context->instanceid));
|
||||
$subheader = $imagedata->city . ', ' . get_string($imagedata->country, 'countries');
|
||||
$userbuttons = array();
|
||||
$userbuttons['messages'] = array(
|
||||
'title' => get_string('message', 'message'),
|
||||
'url' => new moodle_url('/message/index.php', array('id' => $imagedata->id)),
|
||||
'image' => 'message',
|
||||
'linkattributes' => message_messenger_sendmessage_link_params($imagedata),
|
||||
'page' => $this->page
|
||||
);
|
||||
$type = 'user';
|
||||
}
|
||||
$contextheader = new context_header($imagedata, $userbuttons, $subheader, true, true, $type);
|
||||
return $this->render_context_header($contextheader);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the header bar.
|
||||
*
|
||||
* @param context_header $contextheader Header bar object.
|
||||
* @return string HTML for the header bar.
|
||||
*/
|
||||
protected function render_context_header(context_header $contextheader) {
|
||||
|
||||
// CSS classes.
|
||||
$classprefix = 'header-bar-';
|
||||
$classes = array('header-mc-heady-head');
|
||||
if ($contextheader->type !== 'generic') {
|
||||
$classes[] = $classprefix . $contextheader->type;
|
||||
}
|
||||
$classstr = implode(' ', $classes);
|
||||
|
||||
// All the html stuff goes here.
|
||||
|
||||
$html = html_writer::start_div($classstr);
|
||||
|
||||
// Image data.
|
||||
if (isset($contextheader->imagedata)) {
|
||||
$html .= html_writer::div($this->user_picture($contextheader->imagedata, array('size' => 100)), 'page-header-image');
|
||||
}
|
||||
|
||||
// Headings.
|
||||
$headings = $this->heading($this->page->heading, 1);
|
||||
if (isset($contextheader->subheading)) {
|
||||
$headings .= $contextheader->subheading;
|
||||
}
|
||||
$html .= html_writer::tag('div', $headings, array('class' => 'page-header-headings'));
|
||||
|
||||
// Buttons.
|
||||
if (isset($contextheader->additionalbuttons)) {
|
||||
|
||||
$buttons = array();
|
||||
|
||||
$html .= html_writer::start_div('btn-group header-button-group');
|
||||
|
||||
foreach ($contextheader->additionalbuttons as $key => $value) {
|
||||
if (!isset($value->page)) {
|
||||
$image = $this->pix_icon($value['formattedimage'], $value['title'], 'moodle', array(
|
||||
'class' => 'iconsmall',
|
||||
'role' => 'presentation'
|
||||
));
|
||||
$image .= html_writer::span($value['title'], 'header-button-title');
|
||||
} else {
|
||||
$image = html_writer::empty_tag('img', array(
|
||||
'src' => $value['formattedimage'],
|
||||
'role' => 'presentation'
|
||||
));
|
||||
}
|
||||
$html .= html_writer::link($value['url'], html_writer::tag('span', $image), $value['linkattributes']);
|
||||
}
|
||||
$html .= html_writer::end_div();
|
||||
|
||||
}
|
||||
|
||||
$html .= html_writer::tag('div', $this->course_header(), array('class' => 'course-header'));
|
||||
$html .= html_writer::end_div();
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
public function full_header() {
|
||||
return $this->render_full_header();
|
||||
}
|
||||
|
||||
protected function render_full_header() {
|
||||
$html = html_writer::start_tag('header', array('id' => 'page-header', 'class' => 'clearfix'));
|
||||
$html .= $this->context_header();
|
||||
$html .= html_writer::tag('nav', $this->navbar(), array('class' => 'breadcrumb-nav'));
|
||||
$html .= html_writer::div($this->page_heading_button(), 'breadcrumb-button');
|
||||
$html .= html_writer::end_tag('header');
|
||||
return $html;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -67,18 +67,7 @@ echo $OUTPUT->doctype() ?>
|
||||
</header>
|
||||
|
||||
<div id="page" class="container-fluid">
|
||||
|
||||
<header id="page-header" class="clearfix">
|
||||
<div id="page-navbar" class="clearfix">
|
||||
<nav class="breadcrumb-nav"><?php echo $OUTPUT->navbar(); ?></nav>
|
||||
<div class="breadcrumb-button"><?php echo $OUTPUT->page_heading_button(); ?></div>
|
||||
</div>
|
||||
<?php echo $OUTPUT->page_heading(); ?>
|
||||
<div id="course-header">
|
||||
<?php echo $OUTPUT->course_header(); ?>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<?php echo $OUTPUT->full_header(); ?>
|
||||
<div id="page-content" class="row-fluid">
|
||||
<section id="region-main" class="<?php echo $regionmain; ?>">
|
||||
<?php
|
||||
|
@ -72,17 +72,7 @@ echo $OUTPUT->doctype() ?>
|
||||
</header>
|
||||
|
||||
<div id="page" class="container-fluid">
|
||||
|
||||
<header id="page-header" class="clearfix">
|
||||
<div id="page-navbar" class="clearfix">
|
||||
<nav class="breadcrumb-nav"><?php echo $OUTPUT->navbar(); ?></nav>
|
||||
<div class="breadcrumb-button"><?php echo $OUTPUT->page_heading_button(); ?></div>
|
||||
</div>
|
||||
<?php echo $OUTPUT->page_heading(); ?>
|
||||
<div id="course-header">
|
||||
<?php echo $OUTPUT->course_header(); ?>
|
||||
</div>
|
||||
</header>
|
||||
<?php echo $OUTPUT->full_header(); ?>
|
||||
|
||||
<div id="page-content" class="row-fluid">
|
||||
<div id="region-main-box" class="<?php echo $regionmainbox; ?>">
|
||||
|
@ -2089,6 +2089,40 @@ img#persona_signin {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
/** Header-bar styles **/
|
||||
.header-mc-heady-head {
|
||||
// We need to be explicit about the height of the header.
|
||||
@pageHeaderHeight: 140px;
|
||||
// margin: 0;
|
||||
// Change height of the user header to allow for an image.
|
||||
&.header-bar-user {
|
||||
// Set up for vertical alignment.
|
||||
height: @pageHeaderHeight;
|
||||
// line-height: @pageHeaderHeight;
|
||||
}
|
||||
}
|
||||
|
||||
.page-header-headings {
|
||||
position: relative;
|
||||
top: -90px;
|
||||
left: 110px;
|
||||
}
|
||||
|
||||
.dir-rtl .page-header-headings {
|
||||
position: relative;
|
||||
top: -90px;
|
||||
right: 110px;
|
||||
}
|
||||
|
||||
.btn-group {
|
||||
&.header-button-group{
|
||||
position: relative;
|
||||
top: -121px;
|
||||
right: 105px;
|
||||
float: right;
|
||||
}
|
||||
}
|
||||
|
||||
/** Action menu component styles **/
|
||||
.moodle-actionmenu,
|
||||
.moodle-actionmenu > ul,
|
||||
|
File diff suppressed because one or more lines are too long
@ -70,18 +70,7 @@ echo $OUTPUT->doctype() ?>
|
||||
</header>
|
||||
|
||||
<div id="page" class="container-fluid">
|
||||
|
||||
<header id="page-header" class="clearfix">
|
||||
<?php echo $html->heading; ?>
|
||||
<div id="page-navbar" class="clearfix">
|
||||
<nav class="breadcrumb-nav"><?php echo $OUTPUT->navbar(); ?></nav>
|
||||
<div class="breadcrumb-button"><?php echo $OUTPUT->page_heading_button(); ?></div>
|
||||
</div>
|
||||
<div id="course-header">
|
||||
<?php echo $OUTPUT->course_header(); ?>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<?php echo $OUTPUT->full_header(); ?>
|
||||
<div id="page-content" class="row-fluid">
|
||||
<section id="region-main" class="<?php echo $regionmain; ?>">
|
||||
<?php
|
||||
|
@ -80,17 +80,7 @@ echo $OUTPUT->doctype() ?>
|
||||
</header>
|
||||
|
||||
<div id="page" class="container-fluid">
|
||||
|
||||
<header id="page-header" class="clearfix">
|
||||
<?php echo $html->heading; ?>
|
||||
<div id="page-navbar" class="clearfix">
|
||||
<nav class="breadcrumb-nav"><?php echo $OUTPUT->navbar(); ?></nav>
|
||||
<div class="breadcrumb-button"><?php echo $OUTPUT->page_heading_button(); ?></div>
|
||||
</div>
|
||||
<div id="course-header">
|
||||
<?php echo $OUTPUT->course_header(); ?>
|
||||
</div>
|
||||
</header>
|
||||
<?php echo $OUTPUT->full_header(); ?>
|
||||
|
||||
<div id="page-content" class="row-fluid">
|
||||
<div id="region-main-box" class="<?php echo $regionmainbox; ?>">
|
||||
|
Loading…
x
Reference in New Issue
Block a user