src/Titon/Db/Behavior/HierarchyBehavior.php
protected function _reOrder($parent_id, $left, array $order = []) {
        $parent = $this->getConfig('parentField');
        $repo = $this->getRepository();
        $pk = $repo->getPrimaryKey();
        $right = $left + 1;

        // Get children and sort
        $children = $repo->select()
            ->where($parent, $parent_id)
            ->orderBy($order)
            ->all();

        foreach ($children as $child) {
            $right = $this->_reOrder($child[$pk], $right, $order);
        }

        // Update parent node
        if ($parent_id) {
            $this->_moveNode(function(Query $query) use ($pk, $parent_id) {
                $query->where($pk, $parent_id);
            }, [
                $this->getConfig('leftField') => $left,
                $this->getConfig('rightField') => $right
            ]);
        }

        return $right + 1;
    }
protected function _reOrder($parent_id, $left, array $order = []) {
        $parent = $this->getConfig('parentField');
        $repo = $this->getRepository();
        $pk = $repo->getPrimaryKey();
        $right = $left + 1;

        // Get children and sort
        $children = $repo->select()
            ->where($parent, $parent_id)
            ->orderBy($order)
            ->all();

        foreach ($children as $child) {
            $right = $this->_reOrder($child[$pk], $right, $order);
        }

        // Update parent node
        if ($parent_id) {
            $this->_moveNode(function(Query $query) use ($pk, $parent_id) {
                $query->where($pk, $parent_id);
            }, [
                $this->getConfig('leftField') => $left,
                $this->getConfig('rightField') => $right
            ]);
        }

        return $right + 1;
    }
protected function _reOrder ( $ parent_id , $ left , array $ order = [ ] ) { $ parent = $ this -> getConfig ( 'parentField' ) ; $ repo = $ this -> getRepository ( ) ; $ pk = $ repo -> getPrimaryKey ( ) ; $ right = $ left + 1 ; // Get children and sort $ children = $ repo -> select ( ) -> where ( $ parent , $ parent_id ) -> orderBy ( $ order ) -> all ( ) ; foreach ( $ children as $ child ) { $ right = $ this -> _reOrder ( $ child [ $ pk ] , $ right , $ order ) ; } // Update parent node if ( $ parent_id ) { $ this -> _moveNode ( function ( Query $ query ) use ( $ pk , $ parent_id ) { $ query -> where ( $ pk , $ parent_id ) ; } , [ $ this -> getConfig ( 'leftField' ) => $ left , $ this -> getConfig ( 'rightField' ) => $ right ] ) ; } return $ right + 1 ; }
Re-order the tree by recursively looping through all parents and children,
ordering the results, and generating the correct left and right indexes.

@param int $parent_id
@param int $left
@param array $order
@return int
Re - order the tree by recursively looping through all parents and children ordering the results and generating the correct left and right indexes .