JTable/move
From Joomla! Documentation
< API15:JTable
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
[<! removed edit link to red link >]
<! removed transcluded page call, red link never existed >
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;
}
[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >
Examples[edit]
Code Examples[edit]