Moodle 2.2.4 release
[moodle.git] / blocks / settings / renderer.php
blob41cea8742c2d89e708abe5d7d90fffdd80aa8e02
1 <?php
3 class block_settings_renderer extends plugin_renderer_base {
5 public function settings_tree(settings_navigation $navigation) {
6 $count = 0;
7 foreach ($navigation->children as &$child) {
8 $child->preceedwithhr = ($count!==0);
9 $count++;
11 $content = $this->navigation_node($navigation, array('class'=>'block_tree list'));
12 if (isset($navigation->id) && !is_numeric($navigation->id) && !empty($content)) {
13 $content = $this->output->box($content, 'block_tree_box', $navigation->id);
15 return $content;
18 protected function navigation_node(navigation_node $node, $attrs=array()) {
19 $items = $node->children;
21 // exit if empty, we don't want an empty ul element
22 if ($items->count()==0) {
23 return '';
26 // array of nested li elements
27 $lis = array();
28 foreach ($items as $item) {
29 if (!$item->display) {
30 continue;
33 $isbranch = ($item->children->count()>0 || $item->nodetype==navigation_node::NODETYPE_BRANCH);
34 $hasicon = (!$isbranch && $item->icon instanceof renderable);
36 if ($isbranch) {
37 $item->hideicon = true;
39 $content = $this->output->render($item);
41 // this applies to the li item which contains all child lists too
42 $liclasses = array($item->get_css_type());
43 if (!$item->forceopen || (!$item->forceopen && $item->collapse) || ($item->children->count()==0 && $item->nodetype==navigation_node::NODETYPE_BRANCH)) {
44 $liclasses[] = 'collapsed';
46 if ($isbranch) {
47 $liclasses[] = 'contains_branch';
48 } else if ($hasicon) {
49 $liclasses[] = 'item_with_icon';
51 if ($item->isactive === true) {
52 $liclasses[] = 'current_branch';
54 $liattr = array('class'=>join(' ',$liclasses));
55 // class attribute on the div item which only contains the item content
56 $divclasses = array('tree_item');
57 if ($isbranch) {
58 $divclasses[] = 'branch';
59 } else {
60 $divclasses[] = 'leaf';
62 if (!empty($item->classes) && count($item->classes)>0) {
63 $divclasses[] = join(' ', $item->classes);
65 $divattr = array('class'=>join(' ', $divclasses));
66 if (!empty($item->id)) {
67 $divattr['id'] = $item->id;
69 $content = html_writer::tag('p', $content, $divattr) . $this->navigation_node($item);
70 if (!empty($item->preceedwithhr) && $item->preceedwithhr===true) {
71 $content = html_writer::empty_tag('hr') . $content;
73 $content = html_writer::tag('li', $content, $liattr);
74 $lis[] = $content;
77 if (count($lis)) {
78 return html_writer::tag('ul', implode("\n", $lis), $attrs);
79 } else {
80 return '';
84 public function search_form(moodle_url $formtarget, $searchvalue) {
85 $content = html_writer::start_tag('form', array('class'=>'adminsearchform', 'method'=>'get', 'action'=>$formtarget));
86 $content .= html_writer::start_tag('div');
87 $content .= html_writer::tag('label', s(get_string('searchinsettings', 'admin')), array('for'=>'adminsearchquery', 'class'=>'accesshide'));
88 $content .= html_writer::empty_tag('input', array('id'=>'adminsearchquery', 'type'=>'text', 'name'=>'query', 'value'=>s($searchvalue)));
89 $content .= html_writer::empty_tag('input', array('type'=>'submit', 'value'=>s(get_string('search'))));
90 $content .= html_writer::end_tag('div');
91 $content .= html_writer::end_tag('form');
92 return $content;