english/libraries/joomla/database/table/usergroup.php
/**
	 * Method to recursively rebuild the nested set tree.
	 *
	 * @param   integer  $parent_id  The root of the tree to rebuild.
	 * @param   integer  $left       The left id to start with in building the tree.
	 *
	 * @return  boolean  True on success
	 *
	 * @since   11.1
	 */
Method to recursively rebuild the nested set tree.
@param   integer  $parent_id  The root of the tree to rebuild.
@param   integer  $left       The left id to start with in building the tree.

@return  boolean  True on success


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