dolibarr 21.0.0-alpha
webportal.lib.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
3 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
4 */
5
18function getNav($Tmenu)
19{
20 $menu = '';
21
22 foreach ($Tmenu as $item) {
23 $menu .= getNavItem($item);
24 }
25
26 return $menu;
27}
28
37function getNavItem($item, $deep = 0)
38{
40
41 $menu = '';
42
43 $itemDefault = array(
44 'active' => false,
45 'separator' => false,
46 );
47
48 $item = array_replace($itemDefault, $item); // applique les valeurs par default
49
50 if ($context->menuIsActive($item['id'])) {
51 $item['active'] = true;
52 }
53
54 if (!isset($item['class'])) {
55 $item['class'] = '--item-' . preg_replace('/[^a-z0-9 ]/i', '-', $item['id']);
56 }
57
58
59 if (!empty($item['override'])) {
60 $menu .= $item['override'];
61 } elseif (!empty($item['children'])) {
62 $menuChildren = '';
63 $haveChildActive = false;
64
65 foreach ($item['children'] as $child) {
66 $item = array_replace($itemDefault, $item); // applique les valeurs par default
67 '@phan-var-force array{id:string,rank:int,url:string,name:string,group:string,override?:int<0,1>,active?:bool,separator?:bool} $child';
68
69 if (!empty($child['separator'])) {
70 $menuChildren .= '<li role="separator" class="divider"></li>';
71 }
72
73 if ($context->menuIsActive($child['id'])) {
74 $child['active'] = true;
75 $haveChildActive = true;
76 }
77
78 if (!empty($child['children'])) {
79 $menuChildren .= "\n\r" . '<!-- print sub menu -->' . "\n\r";
80 $menuChildren .= getNavItem($child, $deep + 1);
81 $menuChildren .= "\n\r" . '<!-- print sub menu -->' . "\n\r";
82 } else {
83 $menuChildren .= '<li class="dropdown-item '.$item['class'].'" data-deep="' . $deep . '" ><a href="' . $child['url'] . '" class="' . (!empty($child['active']) ? 'active' : '') . '" ">' . $child['name'] . '</a></li>';
84 }
85 }
86
87 $active = '';
88 if ($haveChildActive || $item['active']) {
89 $active = 'active';
90 }
91
92 $menu .= '<li data-deep="' . $deep . '" class="'.$item['class'].' dropdown ' . ($deep > 0 ? 'dropdown-item dropdown-submenu' : 'nav-item') . ' ' . $active . '">';
93 $menu .= '<a href="#" class="' . ($deep > 0 ? '' : 'nav-link') . ' dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">' . $item['name'] . ' <span class="caret"></span></a>';
94 $menu .= '<ul class="dropdown-menu ">' . $menuChildren . '</ul>';
95 $menu .= '</li>';
96 } else {
97 $menu .= '<li data-deep="' . $deep . '" class="'.$item['class'].' ' . ($deep > 0 ? 'dropdown-item' : 'nav-item ') . ' ' . ($item['active'] ? 'active' : '') . '"><a href="' . $item['url'] . '" class="' . ($deep > 0 ? '' : 'nav-link') . '" >' . $item['name'] . '</a></li>';
98 }
99
100 return $menu;
101}
102
115function menuSortInv($a, $b)
116{
117
118 if (empty($a['rank'])) {
119 $a['rank'] = 0;
120 }
121 if (empty($b['rank'])) {
122 $b['rank'] = 0;
123 }
124 if ($a['rank'] == $b['rank']) {
125 return 0;
126 }
127
128 return ($a['rank'] < $b['rank']) ? -1 : 1;
129}
static getInstance()
Singleton method to create one instance of this object.
getNav($Tmenu)
Get nav menu.
getNavItem($item, $deep=0)
Get nav item.
menuSortInv($a, $b)
Sort menu uasort callback function to Sort menu fields.
$context
@method int call_trigger(string $triggerName, User $user)
Definition logout.php:42