Actions

API15

JTable/reorder

From Joomla! Documentation

< API15:JTable
Revision as of 13:52, 12 May 2013 by JoomlaWikiBot (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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

Compacts the ordering sequence of the selected records

[<! removed edit link to red link >]

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

Syntax

reorder($where='')
Parameter Name Default Value Description
$where Additional where query to limit ordering to a particular subset of records

Defined in

libraries/joomla/database/table.php

Importing

jimport( 'joomla.database.table' );

Source Body

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

<CodeExamplesForm />