protected function buildTree(array $simpleTree, $tree = [])
    {
        foreach ($simpleTree as $item) {
            if (!isset($this->collection[$item['id']])) {
                continue;
            }

            $content = $this->collection[$item['id']];

            unset($this->collection[$item['id']]); // TODO Fix multi-usage of single item

            if (isset($item['__children']) && count($item['__children'])) {
                $content['__children'] = $this->buildTree($item['__children']);
            } else {
                $content['__children'] = [];
            }

            $tree[] = $content;
        }

        return $tree;
    }
protected function buildTree(array $simpleTree, $tree = [])
    {
        foreach ($simpleTree as $item) {
            if (!isset($this->collection[$item['id']])) {
                continue;
            }

            $content = $this->collection[$item['id']];

            unset($this->collection[$item['id']]); // TODO Fix multi-usage of single item

            if (isset($item['__children']) && count($item['__children'])) {
                $content['__children'] = $this->buildTree($item['__children']);
            } else {
                $content['__children'] = [];
            }

            $tree[] = $content;
        }

        return $tree;
    }
protected function buildTree ( array $ simpleTree , $ tree = [ ] ) { foreach ( $ simpleTree as $ item ) { if ( ! isset ( $ this -> collection [ $ item [ 'id' ] ] ) ) { continue ; } $ content = $ this -> collection [ $ item [ 'id' ] ] ; unset ( $ this -> collection [ $ item [ 'id' ] ] ) ; // TODO Fix multi-usage of single item if ( isset ( $ item [ '__children' ] ) && count ( $ item [ '__children' ] ) ) { $ content [ '__children' ] = $ this -> buildTree ( $ item [ '__children' ] ) ; } else { $ content [ '__children' ] = [ ] ; } $ tree [ ] = $ content ; } return $ tree ; }
Build the tree from the simpletree and the collection

@param array $simpleTree
@param array $tree
@return array
Build the tree from the simpletree and the collection