mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-07-25 00:24:35 +00:00
refactor
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user