Context/TreeContext.php
private function buildTree(array $rows, $parent = null)
    {
        $tree = [];

        foreach ($rows as &$row) {
            if ($row['parent'] == $parent) {
                $hasChildren        = $this->propertyAccessor->getValue($row, "[{$this->options['children_column']}]");
                $row['hasChildren'] = (bool)($hasChildren > 0);
                $row['children']    = $this->buildTree($rows, $row['id']);
                $tree[]             = $row;
            }
        }

        return $tree;
    }
private function buildTree(array $rows, $parent = null)
    {
        $tree = [];

        foreach ($rows as &$row) {
            if ($row['parent'] == $parent) {
                $hasChildren        = $this->propertyAccessor->getValue($row, "[{$this->options['children_column']}]");
                $row['hasChildren'] = (bool)($hasChildren > 0);
                $row['children']    = $this->buildTree($rows, $row['id']);
                $tree[]             = $row;
            }
        }

        return $tree;
    }
private function buildTree ( array $ rows , $ parent = null ) { $ tree = [ ] ; foreach ( $ rows as & $ row ) { if ( $ row [ 'parent' ] == $ parent ) { $ hasChildren = $ this -> propertyAccessor -> getValue ( $ row , "[{$this->options['children_column']}]" ) ; $ row [ 'hasChildren' ] = ( bool ) ( $ hasChildren > 0 ) ; $ row [ 'children' ] = $ this -> buildTree ( $ rows , $ row [ 'id' ] ) ; $ tree [ ] = $ row ; } } return $ tree ; }
Creates nested tree structure from result rows

@param array $rows
@param null  $parent

@return array
Creates nested tree structure from result rows