Merge branch 'maint/7.0'
[ninja.git] / application / models / menu.php
blob9d72111d3e12b98cac04f5d990c5ce112e2516e0
1 <?php defined('SYSPATH') OR die('No direct access allowed.');
3 /**
4 * Represents a user's, perhaps partial, view of the complete menu
5 */
6 class Menu_Model extends Model
9 /**
10 * @todo previously create_menu, refactor user_controllers' stuff into here as well
11 * Build menu structure and possibly remove some items
13 * @return array
15 function create()
17 include(APPPATH.'views/menu/menu.php');
18 $logged_in_users_groups = Op5Auth::instance()->get_groups();
19 $ninja_menu = Op5Config::instance()->getConfig('ninja_menu');
20 foreach(array_intersect((array)$logged_in_users_groups, array_keys((array) $ninja_menu)) as $section) {
21 $this->remove_menu_items($menu_base, $menu_items, $ninja_menu[$section]);
23 return $menu_base;
26 /**
27 * Remove menu item by index
28 * Both section string ['about', 'monitoring', etc]
29 * and item string ['portal', 'manual', 'support', etc] are required.
30 * As a consequence, all menu items has to be explicitly removed before removing the section
32 private function remove_menu_items(&$menu_links=false, &$menu_items=false, $section_str=false, $item_str=false)
34 if (empty($menu_links) || empty($menu_items) || empty($section_str)) {
35 return false;
38 if (is_array($section_str)) {
39 # we have to make recursive calls
40 foreach ($section_str as $section => $items) {
41 foreach ($items as $item) {
42 $this->remove_menu_items($menu_links, $menu_items, $section, $item);
45 } else {
46 if (empty($item_str) && isset($menu_links[$menu_items['section_'.$section_str]])
47 && empty($menu_links[$menu_items['section_'.$section_str]])) {
48 # remove the section
49 unset($menu_links[$menu_items['section_'.$section_str]]);
50 } elseif (!empty($item_str) && isset($menu_items['section_'.$section_str]) && isset($menu_links[$menu_items['section_'.$section_str]]) && isset($menu_items[$item_str]) && isset($menu_links[$menu_items['section_'.$section_str]][$menu_items[$item_str]])) {
51 unset($menu_links[$menu_items['section_'.$section_str]][$menu_items[$item_str]]);