SwatDB/SwatDB.php
public static function getDataTree(
        $rs,
        $title_field_name,
        $id_field_name,
        $level_field_name,
        $tree = null
    ) {
        $stack = array();
        if ($tree !== null && $tree instanceof SwatDataTreeNode) {
            $current_parent = $tree;
        } else {
            $current_parent = new SwatDataTreeNode('', Swat::_('Root'));
        }

        $base_parent = $current_parent;
        array_push($stack, $current_parent);
        $last_node = $current_parent;

        foreach ($rs as $row) {
            $title = $row->$title_field_name;
            $id = $row->$id_field_name;
            $level = $row->$level_field_name;

            if ($level > count($stack)) {
                array_push($stack, $current_parent);
                $current_parent = $last_node;
            } elseif ($level < count($stack)) {
                $current_parent = array_pop($stack);
            }

            $last_node = new SwatDataTreeNode($id, $title);
            $current_parent->addChild($last_node);
        }

        return $base_parent;
    }
public static function getDataTree(
        $rs,
        $title_field_name,
        $id_field_name,
        $level_field_name,
        $tree = null
    ) {
        $stack = array();
        if ($tree !== null && $tree instanceof SwatDataTreeNode) {
            $current_parent = $tree;
        } else {
            $current_parent = new SwatDataTreeNode('', Swat::_('Root'));
        }

        $base_parent = $current_parent;
        array_push($stack, $current_parent);
        $last_node = $current_parent;

        foreach ($rs as $row) {
            $title = $row->$title_field_name;
            $id = $row->$id_field_name;
            $level = $row->$level_field_name;

            if ($level > count($stack)) {
                array_push($stack, $current_parent);
                $current_parent = $last_node;
            } elseif ($level < count($stack)) {
                $current_parent = array_pop($stack);
            }

            $last_node = new SwatDataTreeNode($id, $title);
            $current_parent->addChild($last_node);
        }

        return $base_parent;
    }
public static function getDataTree ( $ rs , $ title_field_name , $ id_field_name , $ level_field_name , $ tree = null ) { $ stack = array ( ) ; if ( $ tree !== null && $ tree instanceof SwatDataTreeNode ) { $ current_parent = $ tree ; } else { $ current_parent = new SwatDataTreeNode ( '' , Swat :: _ ( 'Root' ) ) ; } $ base_parent = $ current_parent ; array_push ( $ stack , $ current_parent ) ; $ last_node = $ current_parent ; foreach ( $ rs as $ row ) { $ title = $ row -> $ title_field_name ; $ id = $ row -> $ id_field_name ; $ level = $ row -> $ level_field_name ; if ( $ level > count ( $ stack ) ) { array_push ( $ stack , $ current_parent ) ; $ current_parent = $ last_node ; } elseif ( $ level < count ( $ stack ) ) { $ current_parent = array_pop ( $ stack ) ; } $ last_node = new SwatDataTreeNode ( $ id , $ title ) ; $ current_parent -> addChild ( $ last_node ) ; } return $ base_parent ; }
Get a tree of data nodes

Convenience method to take a structured query with each row consisting of
an id, levelnum, and a title, and turning it into a tree of
{@link SwatDataTreeNode} objects. The returned option array in the form
of a collection of {@link SwatDataTreeNode} objects can be used by other
classes, such as {@link SwatTreeFlydown} and
{@link @SwatChecklistTree}.

@param MDB2_Driver_Common $rs The MDB2 result set, usually the result of
a stored procedure. Must be wrapped in
.       {@link SwatDBRecordsetWrapper}.
@param string $title_field_name The name of the database field
representing the title
@param string $idfield_field_name The name of the database field
representing the id
@param string $level_field_name the name of the database field
representing the tree level.
@param SwatDataTreeNode $tree an optional tree to add nodes to. If no
tree is specified, nodes are added to a new empty tree.

@return SwatDataTreeNode a tree composed of
{@link SwatDataTreeNode} objects.

@throws SwatDBException
Get a tree of data nodes