JTable/reorder
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]
Compacts the ordering sequence of the selected records
[<! removed edit link to red link >]
<! removed transcluded page call, red link never existed >
Syntax[edit]
reorder($where='')
Parameter Name | Default Value | Description |
---|---|---|
$where | Additional where query to limit ordering to a particular subset of records |
Defined in[edit]
libraries/joomla/database/table.php
Importing[edit]
jimport( 'joomla.database.table' );
Source Body[edit]
function reorder( $where='' )
{
$k = $this->_tbl_key;
if (!in_array( 'ordering', array_keys($this->getProperties() ) ))
{
$this->setError( get_class( $this ).' does not support ordering');
return false;
}
if ($this->_tbl == '#__content_frontpage')
{
$order2 = ", content_id DESC";
}
else
{
$order2 = "";
}
$query = 'SELECT '.$this->_tbl_key.', ordering'
. ' FROM '. $this->_tbl
. ' WHERE ordering >= 0' . ( $where ? ' AND '. $where : '' )
. ' ORDER BY ordering'.$order2
;
$this->_db->setQuery( $query );
if (!($orders = $this->_db->loadObjectList()))
{
$this->setError($this->_db->getErrorMsg());
return false;
}
// compact the ordering numbers
for ($i=0, $n=count( $orders ); $i < $n; $i++)
{
if ($orders[$i]->ordering >= 0)
{
if ($orders[$i]->ordering != $i+1)
{
$orders[$i]->ordering = $i+1;
$query = 'UPDATE '.$this->_tbl
. ' SET ordering = '. (int) $orders[$i]->ordering
. ' WHERE '. $k .' = '. $this->_db->Quote($orders[$i]->$k)
;
$this->_db->setQuery( $query);
$this->_db->query();
}
}
}
return true;
}
[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >
Examples[edit]
Code Examples[edit]