|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 class block_settings_renderer extends plugin_renderer_base { 00004 00005 public function settings_tree(settings_navigation $navigation) { 00006 $count = 0; 00007 foreach ($navigation->children as &$child) { 00008 $child->preceedwithhr = ($count!==0); 00009 $count++; 00010 } 00011 $content = $this->navigation_node($navigation, array('class'=>'block_tree list')); 00012 if (isset($navigation->id) && !is_numeric($navigation->id) && !empty($content)) { 00013 $content = $this->output->box($content, 'block_tree_box', $navigation->id); 00014 } 00015 return $content; 00016 } 00017 00018 protected function navigation_node(navigation_node $node, $attrs=array()) { 00019 $items = $node->children; 00020 00021 // exit if empty, we don't want an empty ul element 00022 if ($items->count()==0) { 00023 return ''; 00024 } 00025 00026 // array of nested li elements 00027 $lis = array(); 00028 foreach ($items as $item) { 00029 if (!$item->display) { 00030 continue; 00031 } 00032 00033 $isbranch = ($item->children->count()>0 || $item->nodetype==navigation_node::NODETYPE_BRANCH); 00034 $hasicon = (!$isbranch && $item->icon instanceof renderable); 00035 00036 if ($isbranch) { 00037 $item->hideicon = true; 00038 } 00039 $content = $this->output->render($item); 00040 00041 // this applies to the li item which contains all child lists too 00042 $liclasses = array($item->get_css_type()); 00043 if (!$item->forceopen || (!$item->forceopen && $item->collapse) || ($item->children->count()==0 && $item->nodetype==navigation_node::NODETYPE_BRANCH)) { 00044 $liclasses[] = 'collapsed'; 00045 } 00046 if ($isbranch) { 00047 $liclasses[] = 'contains_branch'; 00048 } else if ($hasicon) { 00049 $liclasses[] = 'item_with_icon'; 00050 } 00051 if ($item->isactive === true) { 00052 $liclasses[] = 'current_branch'; 00053 } 00054 $liattr = array('class'=>join(' ',$liclasses)); 00055 // class attribute on the div item which only contains the item content 00056 $divclasses = array('tree_item'); 00057 if ($isbranch) { 00058 $divclasses[] = 'branch'; 00059 } else { 00060 $divclasses[] = 'leaf'; 00061 } 00062 if (!empty($item->classes) && count($item->classes)>0) { 00063 $divclasses[] = join(' ', $item->classes); 00064 } 00065 $divattr = array('class'=>join(' ', $divclasses)); 00066 if (!empty($item->id)) { 00067 $divattr['id'] = $item->id; 00068 } 00069 $content = html_writer::tag('p', $content, $divattr) . $this->navigation_node($item); 00070 if (!empty($item->preceedwithhr) && $item->preceedwithhr===true) { 00071 $content = html_writer::empty_tag('hr') . $content; 00072 } 00073 $content = html_writer::tag('li', $content, $liattr); 00074 $lis[] = $content; 00075 } 00076 00077 if (count($lis)) { 00078 return html_writer::tag('ul', implode("\n", $lis), $attrs); 00079 } else { 00080 return ''; 00081 } 00082 } 00083 00084 public function search_form(moodle_url $formtarget, $searchvalue) { 00085 $content = html_writer::start_tag('form', array('class'=>'adminsearchform', 'method'=>'get', 'action'=>$formtarget)); 00086 $content .= html_writer::start_tag('div'); 00087 $content .= html_writer::tag('label', s(get_string('searchinsettings', 'admin')), array('for'=>'adminsearchquery', 'class'=>'accesshide')); 00088 $content .= html_writer::empty_tag('input', array('id'=>'adminsearchquery', 'type'=>'text', 'name'=>'query', 'value'=>s($searchvalue))); 00089 $content .= html_writer::empty_tag('input', array('type'=>'submit', 'value'=>s(get_string('search')))); 00090 $content .= html_writer::end_tag('div'); 00091 $content .= html_writer::end_tag('form'); 00092 return $content; 00093 } 00094 00095 }