Back to Menu class

Method treerecurse

public static array
treerecurse
(mixed $id, mixed $indent, mixed $list, mixed &$children, mixed $maxlevel = 9999, mixed $level = 0, mixed $type = 1)
Build the list representing the menu tree
Parameters
  • int $id Id of the menu item
  • string $indent The indentation string
  • array $list The list to process
  • array $children The children of the current item
  • int $maxlevel The maximum number of levels in the tree
  • int $level The starting level
  • int $type Set the type of spacer to use. Use 1 for |_ or 0 for -
Returns
  • array
Since
  • 1.5
Class: Menu
Project: Joomla

Method treerecurse - Source code

/**
 * Build the list representing the menu tree
 *
 * @param   integer  $id         Id of the menu item
 * @param   string   $indent     The indentation string
 * @param   array    $list       The list to process
 * @param   array    $children   The children of the current item
 * @param   integer  $maxlevel   The maximum number of levels in the tree
 * @param   integer  $level      The starting level
 * @param   int      $type       Set the type of spacer to use. Use 1 for |_ or 0 for -
 *
 * @return  array
 *
 * @since   1.5
 */
public static function treerecurse($id, $indent, $list, &$children, $maxlevel = 9999, $level = 0, $type = 1)
{
    if ($level <= $maxlevel && isset($children[$id]) && is_array($children[$id])) {
        if ($type) {
            $pre = '<sup>|_</sup> ';
            $spacer = '.      ';
        } else {
            $pre = '- ';
            $spacer = '  ';
        }
        foreach ($children[$id] as $v) {
            $id = $v->id;
            if ($v->parent_id == 0) {
                $txt = $v->title;
            } else {
                $txt = $pre . $v->title;
            }
            $list[$id] = $v;
            $list[$id]->treename = $indent . $txt;
            if (isset($children[$id]) && is_array($children[$id])) {
                $list[$id]->children = count($children[$id]);
                $list = static::treerecurse($id, $indent . $spacer, $list, $children, $maxlevel, $level + 1, $type);
            } else {
                $list[$id]->children = 0;
            }
        }
    }
    return $list;
}