diff --git a/application/classes/controller/tree.php b/application/classes/controller/tree.php index 4b6cec70..e33c5a1f 100644 --- a/application/classes/controller/tree.php +++ b/application/classes/controller/tree.php @@ -42,6 +42,10 @@ class Controller_Tree extends Controller_lnApp_Tree { array_push($data,array('id'=>$id,'name'=>$mo->name,'state'=>'closed')); } else { + $idx = NULL; + if (preg_match('/:/',$id)) + list($id,$idx) = explode(':',$id,2); + $mo = ORM::factory('module',$id); $methods = array(); @@ -54,6 +58,7 @@ class Controller_Tree extends Controller_lnApp_Tree { Sort::MASort($modules,'name'); + $subdata = array(); foreach ($methods as $id => $mmo) { if (preg_match('/_/',$mmo->name)) { list($mode,$action) = explode('_',$mmo->name); @@ -62,14 +67,47 @@ class Controller_Tree extends Controller_lnApp_Tree { $url = URL::site(sprintf('%s/%s',$mmo->module->name,$mmo->name)); } - array_push($data,array( - 'id'=>sprintf('%s_%s',$mmo->module_id,$id), - 'name'=>$mmo->name, - 'state'=>'none', - 'attr_id'=>sprintf('%s_%s',$mmo->module->name,$id), - 'attr_href'=>(empty($details['page']) ? $url : $details['page']) - )); + // We can split our menus into sub menus using the _ char. + if (preg_match('/_/',$mmo->name)) { + list($sub,$name) = explode('_',$mmo->name,2); + $subdata[$sub][$name]['name'] = preg_replace('/^(.*: )/','',$mmo->notes); + $subdata[$sub][$name]['id'] = sprintf('%s_%s',$mmo->module_id,$id); + $subdata[$sub][$name]['href'] = (empty($details['page']) ? $url : $details['page']); + + } else { + // We dont want to show these items again, if we can through on a submenu + if (! $idx) + array_push($data,array( + 'id'=>sprintf('%s_%s',$mmo->module_id,$id), + 'name'=>$mmo->name, + 'state'=>'none', + 'attr_id'=>sprintf('%s_%s',$mmo->module->name,$id), + 'attr_href'=>(empty($details['page']) ? $url : $details['page']) + )); + } } + + // If our sub menus only have 1 branch, then we'll display it as normal. + if (count($subdata) == 1) { + $sk = array_keys($subdata); + $idx = array_shift($sk); + } + + if ($idx) + foreach ($subdata[$idx] as $k=>$v) { + array_push($data,array( + 'id'=>$v['id'], + 'name'=>$v['name'], + 'state'=>'none', + 'attr_id'=>$v['id'], + 'attr_href'=>$v['href'] + )); + } + + else + foreach ($subdata as $t=>$x) + array_push($data,array('id'=>$mmo->module_id.':'.$t,'name'=>$t,'state'=>'closed')); + } } }