dolibarr 20.0.2
menu.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2002-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2005-2012 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
30class Menu
31{
37 public $liste;
38
42 public function __construct()
43 {
44 $this->liste = array();
45 }
46
52 public function clear()
53 {
54 $this->liste = array();
55 }
56
74 public function add($url, $titre, $level = 0, $enabled = 1, $target = '', $mainmenu = '', $leftmenu = '', $position = 0, $id = '', $idsel = '', $classname = '', $prefix = '')
75 {
76 $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);
77 }
78
97 public function insert($idafter, $url, $titre, $level = 0, $enabled = 1, $target = '', $mainmenu = '', $leftmenu = '', $position = 0, $id = '', $idsel = '', $classname = '', $prefix = '')
98 {
99 $array_start = array_slice($this->liste, 0, ($idafter + 1));
100 $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));
101 $array_end = array_slice($this->liste, ($idafter + 1));
102 $this->liste = array_merge($array_start, $array_new, $array_end);
103 }
104
105 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
111 public function remove_last()
112 {
113 // phpcs:enable
114 if (count($this->liste) > 1) {
115 array_pop($this->liste);
116 }
117 }
118
125 {
126 $nb = 0;
127 foreach ($this->liste as $val) {
128 if (!empty($val['enabled'])) {
129 $nb++; // $val['enabled'] is already evaluated to 0 or 1, no need for dol_eval()
130 }
131 }
132 return $nb;
133 }
134}
Class to manage left menus.
add($url, $titre, $level=0, $enabled=1, $target='', $mainmenu='', $leftmenu='', $position=0, $id='', $idsel='', $classname='', $prefix='')
Add a menu entry into this->liste (at end)
remove_last()
Remove a menu entry from this->liste.
__construct()
Constructor.
getNbOfVisibleMenuEntries()
Return number of visible entries (gray or not)
insert($idafter, $url, $titre, $level=0, $enabled=1, $target='', $mainmenu='', $leftmenu='', $position=0, $id='', $idsel='', $classname='', $prefix='')
Insert a menu entry into this->liste (after $idafter)
clear()
Clear property ->liste.