/** * Initialize navigation system * * @param array $sitemap */ public static function init(array $sitemap) { foreach ($sitemap as $section) { // Invalid if (!isset($section['name'])) { continue; } // Add page if (isset($section['url']) && !isset($section['top'])) { //var_dump($section); $page = Navigation_Page::factory($section); $section_object = Navigation::get_root_section(); $section_object->add_page($page); } else { $section_object = Navigation::get_section($section['name'], null, isset($section['priority']) ? $section['priority'] : 1); // URL if (isset($section['url'])) { $section_object->url = $section['url']; } // Icon if (isset($section['icon'])) { $section_object->icon = $section['icon']; } // Buttons if (isset($section['buttons'])) { $section_object->add_buttons($section['buttons']); } // Priority if (isset($section['priority'])) { $section_object->priority = (int) $section['priority']; } if (!empty($section['children'])) { $section_object->add_pages($section['children']); } } } }
/** * Add multiple pages to section * * @param array $pages */ public function add_pages(array $pages) { foreach ($pages as $page) { if (isset($page['children'])) { $section = Navigation::get_section($page['name'], $this); if (isset($page['icon'])) { $section->icon = $page['icon']; } // Buttons if (isset($section['buttons'])) { $section->add_buttons($section['buttons']); } // Hijos if (count($page['children']) > 0) { $section->add_pages($page['children']); } } else { $page = Navigation_Page::factory($page); $this->add_page($page); } } }