-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
menu.class.php
127 lines (118 loc) · 4.48 KB
/
menu.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<?php
/* Copyright (C) 2002-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2005-2012 Laurent Destailleur <eldy@users.sourceforge.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* \file htdocs/core/class/menu.class.php
* \ingroup core
* \brief Fichier de la classe de gestion du menu gauche
*/
/**
* Class to manage left menus
*/
class Menu
{
var $liste;
/**
* Constructor
*/
function __construct()
{
$this->liste = array();
}
/**
* Clear property ->liste
*
* @return void
*/
function clear()
{
$this->liste = array();
}
/**
* Add a menu entry into this->liste (at end)
*
* @param string $url Url to follow on click (does not include DOL_URL_ROOT)
* @param string $titre Label of menu to add
* @param integer $level Level of menu to add
* @param int $enabled Menu active or not (0=Not active, 1=Active, 2=Active but grey)
* @param string $target Target link
* @param string $mainmenu Main menu ('home', 'companies', 'products', ...)
* @param string $leftmenu Left menu ('setup', 'system', 'admintools', ...)
* @param int $position Position (not used yet)
* @param string $id Id
* @param string $idsel Id sel
* @param string $classname Class name
* @param string $prefix Prefix to title (image or picto)
* @return void
*/
function add($url, $titre, $level=0, $enabled=1, $target='',$mainmenu='',$leftmenu='',$position=0, $id='', $idsel='', $classname='', $prefix='')
{
$this->liste[]=array('url'=>$url,'titre'=>$titre,'level'=>$level,'enabled'=>$enabled,'target'=>$target,'mainmenu'=>$mainmenu,'leftmenu'=>$leftmenu, 'position'=>$position, 'id'=>$id, 'idsel'=>$idsel, 'classname'=>$classname, 'prefix'=>$prefix);
}
/**
* Insert a menu entry into this->liste
*
* @param int $idafter Array key after which inserting new entry
* @param string $url Url to follow on click
* @param string $titre Label of menu to add
* @param integer $level Level of menu to add
* @param int $enabled Menu active or not
* @param string $target Target link
* @param string $mainmenu Main menu ('home', 'companies', 'products', ...)
* @param string $leftmenu Left menu ('setup', 'system', 'admintools', ...)
* @param int $position Position (not used yet)
* @param string $id Id
* @param string $idsel Id sel
* @param string $classname Class name
* @param string $prefix Prefix to title (image or picto)
* @return void
*/
function insert($idafter, $url, $titre, $level=0, $enabled=1, $target='',$mainmenu='',$leftmenu='',$position=0, $id='', $idsel='', $classname='', $prefix='')
{
$array_start = array_slice($this->liste,0,($idafter+1));
$array_new = array(0=>array('url'=>$url,'titre'=>$titre,'level'=>$level,'enabled'=>$enabled,'target'=>$target,'mainmenu'=>$mainmenu,'leftmenu'=>$leftmenu,'position'=>$position, 'id'=>$id, 'idsel'=>$idsel, 'classname'=>$classname, 'prefix'=>$prefix));
$array_end = array_slice($this->liste,($idafter+1));
$this->liste=array_merge($array_start,$array_new,$array_end);
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
/**
* Remove a menu entry from this->liste
*
* @return void
*/
function remove_last()
{
// phpcs:enable
if (count($this->liste) > 1) {
array_pop($this->liste);
}
}
/**
* Return number of visible entries (gray or not)
*
* @return int Number of visible (gray or not) menu entries
*/
function getNbOfVisibleMenuEntries()
{
$nb=0;
foreach($this->liste as $val)
{
if (! empty($val['enabled'])) $nb++;
}
return $nb;
}
}