public function renderAsHtml($data = false, $parent = 0, $first = true)
{
$args = $this->setParameters(func_get_args());
// open the ul tag if function is first run
$tree = $first ? $this->ul(null, $parent) : '';
$args['data']->each(function ($child_item) use(&$tree, $args) {
$childItems = '';
if (intval($child_item[$this->parent]) == intval($args['parent'])) {
$path = $child_item[$this->config['html']['href']];
$label = $child_item[$this->config['html']['label']];
$currentData = ['label' => $label, 'href' => $this->url($path, $label)];
// Check the active item
$activeItem = $this->doActive($path, $label);
// open the li tag
$childItems .= $this->openLi($currentData, $activeItem);
// Get the primary key name
$item_id = $child_item[$this->config['primary_key']];
// check the child element
if ($this->hasChild($this->parent, $item_id, $args['data'])) {
// function call again for child elements
$html = $this->renderAsHtml($args['data'], $item_id, false);
if (!empty($html)) {
$childItems .= $this->ul($html, $item_id);
}
}
// close the li tag
$childItems = $this->closeLi($childItems);
}
// current data contact to the parent variable
$tree = $tree . $childItems;
});
// close the ul tag
$tree = $first ? $this->closeUl($tree) : $tree;
return $tree;
}