code/database/behavior/orderable.php
public function order($change)
    {
        //force to integer
        settype($change, 'int');

        if($change !== 0)
        {
            $old = (int) $this->ordering;
            $new = $this->ordering + $change;
            $new = $new <= 0 ? 1 : $new;

            $table = $this->getTable();
            $query = $this->getObject('lib:database.query.update')
                ->table($table->getBase());

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

            if($change < 0)
            {
                $query->values('ordering = ordering + 1')
                    ->where('ordering >= :new')
                    ->where('ordering <  :old')
                    ->bind(array('new' => $new, 'old' => $old));
            }
            else
            {
                $query->values('ordering = ordering - 1')
                ->where('ordering <=  :new')
                ->where('ordering > :old')
                ->bind(array('new' => $new, 'old' => $old));
            }

            $table->getDriver()->update($query);

            $this->ordering = $new;
            $this->save();
            $this->reorder();
        }

        return $this->getMixer();
    }
public function order($change)
    {
        //force to integer
        settype($change, 'int');

        if($change !== 0)
        {
            $old = (int) $this->ordering;
            $new = $this->ordering + $change;
            $new = $new <= 0 ? 1 : $new;

            $table = $this->getTable();
            $query = $this->getObject('lib:database.query.update')
                ->table($table->getBase());

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

            if($change < 0)
            {
                $query->values('ordering = ordering + 1')
                    ->where('ordering >= :new')
                    ->where('ordering <  :old')
                    ->bind(array('new' => $new, 'old' => $old));
            }
            else
            {
                $query->values('ordering = ordering - 1')
                ->where('ordering <=  :new')
                ->where('ordering > :old')
                ->bind(array('new' => $new, 'old' => $old));
            }

            $table->getDriver()->update($query);

            $this->ordering = $new;
            $this->save();
            $this->reorder();
        }

        return $this->getMixer();
    }
public function order ( $ change ) { //force to integer settype ( $ change , 'int' ) ; if ( $ change !== 0 ) { $ old = ( int ) $ this -> ordering ; $ new = $ this -> ordering + $ change ; $ new = $ new <= 0 ? 1 : $ new ; $ table = $ this -> getTable ( ) ; $ query = $ this -> getObject ( 'lib:database.query.update' ) -> table ( $ table -> getBase ( ) ) ; //Build the where query $ this -> _buildQueryWhere ( $ query ) ; if ( $ change < 0 ) { $ query -> values ( 'ordering = ordering + 1' ) -> where ( 'ordering >= :new' ) -> where ( 'ordering <  :old' ) -> bind ( array ( 'new' => $ new , 'old' => $ old ) ) ; } else { $ query -> values ( 'ordering = ordering - 1' ) -> where ( 'ordering <=  :new' ) -> where ( 'ordering > :old' ) -> bind ( array ( 'new' => $ new , 'old' => $ old ) ) ; } $ table -> getDriver ( ) -> update ( $ query ) ; $ this -> ordering = $ new ; $ this -> save ( ) ; $ this -> reorder ( ) ; } return $ this -> getMixer ( ) ; }
Move the row up or down in the ordering

Requires an 'ordering' column

@param   integer $change Amount to move up or down
@return  DatabaseRowAbstract
Move the row up or down in the ordering