From 7876a164138979a18c1b61cdf94ab290d1f2cdf4 Mon Sep 17 00:00:00 2001 From: Deon George Date: Fri, 14 Oct 2011 18:09:52 +1100 Subject: [PATCH] Work on the tree --- application/classes/controller/tree.php | 52 +++++++++++++++++++++---- 1 file changed, 45 insertions(+), 7 deletions(-) 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')); + } } }