API15

JTable/move

From Joomla! Documentation

< API15:JTable
Revision as of 17:16, 22 March 2010 by Doxiki (talk | contribs) (New page: ===Description=== Description <span class="editsection" style="font-size:76%;"> <nowiki>[</nowiki>Edit Descripton<nowiki>]</nowiki> </span> {{Descripti...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

The "API15" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.

Description[edit]

Description

[Edit Descripton]

Template:Description:JTable/move

Syntax[edit]

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

Defined in[edit]

libraries/joomla/database/table.php

Importing[edit]

jimport( 'joomla.database.table' );

Source Body[edit]

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;
}

[Edit See Also] Template:SeeAlso:JTable/move

Examples[edit]

<CodeExamplesForm />