private function updatePageMenuPosition(Page $page)
    {
        $pageMenuRepository = $this->doctrine->getRepository('FulgurioLightCMSBundle:PageMenu');
        $em = $this->doctrine->getManager();
        $data = $this->request->get('page');
        if (isset($data['availableMenu']))
        {
            if (!is_null($page->getId()))
            {
                $menus = $page->getMenu();
                $alreadyInMenu = array();
                foreach ($menus as $menu)
                {
                    if (!in_array($menu->getLabel(), $data['availableMenu']))
                    {
                        $pageMenuRepository->upMenuPagesPosition($menu->getLabel(), $menu->getPosition() + 1);
                        $em->remove($menu);
                    }
                    else
                    {
                        $alreadyInMenu[] = $menu->getLabel();
                    }
                }
            }
            foreach ($data['availableMenu'] as $menuLabel)
            {
                // If it s a new page, or if it a page which we had a new menu
                if (!isset($alreadyInMenu) || !in_array($menuLabel, $alreadyInMenu))
                {
                    $menu = new PageMenu();
                    $menu->setPosition($pageMenuRepository->getNextMenuPosition($menuLabel));
                    $menu->setLabel($menuLabel);
                    $menu->setPage($page);
                    $em->persist($menu);
                }
            }
        }
        else if (!is_null($page->getId()))
        {
            $menus = $page->getMenu();
            foreach ($menus as $menu)
            {
                $pageMenuRepository->upMenuPagesPosition($menu->getLabel(), $menu->getPosition() + 1);
                $em->remove($menu);
            }
        }
    }
private function updatePageMenuPosition(Page $page)
    {
        $pageMenuRepository = $this->doctrine->getRepository('FulgurioLightCMSBundle:PageMenu');
        $em = $this->doctrine->getManager();
        $data = $this->request->get('page');
        if (isset($data['availableMenu']))
        {
            if (!is_null($page->getId()))
            {
                $menus = $page->getMenu();
                $alreadyInMenu = array();
                foreach ($menus as $menu)
                {
                    if (!in_array($menu->getLabel(), $data['availableMenu']))
                    {
                        $pageMenuRepository->upMenuPagesPosition($menu->getLabel(), $menu->getPosition() + 1);
                        $em->remove($menu);
                    }
                    else
                    {
                        $alreadyInMenu[] = $menu->getLabel();
                    }
                }
            }
            foreach ($data['availableMenu'] as $menuLabel)
            {
                // If it s a new page, or if it a page which we had a new menu
                if (!isset($alreadyInMenu) || !in_array($menuLabel, $alreadyInMenu))
                {
                    $menu = new PageMenu();
                    $menu->setPosition($pageMenuRepository->getNextMenuPosition($menuLabel));
                    $menu->setLabel($menuLabel);
                    $menu->setPage($page);
                    $em->persist($menu);
                }
            }
        }
        else if (!is_null($page->getId()))
        {
            $menus = $page->getMenu();
            foreach ($menus as $menu)
            {
                $pageMenuRepository->upMenuPagesPosition($menu->getLabel(), $menu->getPosition() + 1);
                $em->remove($menu);
            }
        }
    }
private function updatePageMenuPosition ( Page $ page ) { $ pageMenuRepository = $ this -> doctrine -> getRepository ( 'FulgurioLightCMSBundle:PageMenu' ) ; $ em = $ this -> doctrine -> getManager ( ) ; $ data = $ this -> request -> get ( 'page' ) ; if ( isset ( $ data [ 'availableMenu' ] ) ) { if ( ! is_null ( $ page -> getId ( ) ) ) { $ menus = $ page -> getMenu ( ) ; $ alreadyInMenu = array ( ) ; foreach ( $ menus as $ menu ) { if ( ! in_array ( $ menu -> getLabel ( ) , $ data [ 'availableMenu' ] ) ) { $ pageMenuRepository -> upMenuPagesPosition ( $ menu -> getLabel ( ) , $ menu -> getPosition ( ) + 1 ) ; $ em -> remove ( $ menu ) ; } else { $ alreadyInMenu [ ] = $ menu -> getLabel ( ) ; } } } foreach ( $ data [ 'availableMenu' ] as $ menuLabel ) { // If it s a new page, or if it a page which we had a new menu if ( ! isset ( $ alreadyInMenu ) || ! in_array ( $ menuLabel , $ alreadyInMenu ) ) { $ menu = new PageMenu ( ) ; $ menu -> setPosition ( $ pageMenuRepository -> getNextMenuPosition ( $ menuLabel ) ) ; $ menu -> setLabel ( $ menuLabel ) ; $ menu -> setPage ( $ page ) ; $ em -> persist ( $ menu ) ; } } } else if ( ! is_null ( $ page -> getId ( ) ) ) { $ menus = $ page -> getMenu ( ) ; foreach ( $ menus as $ menu ) { $ pageMenuRepository -> upMenuPagesPosition ( $ menu -> getLabel ( ) , $ menu -> getPosition ( ) + 1 ) ; $ em -> remove ( $ menu ) ; } } }
Update page menu position

@param Page $page
Update page menu position