public function changeAbsolutePosition($newPosition)
    {
        // The current position
        $current_position = $this->getPosition();

        if ($newPosition != null && $newPosition > 0 && $newPosition != $current_position) {
            // Find categories to offset
            $search = $this->createQuery();

            $this->addCriteriaToPositionQuery($search);

            if ($newPosition > $current_position) {
                // The new position is after the current position -> we will offset + 1 all categories located between us and the new position
                $search->filterByPosition(array('min' => 1+$current_position, 'max' => $newPosition));

                $delta = -1;
            } else {
                // The new position is brefore the current position -> we will offset - 1 all categories located between us and the new position
                $search->filterByPosition(array('min' => $newPosition, 'max' => $current_position - 1));

                $delta = 1;
            }

            $results = $search->find();

            $cnx = Propel::getWriteConnection($this->getDatabaseName());

            $cnx->beginTransaction();

            try {
                foreach ($results as $result) {
                    $objNewPosition = $result->getPosition() + $delta;

                    // For BC
                    if (method_exists($result, 'setDispatcher') && method_exists($this, 'getDispatcher')) {
                        $result->setDispatcher($this->getDispatcher());
                    }

                    $result->setPosition($objNewPosition)->save($cnx);
                }

                $this
                    ->setPosition($newPosition)
                    ->save($cnx)
                ;

                $cnx->commit();
            } catch (\Exception $e) {
                $cnx->rollback();
            }
        }
    }
public function changeAbsolutePosition($newPosition)
    {
        // The current position
        $current_position = $this->getPosition();

        if ($newPosition != null && $newPosition > 0 && $newPosition != $current_position) {
            // Find categories to offset
            $search = $this->createQuery();

            $this->addCriteriaToPositionQuery($search);

            if ($newPosition > $current_position) {
                // The new position is after the current position -> we will offset + 1 all categories located between us and the new position
                $search->filterByPosition(array('min' => 1+$current_position, 'max' => $newPosition));

                $delta = -1;
            } else {
                // The new position is brefore the current position -> we will offset - 1 all categories located between us and the new position
                $search->filterByPosition(array('min' => $newPosition, 'max' => $current_position - 1));

                $delta = 1;
            }

            $results = $search->find();

            $cnx = Propel::getWriteConnection($this->getDatabaseName());

            $cnx->beginTransaction();

            try {
                foreach ($results as $result) {
                    $objNewPosition = $result->getPosition() + $delta;

                    // For BC
                    if (method_exists($result, 'setDispatcher') && method_exists($this, 'getDispatcher')) {
                        $result->setDispatcher($this->getDispatcher());
                    }

                    $result->setPosition($objNewPosition)->save($cnx);
                }

                $this
                    ->setPosition($newPosition)
                    ->save($cnx)
                ;

                $cnx->commit();
            } catch (\Exception $e) {
                $cnx->rollback();
            }
        }
    }
public function changeAbsolutePosition ( $ newPosition ) { // The current position $ current_position = $ this -> getPosition ( ) ; if ( $ newPosition != null && $ newPosition > 0 && $ newPosition != $ current_position ) { // Find categories to offset $ search = $ this -> createQuery ( ) ; $ this -> addCriteriaToPositionQuery ( $ search ) ; if ( $ newPosition > $ current_position ) { // The new position is after the current position -> we will offset + 1 all categories located between us and the new position $ search -> filterByPosition ( array ( 'min' => 1 + $ current_position , 'max' => $ newPosition ) ) ; $ delta = - 1 ; } else { // The new position is brefore the current position -> we will offset - 1 all categories located between us and the new position $ search -> filterByPosition ( array ( 'min' => $ newPosition , 'max' => $ current_position - 1 ) ) ; $ delta = 1 ; } $ results = $ search -> find ( ) ; $ cnx = Propel :: getWriteConnection ( $ this -> getDatabaseName ( ) ) ; $ cnx -> beginTransaction ( ) ; try { foreach ( $ results as $ result ) { $ objNewPosition = $ result -> getPosition ( ) + $ delta ; // For BC if ( method_exists ( $ result , 'setDispatcher' ) && method_exists ( $ this , 'getDispatcher' ) ) { $ result -> setDispatcher ( $ this -> getDispatcher ( ) ) ; } $ result -> setPosition ( $ objNewPosition ) -> save ( $ cnx ) ; } $ this -> setPosition ( $ newPosition ) -> save ( $ cnx ) ; $ cnx -> commit ( ) ; } catch ( \ Exception $ e ) { $ cnx -> rollback ( ) ; } } }
Changes object position

@param newPosition
Changes object position