public static function signed_in($user, $loginfailures, $mnet, $real, $role_switch, $logout) { $links[] = bootstrap::li_icon_link($user['link'], 'user', 'Profile'); if ($mnet !== null) { $links[] = bootstrap::li_icon_link($mnet['link'], 'globe', $mnet['name']); } if (isset($loginfailures)) { $links[] = bootstrap::li_icon_link($loginfailures['link'], 'warning-sign', $loginfailures['name']); $user['name'] .= ' ' . bootstrap::icon('warning-sign'); } if ($role_switch !== null) { $links[] = bootstrap::li_icon_link($role_switch['link'], 'repeat', $role_switch['name']); } if ($real !== null) { $links[] = bootstrap::li_icon_link($real['link'], 'user', $real['name']); } $links[] = bootstrap::list_divider(); $links[] = bootstrap::li_icon_link($logout['link'], 'off', $logout['name']); return html::ul('nav pull-right', bootstrap::dropdown_menu($user['name'], $links)); }
protected function render_custom_menu_item(custom_menu_item $menunode, $submenu = null) { if ('list_divider' === $menunode->get_text()) { return bootstrap::list_divider(); } if (!$menunode->has_children()) { return $this->render_custom_menu_leaf($menunode); } foreach ($menunode->get_children() as $child) { $items[] = $this->render_custom_menu_item($child, true); } if ($submenu === true) { return html::li(bootstrap::dropdown_submenu($menunode->get_text(), $items)); } else { return html::li(bootstrap::dropdown_menu($menunode->get_text(), $items)); } }
protected function navigation_node(navigation_node $node, $attrs = array('class' => 'nav nav-list')) { $items = $node->children; // exit if empty, we don't want an empty ul element if ($items->count() == 0) { return ''; } // array of nested li elements $lis = array(); foreach ($items as $item) { if (!$item->display) { continue; } $isbranch = $item->children->count() > 0 || $item->nodetype == navigation_node::NODETYPE_BRANCH; $hasicon = !$isbranch && $item->icon instanceof renderable; if ($isbranch) { $item->hideicon = true; } $content = $this->output->render($item); // this applies to the li item which contains all child lists too $liclasses = array($item->get_css_type()); $liexpandable = array(); if (!$item->forceopen || !$item->forceopen && $item->collapse || $item->children->count() == 0 && $item->nodetype == navigation_node::NODETYPE_BRANCH) { $liclasses[] = 'collapsed'; } if ($isbranch) { $liclasses[] = 'contains_branch'; $liexpandable = array('aria-expanded' => in_array('collapsed', $liclasses) ? "false" : "true"); } else { if ($hasicon) { $liclasses[] = 'item_with_icon'; } } if ($item->isactive === true) { $liclasses[] = 'current_branch'; $liclasses[] = 'active'; } $liattr = array('class' => join(' ', $liclasses)) + $liexpandable; // class attribute on the div item which only contains the item content $divclasses = array('tree_item'); if ($isbranch) { $divclasses[] = 'branch'; } else { $divclasses[] = 'leaf'; } if (!empty($item->classes) && count($item->classes) > 0) { $divclasses[] = join(' ', $item->classes); } $divattr = array('class' => join(' ', $divclasses)); if (!empty($item->id)) { $divattr['id'] = $item->id; } $content = $this->rewrite_tree_node($content, $divclasses); $content .= $this->navigation_node($item); $content = html_writer::tag('li', $content, $liattr); if (!empty($item->preceedwithhr) && $item->preceedwithhr === true) { $content = bootstrap::list_divider() . $content; } $lis[] = $content; } if (count($lis)) { return html_writer::tag('ul', implode("\n", $lis), $attrs); } else { return ''; } }
protected function navigation_node($items, $attrs = array('class' => 'nav nav-list'), $expansionlimit = null, array $options = array(), $depth = 1) { // exit if empty, we don't want an empty ul element if (count($items) == 0) { return ''; } // array of nested li elements $lis = array(); foreach ($items as $item) { if (!$item->display && !$item->contains_active_node()) { continue; } $content = $item->get_content(); $title = $item->get_title(); $isexpandable = empty($expansionlimit) || ($item->type > navigation_node::TYPE_ACTIVITY || $item->type < $expansionlimit) || $item->contains_active_node() && $item->children->count() > 0; $isbranch = $isexpandable && ($item->children->count() > 0 || $item->has_children() && (isloggedin() || $item->type <= navigation_node::TYPE_CATEGORY)); // Skip elements which have no content and no action - no point in showing them if (!$isexpandable && empty($item->action)) { continue; } $hasicon = (!$isbranch || $item->type == navigation_node::TYPE_ACTIVITY || $item->type == navigation_node::TYPE_RESOURCE) && $item->icon instanceof renderable; if ($hasicon) { $icon = $this->output->render($item->icon); } else { $icon = ''; } $content = $icon . $content; // use CSS for spacing of icons if ($item->helpbutton !== null) { $content = trim($item->helpbutton) . html_writer::tag('span', $content, array('class' => 'clearhelpbutton')); } if ($content === '') { continue; } $attributes = array(); if ($title !== '') { $attributes['title'] = $title; } if ($item->hidden) { $attributes['class'] = 'dimmed_text'; } if (is_string($item->action) || empty($item->action) || $item->type === navigation_node::TYPE_CATEGORY && empty($options['linkcategories'])) { $attributes['tabindex'] = '0'; //add tab support to span but still maintain character stream sequence. $content = html_writer::tag('span', $content, $attributes); } else { if ($item->action instanceof action_link) { //TODO: to be replaced with something else $link = $item->action; $link->text = $icon . $link->text; $link->attributes = array_merge($link->attributes, $attributes); $content = $this->output->render($link); $linkrendered = true; } else { if ($item->action instanceof moodle_url) { $content = html_writer::link($item->action, $content, $attributes); } } } // this applies to the li item which contains all child lists too $liclasses = array($item->get_css_type(), 'depth_' . $depth); $liexpandable = array(); if ($item->has_children() && (!$item->forceopen || $item->collapse)) { $liclasses[] = 'collapsed'; } if ($isbranch) { $liclasses[] = 'contains_branch'; $liexpandable = array('aria-expanded' => in_array('collapsed', $liclasses) ? "false" : "true"); } else { if ($hasicon) { $liclasses[] = 'item_with_icon'; } } if ($item->isactive === true) { $liclasses[] = 'current_branch'; $liclasses[] = 'active'; } $liattr = array('class' => join(' ', $liclasses)) + $liexpandable; // class attribute on the div item which only contains the item content $divclasses = array('tree_item'); if ($isbranch) { $divclasses[] = 'branch'; } else { $divclasses[] = 'leaf'; } if ($hasicon) { $divclasses[] = 'hasicon'; } if (!empty($item->classes) && count($item->classes) > 0) { $divclasses[] = join(' ', $item->classes); } $divattr = array('class' => join(' ', $divclasses)); if (!empty($item->id)) { $divattr['id'] = $item->id; } $content = $this->rewrite_tree_node($content, $divclasses); if ($isexpandable) { $content .= $this->navigation_node($item->children, array('class' => 'nav nav-list'), $expansionlimit, $options, $depth + 1); } if (!empty($item->preceedwithhr) && $item->preceedwithhr === true) { $content = bootstrap::list_divider() . $content; } $content = html_writer::tag('li', $content, $liattr); $lis[] = $content; } if (count($lis)) { return html_writer::tag('ul', implode("\n", $lis), $attrs); } else { return ''; } }