protected function movePositionUpOrDown($up = true)
    {
        // The current position of the object
        $myPosition = $this->getPosition();

        // Find object to exchange position with
        $search = $this->createQuery();

        $this->addCriteriaToPositionQuery($search);

        // Up or down ?
        if ($up === true) {
            // Find the object immediately before me
            $search->filterByPosition(array('max' => $myPosition-1))->orderByPosition(Criteria::DESC);
        } else {
            // Find the object immediately after me
            $search->filterByPosition(array('min' => $myPosition+1))->orderByPosition(Criteria::ASC);
        }

        $result = $search->findOne();

        // If we found the proper object, exchange their positions
        if ($result) {
            $cnx = Propel::getWriteConnection($this->getDatabaseName());

            $cnx->beginTransaction();

            try {
                $this
                    ->setPosition($result->getPosition())
                    ->save($cnx)
                ;

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

                $result->setPosition($myPosition)->save($cnx);

                $cnx->commit();
            } catch (\Exception $e) {
                $cnx->rollback();
            }
        }
    }
protected function movePositionUpOrDown($up = true)
    {
        // The current position of the object
        $myPosition = $this->getPosition();

        // Find object to exchange position with
        $search = $this->createQuery();

        $this->addCriteriaToPositionQuery($search);

        // Up or down ?
        if ($up === true) {
            // Find the object immediately before me
            $search->filterByPosition(array('max' => $myPosition-1))->orderByPosition(Criteria::DESC);
        } else {
            // Find the object immediately after me
            $search->filterByPosition(array('min' => $myPosition+1))->orderByPosition(Criteria::ASC);
        }

        $result = $search->findOne();

        // If we found the proper object, exchange their positions
        if ($result) {
            $cnx = Propel::getWriteConnection($this->getDatabaseName());

            $cnx->beginTransaction();

            try {
                $this
                    ->setPosition($result->getPosition())
                    ->save($cnx)
                ;

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

                $result->setPosition($myPosition)->save($cnx);

                $cnx->commit();
            } catch (\Exception $e) {
                $cnx->rollback();
            }
        }
    }
protected function movePositionUpOrDown ( $ up = true ) { // The current position of the object $ myPosition = $ this -> getPosition ( ) ; // Find object to exchange position with $ search = $ this -> createQuery ( ) ; $ this -> addCriteriaToPositionQuery ( $ search ) ; // Up or down ? if ( $ up === true ) { // Find the object immediately before me $ search -> filterByPosition ( array ( 'max' => $ myPosition - 1 ) ) -> orderByPosition ( Criteria :: DESC ) ; } else { // Find the object immediately after me $ search -> filterByPosition ( array ( 'min' => $ myPosition + 1 ) ) -> orderByPosition ( Criteria :: ASC ) ; } $ result = $ search -> findOne ( ) ; // If we found the proper object, exchange their positions if ( $ result ) { $ cnx = Propel :: getWriteConnection ( $ this -> getDatabaseName ( ) ) ; $ cnx -> beginTransaction ( ) ; try { $ this -> setPosition ( $ result -> getPosition ( ) ) -> save ( $ cnx ) ; // For BC if ( method_exists ( $ result , 'setDispatcher' ) && method_exists ( $ this , 'getDispatcher' ) ) { $ result -> setDispatcher ( $ this -> getDispatcher ( ) ) ; } $ result -> setPosition ( $ myPosition ) -> save ( $ cnx ) ; $ cnx -> commit ( ) ; } catch ( \ Exception $ e ) { $ cnx -> rollback ( ) ; } } }
Move up or down a object

@param bool $up the exchange mode: go up (POSITION_UP) or go down (POSITION_DOWN)
Move up or down a object