Actions

API16

JTableUsergroup/rebuild

From Joomla! Documentation

< API16:JTableUsergroup
Revision as of 17:43, 22 March 2010 by Doxiki (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Replacement filing cabinet.png
This Namespace has been archived - Please Do Not Edit or Create Pages in this namespace. Pages contain information for a Joomla! version which is no longer supported. It exists only as a historical reference, will not be improved and its content may be incomplete.

Contents

Description

Method to recursively rebuild the nested set tree.

[Edit Descripton]

Description:JTableUsergroup/rebuild

Syntax

rebuild($parent_id=0, $left=0)
Parameter Name Default Value Description
$parent_id 0 The root of the tree to rebuild.
$left 0 The left id to start with in building the tree.

Returns

boolean True on success

Defined in

libraries/joomla/database/table/usergroup.php

Importing

jimport( 'joomla.database.table.usergroup' );

Source Body

function rebuild($parent_id = 0, $left = 0)
{
        // get the database object
        $db = &$this->_db;
 
        // get all children of this node
        $db->setQuery(
                'SELECT id FROM '. $this->_tbl .
                ' WHERE parent_id='. (int)$parent_id .
                ' ORDER BY parent_id, title'
        );
        $children = $db->loadResultArray();
 
        // the right value of this node is the left value + 1
        $right = $left + 1;
 
        // execute this function recursively over all children
        for ($i=0,$n=count($children); $i < $n; $i++)
        {
                // $right is the current right value, which is incremented on recursion return
                $right = $this->rebuild($children[$i], $right);
 
                // if there is an update failure, return false to break out of the recursion
                if ($right === false) {
                        return false;
                }
        }
 
        // we've got the left value, and now that we've processed
        // the children of this node we also know the right value
        $db->setQuery(
                'UPDATE '. $this->_tbl .
                ' SET lft='. (int)$left .', rgt='. (int)$right .
                ' WHERE id='. (int)$parent_id
        );
        // if there is an update failure, return false to break out of the recursion
        if (!$db->query()) {
                return false;
        }
 
        // return the right value of this node + 1
        return $right + 1;
}

[Edit See Also] SeeAlso:JTableUsergroup/rebuild

Examples

<CodeExamplesForm />