Skip to content

Commit

Permalink
MDL-45896 navigation: CSS and renderer improvements.
Browse files Browse the repository at this point in the history
Part of MDL-45774.
  • Loading branch information
abgreeve committed Apr 10, 2015
1 parent ccb76d4 commit 3b927d3
Show file tree
Hide file tree
Showing 9 changed files with 123 additions and 135 deletions.
55 changes: 28 additions & 27 deletions lib/outputcomponents.php
Original file line number Diff line number Diff line change
Expand Up @@ -3087,7 +3087,15 @@ protected function set_level($level) {
class context_header implements renderable {

/**
* @var stdClass $imagedata Image information to retrieve a picture for the header.
* @var string $heading Main heading.
*/
public $heading;
/**
* @var int $headinglevel Main heading 'h' tag level.
*/
public $headinglevel;
/**
* @var string $imagedata HTML for the Image for the header.
*/
public $imagedata;
/**
Expand All @@ -3099,57 +3107,50 @@ class context_header implements renderable {
* 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 string $heading Main heading data.
* @param int $headinglevel Main heading 'h' tag level.
* @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);
public function __construct($heading = null, $headinglevel = 1, $imagedata = null, $additionalbuttons = null) {

$this->heading = $heading;
$this->headinglevel = $headinglevel;
$this->imagedata = $imagedata;
$this->additionalbuttons = $additionalbuttons;
$this->subheading = $subheading;
$this->shownavbar = $shownavbar;
$this->showbutton = $showbutton;
// If we have buttons then format them.
if (isset($this->additionalbuttons)) {
$this->format_button_images();
}
if (!empty($type)) {
$this->type = $type;
}
}

/**
* Adds an array element for a formatted image.
*/
protected function format_button_images() {

foreach ($this->additionalbuttons as $buttontype => $button) {
$page = $button['page'];
// If no image is provided then just use the title.
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.
// Check to see if this is an internal Moodle icon.
$internalimage = $page->theme->resolve_image_location('t/' . $button['image'], 'moodle');
if (!$internalimage) {
$this->additionalbuttons[$buttontype]['formattedimage'] = $button['image'];
} else {
if ($internalimage) {
$this->additionalbuttons[$buttontype]['formattedimage'] = 't/' . $button['image'];
} else {
// Treat as an external image.
$this->additionalbuttons[$buttontype]['formattedimage'] = $button['image'];
}
}
$this->additionalbuttons[$buttontype]['linkattributes'] = array_merge($button['linkattributes'], array('class' => 'btn'));
// Add the bootstrap 'btn' class for formatting.
$this->additionalbuttons[$buttontype]['linkattributes'] = array_merge($button['linkattributes'],
array('class' => 'btn'));
}
}
}
Expand Down
128 changes: 76 additions & 52 deletions lib/outputrenderers.php
Original file line number Diff line number Diff line change
Expand Up @@ -4003,31 +4003,61 @@ public function render_preferences_group(preferences_group $renderable) {
* Returns the header bar.
*
* @since Moodle 2.9
* @param array $headerinfo An array of header information, dependant on what type of header is being displayed. The following
* array example is user specific.
* heading => Override the page heading.
* user => User object.
* usercontext => user context.
* @param int $headinglevel What level the 'h' tag will be.
* @return string HTML for the header bar.
*/
public function context_header() {
global $DB;
public function context_header($headerinfo = null, $headinglevel = 1) {
global $DB, $USER;
$context = $this->page->context;
// Make sure to use the heading if it has been set.
if (isset($headerinfo['heading'])) {
$heading = $headerinfo['heading'];
} else {
$heading = null;
}
$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);
// The user context currently has images and buttons. Other contexts may follow.
if (isset($headerinfo['user']) || $context->contextlevel == CONTEXT_USER) {
if (isset($headerinfo['user'])) {
$user = $headerinfo['user'];
} else {
// Look up the user information if it is not supplied.
$user = $DB->get_record('user', array('id' => $context->instanceid));
}
// If the user context is set, then use that for capability checks.
if (isset($headerinfo['usercontext'])) {
$context = $headerinfo['usercontext'];
}
// Use the user's full name if the heading isn't set.
if (!isset($heading)) {
$heading = fullname($user);
}

$imagedata = $this->user_picture($user, array('size' => 100));
// Check to see if we should be displaying a message button.
if ($USER->id != $user->id && has_capability('moodle/site:sendmessage', $context)) {
$userbuttons = array(
'messages' => array(
'title' => get_string('message', 'message'),
'url' => new moodle_url('/message/index.php', array('id' => $user->id)),
'image' => 'message',
'linkattributes' => message_messenger_sendmessage_link_params($user),
'page' => $this->page
)
);
}
}

$contextheader = new context_header($heading, $headinglevel, $imagedata, $userbuttons);
return $this->render_context_header($contextheader);
}
}

/**
* Renders the header bar.
Expand All @@ -4037,74 +4067,68 @@ public function context_header() {
*/
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);
$html = html_writer::start_div('page-context-header');

// Image data.
if (isset($contextheader->imagedata)) {
$html .= html_writer::div($this->user_picture($contextheader->imagedata, array('size' => 100)), 'page-header-image');
// Header specific image.
$html .= html_writer::div($contextheader->imagedata, 'page-header-image');
}

// Headings.
$headings = $this->heading($this->page->heading, 1);
if (isset($contextheader->subheading)) {
$headings .= html_writer::span($contextheader->subheading, 'fuckensubheading');
if (!isset($contextheader->heading)) {
$headings = $this->heading($this->page->heading, $contextheader->headinglevel);
} else {
$headings = $this->heading($contextheader->heading, $contextheader->headinglevel);
}

$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(
foreach ($contextheader->additionalbuttons as $button) {
if (!isset($button->page)) {
$image = $this->pix_icon($button['formattedimage'], $button['title'], 'moodle', array(
'class' => 'iconsmall',
'role' => 'presentation'
));
$image .= html_writer::span($value['title'], 'header-button-title');
$image .= html_writer::span($button['title'], 'header-button-title');
} else {
$image = html_writer::empty_tag('img', array(
'src' => $value['formattedimage'],
'src' => $button['formattedimage'],
'role' => 'presentation'
));
}
$html .= html_writer::link($value['url'], html_writer::tag('span', $image), $value['linkattributes']);
$html .= html_writer::link($button['url'], html_writer::tag('span', $image), $button['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() {
/**
* Wrapper for header elements.
*/
public function full_header($heading = null) {
$html = html_writer::start_tag('header', array('id' => 'page-header', 'class' => 'clearfix'));
$html .= $this->context_header();
// This is to ensure that the logo completely overwrites the header. MDL-49536 has been created to investigate
// whether the logo should work this way or not.
if (isset($heading) && $heading == '<div class="logo"></div>') {
$html .= $heading;
} else {
$html .= $this->context_header(array('heading' => $heading));
}
$html .= html_writer::start_div('clearfix', array('id' => 'page-navbar'));
$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_div();
$html .= html_writer::tag('div', $this->course_header(), array('class' => 'course-header'));
$html .= html_writer::end_tag('header');
return $html;

}
}

Expand Down
11 changes: 1 addition & 10 deletions theme/bootstrapbase/layout/columns1.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,7 @@

<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="span12">
Expand Down
11 changes: 1 addition & 10 deletions theme/bootstrapbase/layout/popup.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,7 @@

<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="span12">
Expand Down
Loading

0 comments on commit 3b927d3

Please sign in to comment.