Merge branch 'MDL-23219_22' of git://github.com/timhunt/moodle into MOODLE_22_STABLE
[moodle.git] / theme / afterburner / renderers.php
blob70fdebeb312307ffb4d46c4c01c97d5627dbaf20
1 <?php
3 class theme_afterburner_core_renderer extends core_renderer {
5 /**
6 * Renders a custom menu object (located in outputcomponents.php)
8 * The custom menu this method override the render_custom_menu function
9 * in outputrenderers.php
10 * @staticvar int $menucount
11 * @param custom_menu $menu
12 * @return string
14 protected function render_custom_menu(custom_menu $menu) {
16 // If the menu has no children return an empty string
17 if (!$menu->has_children()) {
18 return '';
21 // Add a login or logout link
22 if (isloggedin()) {
23 $branchlabel = get_string('logout');
24 $branchurl = new moodle_url('/login/logout.php');
25 } else {
26 $branchlabel = get_string('login');
27 $branchurl = new moodle_url('/login/index.php');
29 $branch = $menu->add($branchlabel, $branchurl, $branchlabel, -1);
31 // Initialise this custom menu
32 $content = html_writer::start_tag('ul', array('class'=>'dropdown dropdown-horizontal'));
33 // Render each child
34 foreach ($menu->get_children() as $item) {
35 $content .= $this->render_custom_menu_item($item);
37 // Close the open tags
38 $content .= html_writer::end_tag('ul');
39 // Return the custom menu
40 return $content;
43 /**
44 * Renders a custom menu node as part of a submenu
46 * The custom menu this method override the render_custom_menu_item function
47 * in outputrenderers.php
49 * @see render_custom_menu()
51 * @staticvar int $submenucount
52 * @param custom_menu_item $menunode
53 * @return string
55 protected function render_custom_menu_item(custom_menu_item $menunode) {
56 // Required to ensure we get unique trackable id's
57 static $submenucount = 0;
58 $content = html_writer::start_tag('li');
59 if ($menunode->has_children()) {
60 // If the child has menus render it as a sub menu
61 $submenucount++;
62 if ($menunode->get_url() !== null) {
63 $url = $menunode->get_url();
64 } else {
65 $url = '#cm_submenu_'.$submenucount;
67 $content .= html_writer::start_tag('span', array('class'=>'customitem'));
68 $content .= html_writer::link($url, $menunode->get_text(), array('title'=>$menunode->get_title()));
69 $content .= html_writer::end_tag('span');
70 $content .= html_writer::start_tag('ul');
71 foreach ($menunode->get_children() as $menunode) {
72 $content .= $this->render_custom_menu_item($menunode);
74 $content .= html_writer::end_tag('ul');
75 } else {
76 // The node doesn't have children so produce a final menuitem
78 if ($menunode->get_url() !== null) {
79 $url = $menunode->get_url();
80 } else {
81 $url = '#';
83 $content .= html_writer::link($url, $menunode->get_text(), array('title'=>$menunode->get_title()));
85 $content .= html_writer::end_tag('li');
86 // Return the sub menu
87 return $content;
90 /**
91 * Copied from core_renderer with one minor change - changed $this->output->render() call to $this->render()
93 * @param navigation_node $item
94 * @return string
96 protected function render_navigation_node(navigation_node $item) {
97 $content = $item->get_content();
98 $title = $item->get_title();
99 if ($item->icon instanceof renderable && !$item->hideicon) {
100 $icon = $this->render($item->icon);
101 $content = $icon.$content; // use CSS for spacing of icons
103 if ($item->helpbutton !== null) {
104 $content = trim($item->helpbutton).html_writer::tag('span', $content, array('class'=>'clearhelpbutton'));
106 if ($content === '') {
107 return '';
109 if ($item->action instanceof action_link) {
110 //adds class dimmed to hidden courses and categories
111 $link = $item->action;
112 if ($item->hidden) {
113 $link->add_class('dimmed');
115 $content = $this->render($link);
116 } else if ($item->action instanceof moodle_url) {
117 $attributes = array();
118 if ($title !== '') {
119 $attributes['title'] = $title;
121 if ($item->hidden) {
122 $attributes['class'] = 'dimmed_text';
124 $content = html_writer::link($item->action, $content, $attributes);
126 } else if (is_string($item->action) || empty($item->action)) {
127 $attributes = array();
128 if ($title !== '') {
129 $attributes['title'] = $title;
131 if ($item->hidden) {
132 $attributes['class'] = 'dimmed_text';
134 $content = html_writer::tag('span', $content, $attributes);
136 return $content;