/** * Show all navigation groups * * @return void */ public function index() { $groups = $this->adjacency_list->get_all_groups(); $data['groups'] = array(); foreach ($groups as $group) { $items = $this->adjacency_list->get_all($group['id']); $data['groups'][$group['id']] = $group; $data['groups'][$group['id']]['items'] = parse_children($items); } $data['title'] = 'Navigation'; $this->load->view('adjacency/list/index', $data); }
/** * Get all items from group to dropdown array * * @param int $group_id Group id * @param int $exclude Excluded id * @param int $level Current level * @param array &$tree Tree array * * @return array */ public function get_all_for_dropdown($group_id = 1, $exclude = 0, $level = 0, &$tree = array()) { $output = array(); if ($level === 0) { $tree = $this->get_all($group_id); $tree = parse_children($tree); $output[0] = $this->dropdown['parent']; } if (!empty($tree)) { foreach ($tree as &$leaf) { if ($exclude != (int) $leaf['id']) { $output[$leaf['id']] = str_repeat($this->dropdown['space'], $level) . ' ' . htmlspecialchars($leaf['name'], ENT_QUOTES, 'UTF-8'); if ($this->max_levels !== 0 && $this->max_levels > $level + 1 || $this->max_levels === 0 || $exclude === 0) { if (isset($leaf['children']) && !empty($leaf['children'])) { $output += $this->get_all_for_dropdown($group_id, $exclude, $level + 1, $leaf['children']); } } } } } return $output; }
/** * Build tree item * * Creates adjacency list based on group (id or slug) and shows leafs related only to current item * * @param mixed $group Group id or slug * @param int $item_id Current item id * @param array $attributes Any attributes * @param array &$tree Tree array * @param array &$in_array Output tree array * * @return string */ function build_tree_item($group, $item_id, $attributes = array(), &$tree = NULL, &$in_array = array()) { if (empty($tree)) { $CI =& get_instance(); $CI->load->library('adjacency_list'); $tree = $CI->adjacency_list->get_all($group); } if (!empty($tree)) { foreach ($tree as &$leaf) { if ($item_id === (int) $leaf['id']) { array_push($in_array, $leaf['id']); build_tree_item($group, (int) $leaf['parent_id'], $attributes, $tree, $in_array); } } $tree = parse_children($tree); $in_array = array_reverse($in_array); return format_tree($tree, $in_array, $attributes); } return ''; }