protected function getPages(ServiceLocatorInterface $serviceLocator)
 {
     if (null === $this->pages) {
         //FETCH data from table menu :
         $fetchMenu = $serviceLocator->get('menu')->fetchAll();
         $container = new \Zend\Navigation\Navigation();
         foreach ($fetchMenu as $key => $row) {
             if (null !== $row['parent_menu_id']) {
                 continue;
             }
             $container->addPage(array('id' => $row['menu_id'], 'label' => $row['label'], 'uri' => $row['uri'], 'icon' => $row['icon']));
             $i = 0;
             $menu_items = $fetchMenu;
             foreach ($menu_items as $item_key => $item) {
                 if ($item['parent_menu_id'] === null) {
                     continue;
                 }
                 if ($row['menu_id'] === $item['parent_menu_id']) {
                     $subPage = array('id' => $item['menu_id'], 'label' => $item['label'], 'icon' => $item['icon']);
                     if (null !== $item['uri']) {
                         $subPage['uri'] = $item['uri'];
                     } else {
                         if (null !== $item['route']) {
                             $subPage['route'] = $item['route'];
                         }
                     }
                     $container->findBy('id', $row['menu_id'])->addPage($subPage);
                     $i++;
                     unset($fetchMenu[$item_key]);
                 }
             }
             if ($i === 0) {
                 if (null !== $row['uri']) {
                     $container->findBy('id', $row['menu_id'])->setUri($row['uri']);
                 } else {
                     if (null !== $row['route']) {
                         $container->findBy('id', $row['menu_id'])->setUri($row['uri']);
                     }
                 }
                 unset($fetchMenu[$key]);
             }
         }
         $this->pages = $container;
     }
     return $this->pages;
 }
示例#2
0
    public function testOptionEscapeLabelsAsFalse()
    {
        $options = array(
            'escapeLabels' => false
        );

        $container = new \Zend\Navigation\Navigation($this->_nav2->toArray());
        $container->addPage(array(
            'label' => 'Badges <span class="badge">1</span>',
            'uri' => 'badges'
        ));

        $expected = $this->_getExpected('menu/escapelabels_as_false.html');
        $actual = $this->_helper->renderMenu($container, $options);

        $this->assertEquals($expected, $actual);
    }
示例#3
0
 public function testRenderingWithPageClassToLi()
 {
     $options = array('addClassToListItem' => true);
     $container = new \Zend\Navigation\Navigation($this->_nav2->toArray());
     $container->addPage(array('label' => 'Class test', 'uri' => 'test', 'class' => 'foobar'));
     $expected = $this->_getExpected('menu/addclasstolistitem_as_true.html');
     $actual = $this->_helper->renderMenu($container, $options);
     $this->assertEquals(trim($expected), trim($actual));
 }