Actions

API16

JTableNested/orderDown

From Joomla! Documentation

< API16:JTableNested
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 move a node one position to the right in the same level.

[Edit Descripton]

Description:JTableNested/orderDown

Syntax

orderDown($pk)
Parameter Name Default Value Description
$pk Primary key of the node to move.

Returns

boolean True on success.

Defined in

libraries/joomla/database/tablenested.php

Importing

jimport( 'joomla.database.tablenested' );

Source Body

public function orderDown($pk)
{
        // Initialise variables.
        $k = $this->_tbl_key;
        $pk = (is_null($pk)) ? $this->$k : $pk;
 
        // Lock the table for writing.
        if (!$this->_lock()) {
                // Error message set in lock method.
                return false;
        }
 
        // Get the node by primary key.
        if (!$node = $this->_getNode($pk)) {
                // Error message set in getNode method.
                $this->_unlock();
                return false;
        }
 
        // Get the right sibling node.
        if (!$sibling = $this->_getNode($node->rgt + 1, 'left')) {
                // Error message set in getNode method.
                $this->_unlock();
                return false;
        }
 
        // Get the primary keys of child nodes.
        $this->_db->setQuery(
                'SELECT `'.$this->_tbl_key.'`' .
                ' FROM `'.$this->_tbl.'`' .
                ' WHERE `lft` BETWEEN '.(int) $node->lft.' AND '.(int) $node->rgt
        );
        $children = $this->_db->loadResultArray();
 
        // Check for a database error.
        if ($this->_db->getErrorNum()) {
                $this->setError($this->_db->getErrorMsg());
                $this->_unlock();
                return false;
        }
 
        // Shift left and right values for the node and it's children.
        $this->_db->setQuery(
                'UPDATE `'.$this->_tbl.'`' .
                ' SET `lft` = `lft` + '.(int) $sibling->width.', `rgt` = `rgt` + '.(int) $sibling->width.'' .
                ' WHERE `lft` BETWEEN '.(int) $node->lft.' AND '.(int) $node->rgt
        );
        $this->_db->query();
 
        // Check for a database error.
        if ($this->_db->getErrorNum()) {
                $this->setError($this->_db->getErrorMsg());
                $this->_unlock();
                return false;
        }
 
        // Shift left and right values for the sibling and it's children.
        $this->_db->setQuery(
                'UPDATE `'.$this->_tbl.'`' .
                ' SET `lft` = `lft` - '.(int) $node->width.', `rgt` = `rgt` - '.(int) $node->width .
                ' WHERE `lft` BETWEEN '.(int) $sibling->lft.' AND '.(int) $sibling->rgt .
                ' AND `'.$this->_tbl_key.'` NOT IN ('.implode(',', $children).')'
        );
        $this->_db->query();
 
        // Check for a database error.
        if ($this->_db->getErrorNum()) {
                $this->setError($this->_db->getErrorMsg());
                $this->_unlock();
                return false;
        }
 
        // Unlock the table for writing.
        $this->_unlock();
 
        return true;
}

[Edit See Also] SeeAlso:JTableNested/orderDown

Examples

<CodeExamplesForm />