public function navbar() { global $CFG; $items = $this->page->navbar->get_items(); /* Added for subadmin */ $context = get_context_instance(CONTEXT_SYSTEM); $roles = get_user_roles($context, $USER->id, false); $role = key($roles); $rolename = $roles[$role]->shortname; $htmlblocks = array(); // Iterate the navarray and display each node $itemcount = count($items); $separator = get_separator(); for ($i = 0; $i < $itemcount; $i++) { $item = $items[$i]; $item->hideicon = true; if ($i === 0) { if ($rolename == 'subadmin') { $item->action = new moodle_url($CFG->wwwroot . '/my/'); } $content = html_writer::tag('li', $this->render($item)); } else { $content = html_writer::tag('li', $separator . $this->render($item)); } $htmlblocks[] = $content; } //accessibility: heading for navbar list (MDL-20446) $navbarcontent = html_writer::tag('span', get_string('pagepath'), array('class' => 'accesshide')); $navbarcontent .= html_writer::tag('ul', join('', $htmlblocks), array('role' => 'navigation')); // XHTML return $navbarcontent; }
/** * Constructor. * * @param bool $showpasses Whether this reporter should output anything for passes. */ function __construct($showpasses) { parent::__construct('UTF-8'); $this->showpasses = $showpasses; $this->strrunonlyfolder = $this->get_string('runonlyfolder'); $this->strrunonlyfile = $this->get_string('runonlyfile'); $this->strseparator = get_separator(); }
/** * Constructor. * * @param bool $showpasses Whether this reporter should output anything for passes. */ function ExHtmlReporter($showpasses) { $this->HtmlReporter(); $this->showpasses = $showpasses; $this->strrunonlyfolder = $this->get_string('runonlyfolder'); $this->strrunonlyfile = $this->get_string('runonlyfile'); $this->strseparator = get_separator(); }
public function navbar() { $items = $this->page->navbar->get_items(); $breadcrumbs = array(); foreach ($items as $item) { $item->hideicon = true; $breadcrumbs[] = $this->render($item); } $divider = '<span class="divider">' . get_separator() . '</span>'; $list_items = '<li>' . join(" {$divider}</li><li>", $breadcrumbs) . '</li>'; $title = '<span class="accesshide">' . get_string('pagepath') . '</span>'; return $title . "<ul class=\"breadcrumb\">{$list_items}</ul>"; }
/** * Renderers a progress bar for the backup or restore given the items that * make it up. * @param array $items An array of items * @return string */ public function progress_bar(array $items) { foreach ($items as &$item) { $text = $item['text']; unset($item['text']); if (array_key_exists('link', $item)) { $link = $item['link']; unset($item['link']); $item = html_writer::link($link, $text, $item); } else { $item = html_writer::tag('span', $text, $item); } } return html_writer::tag('div', join(get_separator(), $items), array('class'=>'backup_progress clearfix')); }
public function navbar() { $items = $this->page->navbar->get_items(); if (empty($items)) { return ''; } $breadcrumbs = array(); foreach ($items as $item) { $item->hideicon = true; $breadcrumbs[] = $this->render($item); } $divider = '<span class="divider">' . get_separator() . '</span>'; $list_items = '<li>' . join(" {$divider}</li><li>", $breadcrumbs) . '</li>'; $title = '<span class="accesshide" id="navbar-label">' . get_string('pagepath') . '</span>'; return $title . '<nav aria-labelledby="navbar-label"><ul class="breadcrumb">' . $list_items . '</ul></nav>'; }
/** * Return the navbar content so that it can be echoed out by the layout * * @return string XHTML navbar */ public function navbar() { $items = $this->page->navbar->get_items(); $itemcount = count($items); if ($itemcount === 0) { return ''; } $htmlblocks = array(); // Iterate the navarray and display each node $separator = get_separator(); for ($i=0;$i < $itemcount;$i++) { $item = $items[$i]; $item->hideicon = true; if ($i===0) { $content = html_writer::tag('li', $this->render($item)); } else { $content = html_writer::tag('li', $separator.$this->render($item)); } $htmlblocks[] = $content; } //accessibility: heading for navbar list (MDL-20446) $navbarcontent = html_writer::tag('span', get_string('pagepath'), array('class'=>'accesshide')); $navbarcontent .= html_writer::tag('nav', html_writer::tag('ul', join('', $htmlblocks))); // XHTML return $navbarcontent; }
/** * This function will build the navigation string to be used by print_header * and others. * * It automatically generates the site and course level (if appropriate) links. * * If you pass in a $cm object, the method will also generate the activity (e.g. 'Forums') * and activityinstances (e.g. 'General Developer Forum') navigation levels. * * If you want to add any further navigation links after the ones this function generates, * the pass an array of extra link arrays like this: * array( * array('name' => $linktext1, 'link' => $url1, 'type' => $linktype1), * array('name' => $linktext2, 'link' => $url2, 'type' => $linktype2) * ) * The normal case is to just add one further link, for example 'Editing forum' after * 'General Developer Forum', with no link. * To do that, you need to pass * array(array('name' => $linktext, 'link' => '', 'type' => 'title')) * However, becuase this is a very common case, you can use a shortcut syntax, and just * pass the string 'Editing forum', instead of an array as $extranavlinks. * * At the moment, the link types only have limited significance. Type 'activity' is * recognised in order to implement the $CFG->hideactivitytypenavlink feature. Types * that are known to appear are 'home', 'course', 'activity', 'activityinstance' and 'title'. * This really needs to be documented better. In the mean time, try to be consistent, it will * enable people to customise the navigation more in future. * * When passing a $cm object, the fields used are $cm->modname, $cm->name and $cm->course. * If you get the $cm object using the function get_coursemodule_from_instance or * get_coursemodule_from_id (as recommended) then this will be done for you automatically. * If you don't have $cm->modname or $cm->name, this fuction will attempt to find them using * the $cm->module and $cm->instance fields, but this takes extra database queries, so a * warning is printed in developer debug mode. * * @uses $CFG * @uses $THEME * * @param mixed $extranavlinks - Normally an array of arrays, keys: name, link, type. If you * only want one extra item with no link, you can pass a string instead. If you don't want * any extra links, pass an empty string. * @param mixed $cm - optionally the $cm object, if you want this function to generate the * activity and activityinstance levels of navigation too. * * @return $navigation as an object so it can be differentiated from old style * navigation strings. */ function build_navigation($extranavlinks, $cm = null) { global $CFG, $COURSE, $DB, $SITE; if (is_string($extranavlinks)) { if ($extranavlinks == '') { $extranavlinks = array(); } else { $extranavlinks = array(array('name' => $extranavlinks, 'link' => '', 'type' => 'title')); } } $navlinks = array(); //Site name if (!empty($SITE->shortname)) { $navlinks[] = array('name' => format_string($SITE->shortname), 'link' => "{$CFG->wwwroot}/", 'type' => 'home'); } // Course name, if appropriate. if (isset($COURSE) && $COURSE->id != SITEID) { $navlinks[] = array('name' => format_string($COURSE->shortname), 'link' => "{$CFG->wwwroot}/course/view.php?id={$COURSE->id}", 'type' => 'course'); } // Activity type and instance, if appropriate. if (is_object($cm)) { if (!isset($cm->modname)) { debugging('The field $cm->modname should be set if you call build_navigation with ' . 'a $cm parameter. If you get $cm using get_coursemodule_from_instance or ' . 'get_coursemodule_from_id, this will be done automatically.', DEBUG_DEVELOPER); if (!($cm->modname = $DB->get_field('modules', 'name', array('id' => $cm->module)))) { print_error('cannotmoduletype'); } } if (!isset($cm->name)) { debugging('The field $cm->name should be set if you call build_navigation with ' . 'a $cm parameter. If you get $cm using get_coursemodule_from_instance or ' . 'get_coursemodule_from_id, this will be done automatically.', DEBUG_DEVELOPER); if (!($cm->name = $DB->get_field($cm->modname, 'name', array('id' => $cm->instance)))) { print_error('cannotmodulename'); } } $navlinks[] = array('name' => get_string('modulenameplural', $cm->modname), 'link' => $CFG->wwwroot . '/mod/' . $cm->modname . '/index.php?id=' . $cm->course, 'type' => 'activity'); $navlinks[] = array('name' => format_string($cm->name), 'link' => $CFG->wwwroot . '/mod/' . $cm->modname . '/view.php?id=' . $cm->id, 'type' => 'activityinstance'); } //Merge in extra navigation links $navlinks = array_merge($navlinks, $extranavlinks); // Work out whether we should be showing the activity (e.g. Forums) link. // Note: build_navigation() is called from many places -- // install & upgrade for example -- where we cannot count on the // roles infrastructure to be defined. Hence the $CFG->rolesactive check. if (!isset($CFG->hideactivitytypenavlink)) { $CFG->hideactivitytypenavlink = 0; } if ($CFG->hideactivitytypenavlink == 2) { $hideactivitylink = true; } else { if ($CFG->hideactivitytypenavlink == 1 && $CFG->rolesactive && !empty($COURSE->id) && $COURSE->id != SITEID) { if (!isset($COURSE->context)) { $COURSE->context = get_context_instance(CONTEXT_COURSE, $COURSE->id); } $hideactivitylink = !has_capability('moodle/course:manageactivities', $COURSE->context); } else { $hideactivitylink = false; } } //Construct an unordered list from $navlinks //Accessibility: heading hidden from visual browsers by default. $navigation = get_accesshide(get_string('youarehere', 'access'), 'h2') . " <ul>\n"; $lastindex = count($navlinks) - 1; $i = -1; // Used to count the times, so we know when we get to the last item. $first = true; foreach ($navlinks as $navlink) { $i++; $last = $i == $lastindex; if (!is_array($navlink)) { continue; } if (!empty($navlink['type']) && $navlink['type'] == 'activity' && !$last && $hideactivitylink) { continue; } $navigation .= '<li class="first">'; if (!$first) { $navigation .= get_separator(); } if (!empty($navlink['link']) && !$last) { $navigation .= "<a onclick=\"this.target='{$CFG->framename}'\" href=\"{$navlink['link']}\">"; } $navigation .= "{$navlink['name']}"; if (!empty($navlink['link']) && !$last) { $navigation .= "</a>"; } $navigation .= "</li>"; $first = false; } $navigation .= "</ul>"; return array('newnav' => true, 'navlinks' => $navigation); }
/** * Prints breadcrumb trail of links, called in theme/-/header.html * * @uses $CFG * @param mixed $navigation The breadcrumb navigation string to be printed * @param string $separator The breadcrumb trail separator. The default 0 leads to the use * of $THEME->rarrow, themes could use '→', '/', or '' for a style-sheet solution. * @param boolean $return False to echo the breadcrumb string (default), true to return it. */ function print_navigation($navigation, $separator = 0, $return = false) { global $CFG, $THEME; $output = ''; if (0 === $separator) { $separator = get_separator(); } else { $separator = '<span class="sep">' . $separator . '</span>'; } if ($navigation) { if (!is_array($navigation)) { $ar = explode('->', $navigation); $navigation = array(); foreach ($ar as $a) { if (strpos($a, '</a>') === false) { $navigation[] = array('title' => $a, 'url' => ''); } else { if (preg_match('/<a.*href="([^"]*)">(.*)<\\/a>/', $a, $matches)) { $navigation[] = array('title' => $matches[2], 'url' => $matches[1]); } } } } if (!($site = get_site())) { $site = new object(); $site->shortname = get_string('home'); } //Accessibility: breadcrumb links now in a list, » replaced with a 'silent' character. $output .= get_accesshide(get_string('youarehere', 'access'), 'h2') . "<ul>\n"; $output .= '<li class="first">' . "\n" . '<a ' . $CFG->frametarget . ' onclick="this.target=\'' . $CFG->framename . '\'" href="' . $CFG->wwwroot . (!has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM)) && !empty($USER->id) && !empty($CFG->mymoodleredirect) && !isguest() ? '/my' : '') . '/">' . format_string($site->shortname) . "</a>\n</li>\n"; foreach ($navigation as $navitem) { $title = trim(strip_tags(format_string($navitem['title'], false))); $url = $navitem['url']; if (empty($url)) { $output .= '<li class="first">' . "{$separator} {$title}</li>\n"; } else { $output .= '<li class="first">' . "{$separator}\n<a " . $CFG->frametarget . ' onclick="this.target=\'' . $CFG->framename . '\'" href="' . $url . '">' . "{$title}</a>\n</li>\n"; } } $output .= "</ul>\n"; } if ($return) { return $output; } else { echo $output; } }
/** * This function will build the navigation string to be used by print_header * and others * @uses $CFG * @uses $THEME * @param $extranavlinks - array of associative arrays, keys: name, link, type * @return $navigation as an object so it can be differentiated from old style * navigation strings. */ function build_navigation($extranavlinks) { global $CFG, $COURSE; $navigation = ''; $navlinks = array(); //Site name if ($site = get_site()) { $navlinks[] = array('name' => format_string($site->shortname), 'link' => "{$CFG->wwwroot}/", 'type' => 'home'); } if ($COURSE) { if ($COURSE->id != SITEID) { //Course $navlinks[] = array('name' => format_string($COURSE->shortname), 'link' => "{$CFG->wwwroot}/course/view.php?id={$COURSE->id}", 'type' => 'course'); } } //Merge in extra navigation links $navlinks = array_merge($navlinks, $extranavlinks); //Construct an unordered list from $navlinks //Accessibility: heading hidden from visual browsers by default. $navigation = '<h2 class="accesshide">' . get_string('youarehere', 'access') . "</h2> <ul>\n"; $countlinks = count($navlinks); $i = 0; foreach ($navlinks as $navlink) { if ($i >= $countlinks || !is_array($navlink)) { continue; } // Check the link type to see if this link should appear in the trail // // NOTE: we should move capchecks _out_ to the callers. build_navigation() is // called from many places -- install & upgrade for example -- where we cannot // count on the roles infrastructure to be defined. // $cap = 0; if (!empty($COURSE->id) && $COURSE->id != SITEID) { if (!isset($COURSE->context)) { $COURSE->context = get_context_instance(CONTEXT_COURSE, $COURSE->id); } $cap = has_capability('moodle/course:manageactivities', $COURSE->context); } $hidetype_is2 = isset($CFG->hideactivitytypenavlink) && $CFG->hideactivitytypenavlink == 2; $hidetype_is1 = isset($CFG->hideactivitytypenavlink) && $CFG->hideactivitytypenavlink == 1; if ($navlink['type'] == 'activity' && $i + 1 < $countlinks && ($hidetype_is2 || $hidetype_is1 && !$cap)) { continue; } $navigation .= '<li class="first">'; if ($i > 0) { $navigation .= get_separator(); } if (!empty($navlink['link']) && $i + 1 < $countlinks) { $navigation .= "<a onclick=\"this.target='{$CFG->framename}'\" href=\"{$navlink['link']}\">"; } $navigation .= "{$navlink['name']}"; if (!empty($navlink['link']) && $i + 1 < $countlinks) { $navigation .= "</a>"; } $navigation .= "</li>"; $i++; } $navigation .= "</ul>"; return array('newnav' => true, 'navlinks' => $navigation); }
public function navbar() { $items = $this->page->navbar->get_items(); $breadcrumbs = array(); foreach ($items as $item) { $item->hideicon = true; /* * Trying to replace the 'My home' breadcrumb * not very elegant; another solution may be considered later */ $ismyhome = strcasecmp($item->text, get_string('myhome')) == 0; if ($ismyhome) { $breadcrumbs[] = '<a href="/" id="moo-home-button"> <i class="fa fa-home fa-lg"></i></a>'; continue; // go to next element } /**/ $a = $this->render($item); if (strpos($a, "/course/view.php") !== false) { $breadcrumbs[] = html_writer::div($a, 'coursetitle'); } else { $breadcrumbs[] = $a; } } // ADD ELLIPSES ... $new_breadcrumbs = array(); $counter = 0; foreach ($breadcrumbs as $breadcrumb) { //add ellipses in second position if ($counter == 1) { $new_breadcrumbs[] = "<span id='ellipses'>...</span>"; } $new_breadcrumbs[] = $breadcrumb; $counter++; } // $divider = '<span class="divider">' . get_separator() . '</span>'; $list_items = '<li>' . join(" {$divider}</li><li>", $new_breadcrumbs) . '</li>'; $title = '<span class="accesshide">' . get_string('pagepath') . '</span>'; return $title . "<ul id=\"bc1\" class=\"breadcrumb\">{$list_items}</ul>"; }