Example #1
0
 /**
  * Get head
  * 
  * Return the front navbar
  * elements
  * 
  * @return array
  */
 public function getHead()
 {
     $elements = array();
     foreach ($this->elements as $element) {
         $elements[$element->getName()] = $element;
     }
     foreach ($this->elements as $element) {
         if (is_array($element->getChild())) {
             foreach ($element->getChild() as $child) {
                 if ($child instanceof NavBarElement) {
                     if (array_key_exists($child->getName(), $elements)) {
                         unset($elements[$child->getName()]);
                     }
                 }
             }
         }
     }
     $resultNavBar = new NavBar();
     $resultNavBar->setElements($elements);
     $resultNavBar->setOrderedElements($this->orderElements($elements));
     return $resultNavBar;
 }
Example #2
0
 /**
  * Build navbar
  * 
  * Return a navbar element
  * build from the application
  * navbar configuration yaml 
  * files
  * 
  * @param Router $router - the application router service
  * 
  * @return NavBar - the builded navbar
  */
 public function buildNavbar(Router $router)
 {
     $closure = function ($router, $serialize = true) {
         $bundlesNames = $this->bundles->getNames();
         $config = array();
         foreach ($bundlesNames as $name) {
             $bundle = $this->bundles->get($name);
             $configFilePath = $bundle->getPath() . $this->basePath;
             $yaml = new Parser();
             $navbarConfig = $yaml->parse(file_get_contents($configFilePath));
             if (is_array($navbarConfig)) {
                 $config = array_merge($config, $navbarConfig["navbar"]);
             }
         }
         $navBar = new NavBar();
         $navBar->parseArray($config, $router, $this->defaultPosition);
         if ($serialize) {
             return serialize($navBar);
         } else {
             return $navBar;
         }
     };
     if ($this->cacheEnabled) {
         $navbar = unserialize($this->cacheManager->process($this->cacheId . "@navbar", $closure, $router, true));
     } else {
         $navbar = $closure($router, false);
     }
     return $navbar;
 }