This commit is contained in:
Harald Bamberger
2026-06-22 09:52:08 +02:00
parent b0fea017f2
commit d1ef2e4f74
8 changed files with 215 additions and 62 deletions
+77 -8
View File
@@ -10,15 +10,20 @@
*
* @author bambi
*/
abstract class TreeMenuLib
class TreeMenuLib
{
protected $ci;
protected $children_config;
protected $params;
protected $includeSubMenu;
public function __construct($children_config)
{
$this->ci =& get_instance();
$this->children_config = $children_config;
$this->params = array();
$this->includeSubMenu = false;
foreach($this->children_config as $child_config)
{
$grandchildren_config = isset($child_config['children']) ? $child_config['children'] : [];
@@ -26,14 +31,78 @@ abstract class TreeMenuLib
}
}
public function getNode($name)
public function init($params=array(), $includeSubMenu=false)
{
$node = array(
'name' => $name
);
return $node;
$this->params = $params;
$this->includeSubMenu = $includeSubMenu;
}
public abstract function getSubMenu();
public function getNodes()
{
$data = $this->getData();
$nodes = array();
foreach($data as $element)
{
$node = array(
'name' => $this->getName($element),
'link' => $this->getLink($element),
'leaf' => $this->isLeaf()
);
if($this->includeSubMenu)
{
$node['children'] = $this->getSubMenu($element);
}
$nodes[] = $node;
};
return $nodes;
}
public function getSubMenu($element=null)
{
$nodes = array();
foreach($this->children_config as $childconfig)
{
$childlib = basename($childconfig['library']);
$this->ci->$childlib->init(
$this->getParamsForNextLevel($element),
$this->includeSubMenu
);
$childnodes = $this->ci->$childlib->getNodes();
$nodes = array_merge($nodes, $childnodes);
}
return $nodes;
}
protected function getData()
{
return array();
}
protected function getParamsForNextLevel($element=null)
{
return $this->params;
}
protected function getName($element)
{
return __METHOD__ . 'NOT IMPLEMENTED';
}
protected function getLink($element)
{
$link = $this->ci->uri->assoc_to_uri($this->getParamsForNextLevel($element));
return $link;
}
protected function isLeaf()
{
if(count($this->children_config) === 0) {
return true;
}
return false;
}
}