/** * populate * * Populate the the navigation container with the provided * data. This will be recursivly added to the container * * @param \Zend_Navigation_Container $navigation The navigation container * @param mixed(array|ArrayCollection) $data The children to add * @return \Zend_Navigation_Container */ protected function populate(\Zend_Navigation_Container $navigation, $data) { foreach ($data as $page) { $mvc = new \Zend_Navigation_Page_Mvc(array('label' => $page->getTitle(), 'module' => $page->getModule(), 'controller' => $page->getController(), 'action' => $page->getAction(), 'route' => $page->getRoute())); if ($page->hasChildren()) { $this->populate($mvc, $page->getChildren()); } $navigation->addPage($mvc); } return $navigation; }
public function renderMenu(Zend_Navigation_Container $container, $options = array()) { $html = ''; $pages = $container->getPages(); foreach ($pages as $page) { /* @var $page Zend_Navigation_Page */ if ($this->acl && $page->getResource()) { if (!$this->acl->hasPermission($page->getResource(), $page->getPrivilege())) { continue; } } if ($page->isActive()) { $this->activePageId = $this->getId($page); } if (!$page->isVisible(true)) { continue; } if (!$page->getHref()) { continue; } $subMenu = $this->renderSubMenu($page); $class = $subMenu ? 'folder' : ''; if (!($page->hasChildren() && !$subMenu)) { $html .= sprintf('<li><div class="menu-glyph"%s><div class="menu-glyph-delimeter"><a id="%s" href="%s" class="%s">%s</a></div></div>%s</li>', $this->getInlineStyle($page->getId()), 'menu-' . $this->getId($page), $page->hasChildren() ? 'javascript:;' : $page->getHref(), $class . " " . $page->getClass(), $this->view->escape($page->getLabel()), $subMenu); } } $script = ''; if ($this->activePageId) { $script = <<<CUT <script type="text/javascript"> \$(function(){ \$('.admin-menu').adminMenu('{$this->activePageId}'); }); </script> CUT; } return sprintf('<ul class="admin-menu">%s</ul>%s%s', $html, "\n", $script); }
/** * Strategy pattern: Initialize the configuration. * * It adds pages from the configuration file to registered navigation container, * otherwise register a new one and it adds the pages to this. * * See {@link \Zend_Navigation_Container} * See {@link \Zend_Application_Bootstrap_BootstrapAbstract} * See {@link \Zend_Application_Resource_Navigation} * See getContainer() from {@link \Zend_View_Helper_Navigation_HelperAbstract} * * @param Zend_Controller_Request_Abstract $request Request to process (in this * configuration is not used) */ public function init(\Zend_Controller_Request_Abstract $request) { if ($this->_getBootstrap()->hasResource('navigation')) { $navigation = $this->_getBootstrap()->getResource('navigation'); } else { if (\Zend_Registry::isRegistered('Zend_Navigation') && \Zend_Registry::get('Zend_Navigation') instanceof \Zend_Navigation_Container) { // This is the default container used by view if it didn't has a defined container $navigation = \Zend_Registry::get('Zend_Navigation'); } else { // There is not registered \Zend_Navigation_Containter; we are going // to register one through the bootstrap $navigation = new \Zend_Navigation_Container(); $this->_getBootstrap()->getContainer()->{'navigation'} = $navigation; } } // If the configuraiton file defines a new navigation structure, then // replaces old structure if (!$this->_complementaryPages) { $navigation->removePages(); } if (isset($this->_file)) { $navigation->addPages(\ifc\util\zend\Config::loadConfigFile($this->_file['path'], $this->_file['section'])); } }
/** * Returns an array representation of the page * * @return array associative array containing all page properties */ public function toArray() { return array_merge($this->getCustomProperties(), array('label' => $this->getlabel(), 'fragment' => $this->getFragment(), 'id' => $this->getId(), 'class' => $this->getClass(), 'title' => $this->getTitle(), 'target' => $this->getTarget(), 'accesskey' => $this->getAccesskey(), 'rel' => $this->getRel(), 'rev' => $this->getRev(), 'customHtmlAttribs' => $this->getCustomHtmlAttribs(), 'order' => $this->getOrder(), 'resource' => $this->getResource(), 'privilege' => $this->getPrivilege(), 'active' => $this->isActive(), 'visible' => $this->isVisible(), 'type' => get_class($this), 'pages' => parent::toArray())); }
public function addPage($page) { parent::addPage($page); $this->_pages = array(); }
/** * get menu item * * @param Zend_Navigation_Container $navigation * @params array $options * @return string */ public function getSelectedMenuItem(Zend_Navigation_Container $navigation) { $navigation->rewind(); return $navigation->current(); }
/** * Returns the page order of the last child page in the container. * If no page exists in the container, it returns 0. * * @param Zend_Navigation_Container $container The container to search for the last page order * @return int the last page order in the container */ protected function _getLastPageOrderInContainer($container) { $lastPageOrder = 0; foreach ($container->getPages() as $page) { $pageOrder = $page->getOrder(); if ($pageOrder > $lastPageOrder) { $lastPageOrder = $pageOrder; } } return $lastPageOrder; }
protected function checkAclForNavigation(Zend_Navigation_Container $navigation) { $accessConfig = Zend_Registry::get('config')->access; $pages = $navigation->getPages(); foreach ($pages as $page) { $controller = $page->get('controller'); $action = $page->get('action'); $allowed = Infra_AclHelper::isAllowed($controller, $action); if (!$allowed) { $navigation->removePage($page); } else { $this->checkAclForNavigation($page); } if ($action == 'dynamic_action') { $localPages = $page->getPages(); $firstPage = reset($localPages); if ($firstPage) { $firstPageAction = $firstPage->get('action'); $page->set('action', $firstPageAction); } } } }
private function addChildren(Zend_Navigation_Container $nav, SysModule $module) { $children = $module->getChildren(); /* @var $module SysModule */ foreach ($children as $module) { $page = $this->createPage($module); if ($module->hasChildren()) { if ($module->countChildren() > 1) { $this->addChildren($page, $module); } else { /** @var SysModule $child */ $child = $module->getFirstChild(); $page = $this->createPage($child); } } $nav->addPage($page); if ($page->isActive()) { $nav->setActive(true); } } }
protected function checkAclForNavigation(Zend_Navigation_Container $navigation) { $accessConfig = Zend_Registry::get('config')->access; $pages = $navigation->getPages(); foreach ($pages as $page) { $controller = $page->get('controller'); $action = $page->get('action'); $allowed = Kaltura_AclHelper::isAllowed($controller, $action); if (!$allowed) { $navigation->removePage($page); } else { $this->checkAclForNavigation($page); } } }
protected function _renderMenu(Zend_Navigation_Container $container, $linkability_function = false) { $menubar_div_id = "My_Great_MenuBar_" . uniqid(); $menubar_script = ''; $menubar_script .= 'var pMenuBar;'; $menubar_script .= "\npMenuBar = new dijit.MenuBar({});"; //$iterator = new ArrayIterator($container->getPages()); $id_counter = 0; // if (count($container->getPages()) == 1) { // $all_pages = $container->getPages(); // $all_pages = array_pop($all_pages)->getPages(); // } else { $all_pages = $container->getPages(); // } foreach ($all_pages as $page) { $id_counter++; $menu_item = $this->getDojoProgrammaticMenuparts($page, "\n", $id_counter); if ($menu_item) { $menubar_script .= "\n" . $menu_item["code"]; $menubar_script .= "\n\npMenuBar.addChild(new dijit.PopupMenuBarItem({"; $menubar_script .= "\n label: \"" . $this->_getHtmlLabel($page) . "\","; $menubar_script .= "\n popup: " . $menu_item["id"]; $menubar_script .= "\n}));"; } else { $id_counter--; } } $menubar_script .= "\npMenuBar.placeAt(\"{$menubar_div_id}\");"; $menubar_script .= "\npMenuBar.startup();"; $this->view->dojo()->addOnLoad("function() {\n" . $menubar_script . "\n}"); $this->view->dojo()->requireModule('dijit.MenuBar'); $this->view->dojo()->requireModule("dijit.MenuBarItem"); $this->view->dojo()->requireModule("dijit.PopupMenuBarItem"); $this->view->dojo()->requireModule("dijit.Menu"); $this->view->dojo()->requireModule("dijit.MenuItem"); $this->view->dojo()->requireModule("dijit.PopupMenuItem"); $html = "<div id=\"{$menubar_div_id}\"></div>"; return $html; }
/** * @deprecated * @param \Zend_Navigation_Container $menu * @param string $label * @param array $arg_array */ public static function addUrl2Page(\Zend_Navigation_Container $menu, $label, $arg_array = null) { $args = array_slice(func_get_args(), 2); $menu->addPage(self::url($args)->toPage($label)); }