public function changePositionAction($pageId, $menuName, $newPosition)
    {
        if ($this->getRequest()->isXmlHttpRequest())
        {
            $pageMenuRepo = $this->getDoctrine()->getRepository('FulgurioLightCMSBundle:PageMenu');
            $pageMenu = $pageMenuRepo->findOneBy(array('page' => $pageId, 'label' => $menuName));
            if ($pageMenu)
            {
                if ($newPosition == $pageMenu->getPosition())
                {
                    // No change
                }
                else if ($newPosition > $pageMenu->getPosition())
                {
                    if ($newPosition <= $pageMenuRepo->getLastMenuPosition($pageMenu->getLabel()))
                    {
                        // Down !
                        $pageMenuRepo->upMenuPagesPosition($pageMenu->getLabel(), $pageMenu->getPosition() + 1, $newPosition);
                        $pageMenu->setPosition($newPosition);
                        $em = $this->getDoctrine()->getManager();
                        $em->persist($pageMenu);
                        $em->flush();
                    }
                }
                else if ($pageMenu->getPosition() > 1)
                {
                    // Up !
                    $pageMenuRepo->downMenuPagesPosition($pageMenu->getLabel(), $newPosition, $pageMenu->getPosition());
                    $pageMenu->setPosition($newPosition);
                    $em = $this->getDoctrine()->getManager();
                    $em->persist($pageMenu);
                    $em->flush();
                }
                else {
                    // doesn t happen
                }
            }
            return new Response();
        }
        throw new AccessDeniedException();
    }
public function changePositionAction($pageId, $menuName, $newPosition)
    {
        if ($this->getRequest()->isXmlHttpRequest())
        {
            $pageMenuRepo = $this->getDoctrine()->getRepository('FulgurioLightCMSBundle:PageMenu');
            $pageMenu = $pageMenuRepo->findOneBy(array('page' => $pageId, 'label' => $menuName));
            if ($pageMenu)
            {
                if ($newPosition == $pageMenu->getPosition())
                {
                    // No change
                }
                else if ($newPosition > $pageMenu->getPosition())
                {
                    if ($newPosition <= $pageMenuRepo->getLastMenuPosition($pageMenu->getLabel()))
                    {
                        // Down !
                        $pageMenuRepo->upMenuPagesPosition($pageMenu->getLabel(), $pageMenu->getPosition() + 1, $newPosition);
                        $pageMenu->setPosition($newPosition);
                        $em = $this->getDoctrine()->getManager();
                        $em->persist($pageMenu);
                        $em->flush();
                    }
                }
                else if ($pageMenu->getPosition() > 1)
                {
                    // Up !
                    $pageMenuRepo->downMenuPagesPosition($pageMenu->getLabel(), $newPosition, $pageMenu->getPosition());
                    $pageMenu->setPosition($newPosition);
                    $em = $this->getDoctrine()->getManager();
                    $em->persist($pageMenu);
                    $em->flush();
                }
                else {
                    // doesn t happen
                }
            }
            return new Response();
        }
        throw new AccessDeniedException();
    }
public function changePositionAction ( $ pageId , $ menuName , $ newPosition ) { if ( $ this -> getRequest ( ) -> isXmlHttpRequest ( ) ) { $ pageMenuRepo = $ this -> getDoctrine ( ) -> getRepository ( 'FulgurioLightCMSBundle:PageMenu' ) ; $ pageMenu = $ pageMenuRepo -> findOneBy ( array ( 'page' => $ pageId , 'label' => $ menuName ) ) ; if ( $ pageMenu ) { if ( $ newPosition == $ pageMenu -> getPosition ( ) ) { // No change } else if ( $ newPosition > $ pageMenu -> getPosition ( ) ) { if ( $ newPosition <= $ pageMenuRepo -> getLastMenuPosition ( $ pageMenu -> getLabel ( ) ) ) { // Down ! $ pageMenuRepo -> upMenuPagesPosition ( $ pageMenu -> getLabel ( ) , $ pageMenu -> getPosition ( ) + 1 , $ newPosition ) ; $ pageMenu -> setPosition ( $ newPosition ) ; $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ em -> persist ( $ pageMenu ) ; $ em -> flush ( ) ; } } else if ( $ pageMenu -> getPosition ( ) > 1 ) { // Up ! $ pageMenuRepo -> downMenuPagesPosition ( $ pageMenu -> getLabel ( ) , $ newPosition , $ pageMenu -> getPosition ( ) ) ; $ pageMenu -> setPosition ( $ newPosition ) ; $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ em -> persist ( $ pageMenu ) ; $ em -> flush ( ) ; } else { // doesn t happen } } return new Response ( ) ; } throw new AccessDeniedException ( ) ; }
Change position of page in menu, in ajax

@throws AccessDeniedException
@param number $pageId
@param string $menuName
@param number $newPosition
@return Response
Change position of page in menu in ajax