dolibarr 18.0.6
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 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
29class Menu
30{
31 public $liste;
32
36 public function __construct()
37 {
38 $this->liste = array();
39 }
40
46 public function clear()
47 {
48 $this->liste = array();
49 }
50
68 public function add($url, $titre, $level = 0, $enabled = 1, $target = '', $mainmenu = '', $leftmenu = '', $position = 0, $id = '', $idsel = '', $classname = '', $prefix = '')
69 {
70 $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);
71 }
72
91 public function insert($idafter, $url, $titre, $level = 0, $enabled = 1, $target = '', $mainmenu = '', $leftmenu = '', $position = 0, $id = '', $idsel = '', $classname = '', $prefix = '')
92 {
93 $array_start = array_slice($this->liste, 0, ($idafter + 1));
94 $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));
95 $array_end = array_slice($this->liste, ($idafter + 1));
96 $this->liste = array_merge($array_start, $array_new, $array_end);
97 }
98
99 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
105 public function remove_last()
106 {
107 // phpcs:enable
108 if (count($this->liste) > 1) {
109 array_pop($this->liste);
110 }
111 }
112
119 {
120 $nb = 0;
121 foreach ($this->liste as $val) {
122 //if (dol_eval($val['enabled'], 1, 1, '1')) $nb++;
123 if (!empty($val['enabled'])) {
124 $nb++; // $val['enabled'] is already evaluated to 0 or 1, no need for dol_eval()
125 }
126 }
127 return $nb;
128 }
129}
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.
clear()
Clear property ->liste.