/**
  * Find root menu items by menu
  *
  * @param Menu $menu
  * @param array $criteria
  * @param array $orderBy
  * @return array
  */
 public function findRootMenuItemsByMenu(Menu $menu, array $criteria = null, array $orderBy = null)
 {
     $qb = $this->createQueryBuilder('mi');
     $qb->select('mi, c, ci')->where('mi.menu = :menu')->andWhere('mi.parent IS NULL')->leftJoin('mi.children', 'c')->leftJoin('c.children', 'ci')->orderBy('mi.weight', 'ASC')->addOrderBy('mi.lft', 'ASC')->addOrderBy('mi.id', 'ASC');
     $qb->setParameter('menu', $menu->getName());
     $this->setQueryBuilderOptions($qb, $criteria, $orderBy);
     $query = $qb->getQuery();
     return $query->getResult();
 }
Beispiel #2
0
 /**
  * Load
  *
  * @param ObjectManager $manager
  */
 public function load(ObjectManager $manager)
 {
     $menuManager = $this->container->get('zym_menu.menu_manager');
     $menuFactory = $this->container->get('knp_menu.factory');
     $menuItemManager = $this->container->get('zym_menu.menu_item_manager');
     // Main Menu
     $menu = new Entity\Menu();
     $menu->setName('main');
     $menu->setLabel('Main Menu');
     $menu->setDescription('The Main menu\'s links drive the main navigation structure for your site, and are often displayed prominently across the top or side of the site.');
     $menuManager->createMenu($menu);
     $menuItem = new Entity\MenuItem\StaticMenuItem('home', $menuFactory);
     $menuItem->setLabel('Home');
     $menuItem->setUri('/');
     $menu->addChild($menuItem);
     $menuItemManager->createMenuItem($menuItem);
     // Management Menu
     $menu = new Entity\Menu();
     $menu->setName('management');
     $menu->setLabel('Management Menu');
     $menu->setDescription('The Management menu contains links for administrative tasks.');
     $menuManager->createMenu($menu);
     $menuItem = new Entity\MenuItem\StaticMenuItem('home', $menuFactory);
     $menuItem->setLabel('Home');
     $menuItem->setUri('/');
     $menu->addChild($menuItem);
     $menuItemManager->createMenuItem($menuItem);
     $menuItem = new Entity\MenuItem\SectionMenuItem('reports', $menuFactory);
     $menuItem->setLabel('Reports');
     $menuItem->setDescription('Manage the reporting application.');
     $menuItem->setWeight(80);
     $menuItem->setUri('admin/reports');
     $menu->addChild($menuItem);
     $menuItemManager->createMenuItem($menuItem);
     $menuItem = new Entity\MenuItem\SectionMenuItem('structure', $menuFactory);
     $menuItem->setLabel('Structure');
     $menuItem->setDescription('Manage the structure for application.');
     $menuItem->setWeight(100);
     $menuItem->setUri('admin/structure');
     $menu->addChild($menuItem);
     $menuItemManager->createMenuItem($menuItem);
     $cMenuItem = new Entity\MenuItem\RoutedMenuItem('menus', $menuFactory);
     $cMenuItem->setLabel('Menus');
     $cMenuItem->setDescription('Manage the structure of menus.');
     $cMenuItem->setRoute('zym_menus');
     $cMenuItem->setWeight(30);
     $menuItem->addChild($cMenuItem);
     $menuItemManager->createMenuItem($cMenuItem);
     $menuItem = new Entity\MenuItem\SectionMenuItem('configuration', $menuFactory);
     $menuItem->setLabel('Configuration');
     $menuItem->setDescription('Manage the configuration for the application.');
     $menuItem->setWeight(500);
     $menuItem->setUri('admin/config');
     $menu->addChild($menuItem);
     $menuItemManager->createMenuItem($menuItem);
     $cMenuItem = new Entity\MenuItem\StaticMenuItem('security', $menuFactory);
     $cMenuItem->setLabel('Security');
     $cMenuItem->setDescription('Manage the security for the application.');
     $cMenuItem->setUri('/');
     $cMenuItem->setWeight(70);
     $menuItem->addChild($cMenuItem);
     $menuItemManager->createMenuItem($cMenuItem);
     $cMenuItem = new Entity\MenuItem\StaticMenuItem('system', $menuFactory);
     $cMenuItem->setLabel('System');
     $cMenuItem->setDescription('Manage the system settings for the application.');
     $cMenuItem->setUri('/');
     $cMenuItem->setWeight(80);
     $menuItem->addChild($cMenuItem);
     $menuItemManager->createMenuItem($cMenuItem);
     $menuManager->saveMenu($menu);
     $manager->flush();
 }
Beispiel #3
0
 /**
  * Add a menu item
  *
  * @param Entity\Menu $menu
  *
  * @Route(
  *     "/{id}/add/{type}",
  *     name     = "zym_menus_item_add",
  *     defaults = {
  *         "type" = null
  *     }
  * )
  * @ParamConverter("menu", class="ZymMenuBundle:Menu")
  * @Template()
  *
  * @SecureParam(name="menu", permissions="EDIT")
  */
 public function addMenuItemAction(Entity\Menu $menu, $type = null)
 {
     $securityContext = $this->get('security.context');
     // check for create access
     if (!$securityContext->isGranted('CREATE', new ObjectIdentity('class', 'Zym\\Bundle\\MenuBundle\\Entity\\MenuItem'))) {
         throw new \Symfony\Component\Security\Core\Exception\AccessDeniedException();
     }
     if ($type) {
         switch ($type) {
             case 'routed':
                 $menuItem = new Entity\MenuItem\RoutedMenuItem(null, $this->get('knp_menu.factory'), $menu);
                 $menuItem->setRouter($this->get('router'));
                 $form = $this->createForm(new Form\MenuItem\RoutedMenuItemType(), $menuItem);
                 break;
             case 'static':
                 $menuItem = new Entity\MenuItem\StaticMenuItem(null, $this->get('knp_menu.factory'), $menu);
                 $form = $this->createForm(new Form\MenuItem\StaticMenuItemType(), $menuItem);
                 break;
             case 'section':
                 $menuItem = new Entity\MenuItem\SectionMenuItem(null, $this->get('knp_menu.factory'), $menu);
                 $form = $this->createForm(new Form\MenuItem\SectionMenuItemType(), $menuItem);
                 break;
             default:
                 throw $this->createNotFoundException('Invalid MenuItem Type');
         }
         $request = $this->get('request');
         if ($request->getMethod() == 'POST') {
             $form->bind($request);
             if ($form->isValid()) {
                 $menuItemManager = $this->get('zym_menu.menu_item_manager');
                 $menuItemManager->createMenuItem($menuItem);
                 return $this->redirect($this->generateUrl('zym_menus_show', array('id' => $menu->getName())));
             }
         }
         return array('menu' => $menu, 'form' => $form->createView(), 'type' => $type);
     }
 }