src/core/classes/org/glizycms/contents/models/proxy/MenuProxy.php
/**
     * Move a menu in a new position
     */
Move a menu in a new position
Move a menu in a new position
public function moveMenu($menuId, $position, $parentId)
    {
        $menu = org_glizy_ObjectFactory::createModel('org.glizycms.core.models.Menu');
        $menu->load($menuId);
        $isBlock = $menu->menu_type == 'BLOCK';
        $menu->menu_parentId = $parentId;
        $menu->menu_order = $position;
        $menu->save();
        $menus = org_glizy_ObjectFactory::createModelIterator('org.glizycms.core.models.Menu');
        $menus->load('getChildrenMenuInOrder', array('menuId' => $parentId, 'isBlock' => $isBlock));
        $pos = 0;
        foreach ($menus as $menu) {
            if ($menuId == $menu->menu_id) continue;
            if ($position == $pos) $pos++;
            $menu->menu_order = $pos;
            $menu->save();
            $pos++;
        }
        $this->invalidateSitemapCache();
        $evt = array('type' => org_glizycms_contents_events_Menu::MOVE, 'data' => $menuId);
        $this->dispatchEvent($evt);
    }
public function moveMenu ( $ menuId , $ position , $ parentId ) { $ menu = org_glizy_ObjectFactory :: createModel ( 'org.glizycms.core.models.Menu' ) ; $ menu -> load ( $ menuId ) ; $ isBlock = $ menu -> menu_type == 'BLOCK' ; $ menu -> menu_parentId = $ parentId ; $ menu -> menu_order = $ position ; $ menu -> save ( ) ; $ menus = org_glizy_ObjectFactory :: createModelIterator ( 'org.glizycms.core.models.Menu' ) ; $ menus -> load ( 'getChildrenMenuInOrder' , array ( 'menuId' => $ parentId , 'isBlock' => $ isBlock ) ) ; $ pos = 0 ; foreach ( $ menus as $ menu ) { if ( $ menuId == $ menu -> menu_id ) continue ; if ( $ position == $ pos ) $ pos ++ ; $ menu -> menu_order = $ pos ; $ menu -> save ( ) ; $ pos ++ ; } $ this -> invalidateSitemapCache ( ) ; $ evt = array ( 'type' => org_glizycms_contents_events_Menu :: MOVE , 'data' => $ menuId ) ; $ this -> dispatchEvent ( $ evt ) ; }
Move a menu in a new position
Move a menu in a new position
// load the menu from DB // set the parent and the order // TODO: lanciare un'eccezione se il menù non è trovato // reorder the children menus // TODO: lanciare un'eccezione se il parent trovato