Actions

API15

JTable/move

From Joomla! Documentation

< API15:JTable
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

Description

[<! removed edit link to red link >]

<! removed transcluded page call, red link never existed >

Syntax

move($dirn, $where='')
Parameter Name Default Value Description
$dirn
$where

Defined in

libraries/joomla/database/table.php

Importing

jimport( 'joomla.database.table' );

Source Body

function move( $dirn, $where='' )
{
        if (!in_array( 'ordering',  array_keys($this->getProperties())))
        {
                $this->setError( get_class( $this ).' does not support ordering' );
                return false;
        }
 
        $k = $this->_tbl_key;
 
        $sql = "SELECT $this->_tbl_key, ordering FROM $this->_tbl";
 
        if ($dirn < 0)
        {
                $sql .= ' WHERE ordering < '.(int) $this->ordering;
                $sql .= ($where ? ' AND '.$where : '');
                $sql .= ' ORDER BY ordering DESC';
        }
        else if ($dirn > 0)
        {
                $sql .= ' WHERE ordering > '.(int) $this->ordering;
                $sql .= ($where ? ' AND '. $where : '');
                $sql .= ' ORDER BY ordering';
        }
        else
        {
                $sql .= ' WHERE ordering = '.(int) $this->ordering;
                $sql .= ($where ? ' AND '.$where : '');
                $sql .= ' ORDER BY ordering';
        }
 
        $this->_db->setQuery( $sql, 0, 1 );
 
 
        $row = null;
        $row = $this->_db->loadObject();
        if (isset($row))
        {
                $query = 'UPDATE '. $this->_tbl
                . ' SET ordering = '. (int) $row->ordering
                . ' WHERE '. $this->_tbl_key .' = '. $this->_db->Quote($this->$k)
                ;
                $this->_db->setQuery( $query );
 
                if (!$this->_db->query())
                {
                        $err = $this->_db->getErrorMsg();
                        JError::raiseError( 500, $err );
                }
 
                $query = 'UPDATE '.$this->_tbl
                . ' SET ordering = '.(int) $this->ordering
                . ' WHERE '.$this->_tbl_key.' = '.$this->_db->Quote($row->$k)
                ;
                $this->_db->setQuery( $query );
 
                if (!$this->_db->query())
                {
                        $err = $this->_db->getErrorMsg();
                        JError::raiseError( 500, $err );
                }
 
                $this->ordering = $row->ordering;
        }
        else
        {
                $query = 'UPDATE '. $this->_tbl
                . ' SET ordering = '.(int) $this->ordering
                . ' WHERE '. $this->_tbl_key .' = '. $this->_db->Quote($this->$k)
                ;
                $this->_db->setQuery( $query );
 
                if (!$this->_db->query())
                {
                        $err = $this->_db->getErrorMsg();
                        JError::raiseError( 500, $err );
                }
        }
        return true;
}

[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >

Examples

<CodeExamplesForm />