code/database/behavior/orderable.php
public function reorder($base = 0)
    {
        //force to integer
        settype($base, 'int');

        $table  = $this->getTable();
        $db     = $table->getDriver();
        $db->execute('SET @order = '.$base);

        $query = $this->getObject('lib:database.query.update')
            ->table($table->getBase())
            ->values('ordering = (@order := @order + 1)')
            ->order('ordering', 'ASC');

        //Build the where query
        $this->_buildQueryWhere($query);

        if ($base) {
            $query->where('ordering >= :ordering')->bind(array(':ordering' => $base));
        }

        $db->update($query);

        return $this;
    }
public function reorder($base = 0)
    {
        //force to integer
        settype($base, 'int');

        $table  = $this->getTable();
        $db     = $table->getDriver();
        $db->execute('SET @order = '.$base);

        $query = $this->getObject('lib:database.query.update')
            ->table($table->getBase())
            ->values('ordering = (@order := @order + 1)')
            ->order('ordering', 'ASC');

        //Build the where query
        $this->_buildQueryWhere($query);

        if ($base) {
            $query->where('ordering >= :ordering')->bind(array(':ordering' => $base));
        }

        $db->update($query);

        return $this;
    }
public function reorder ( $ base = 0 ) { //force to integer settype ( $ base , 'int' ) ; $ table = $ this -> getTable ( ) ; $ db = $ table -> getDriver ( ) ; $ db -> execute ( 'SET @order = ' . $ base ) ; $ query = $ this -> getObject ( 'lib:database.query.update' ) -> table ( $ table -> getBase ( ) ) -> values ( 'ordering = (@order := @order + 1)' ) -> order ( 'ordering' , 'ASC' ) ; //Build the where query $ this -> _buildQueryWhere ( $ query ) ; if ( $ base ) { $ query -> where ( 'ordering >= :ordering' ) -> bind ( array ( ':ordering' => $ base ) ) ; } $ db -> update ( $ query ) ; return $ this ; }
Resets the order of all rows

Resetting starts at $base to allow creating space in sequence for later record insertion.

@param   integer $base Order at which to start resetting.
@return  DatabaseBehaviorOrderable
Resets the order of all rows