Passed
Push — master ( 4e88da...5feb35 )
by Alxarafe
26:36
created

Menu::getNbOfVisibleMenuEntries()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 4
nop 0
dl 0
loc 8
rs 10
c 0
b 0
f 0
nc 3
1
<?php
2
/* Copyright (C) 2002-2006 Rodolphe Quiedeville <[email protected]>
3
 * Copyright (C) 2005-2012 Laurent Destailleur  <[email protected]>
4
 * Copyright (C) 2018       Alxarafe            <[email protected]>
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 <http://www.gnu.org/licenses/>.
18
 */
19
namespace Alixar\Base;
20
21
/**
22
 *  \file       htdocs/core/class/menu.class.php
23
 *  \ingroup    core
24
 *  \brief      Fichier de la classe de gestion du menu gauche
25
 */
26
27
28
/**
29
 *	Class to manage left menus
30
 */
31
class Menu
32
{
33
    var $liste;
34
35
    /**
36
	 *	Constructor
37
     */
38
    function __construct()
39
    {
40
      	$this->liste = array();
41
    }
42
43
    /**
44
     * Clear property ->liste
45
     *
46
     * @return	void
47
     */
48
    function clear()
49
    {
50
        $this->liste = array();
51
    }
52
53
    /**
54
     * Add a menu entry into this->liste (at end)
55
     *
56
     * @param	string	$url        Url to follow on click (does not include DOL_URL_ROOT)
57
     * @param   string	$titre      Label of menu to add
58
     * @param   integer	$level      Level of menu to add
59
     * @param   int		$enabled    Menu active or not (0=Not active, 1=Active, 2=Active but grey)
60
     * @param   string	$target		Target link
61
     * @param	string	$mainmenu	Main menu ('home', 'companies', 'products', ...)
62
     * @param	string	$leftmenu	Left menu ('setup', 'system', 'admintools', ...)
63
     * @param	int		$position	Position (not used yet)
64
     * @param	string	$id			Id
65
     * @param	string	$idsel		Id sel
66
     * @param	string	$classname	Class name
67
     * @param	string	$prefix		Prefix to title (image or picto)
68
     * @return	void
69
     */
70
    function add($url, $titre, $level=0, $enabled=1, $target='',$mainmenu='',$leftmenu='',$position=0, $id='', $idsel='', $classname='', $prefix='')
71
    {
72
    	$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);
73
    }
74
75
    /**
76
     * Insert a menu entry into this->liste
77
     *
78
     * @param   int		$idafter	Array key after which inserting new entry
79
     * @param	string	$url        Url to follow on click
80
     * @param   string	$titre      Label of menu to add
81
     * @param   integer	$level      Level of menu to add
82
     * @param   int		$enabled    Menu active or not
83
     * @param   string	$target		Target link
84
     * @param	string	$mainmenu	Main menu ('home', 'companies', 'products', ...)
85
     * @param	string	$leftmenu	Left menu ('setup', 'system', 'admintools', ...)
86
     * @param	int		$position	Position (not used yet)
87
     * @param	string	$id			Id
88
     * @param	string	$idsel		Id sel
89
     * @param	string	$classname	Class name
90
     * @param	string	$prefix		Prefix to title (image or picto)
91
     * @return	void
92
     */
93
    function insert($idafter, $url, $titre, $level=0, $enabled=1, $target='',$mainmenu='',$leftmenu='',$position=0, $id='', $idsel='', $classname='', $prefix='')
94
    {
95
        $array_start = array_slice($this->liste,0,($idafter+1));
96
        $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));
97
        $array_end   = array_slice($this->liste,($idafter+1));
98
        $this->liste=array_merge($array_start,$array_new,$array_end);
99
    }
100
101
    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
102
    /**
103
     * Remove a menu entry from this->liste
104
     *
105
     * @return	void
106
     */
107
    function remove_last()
108
    {
109
        // phpcs:enable
110
        if (count($this->liste) > 1) {
111
            array_pop($this->liste);
112
        }
113
    }
114
115
    /**
116
     * Return number of visible entries (gray or not)
117
     *
118
     *  @return int     Number of visible (gray or not) menu entries
119
     */
120
    function getNbOfVisibleMenuEntries()
121
    {
122
        $nb=0;
123
        foreach($this->liste as $val)
124
        {
125
            if (! empty($val['enabled'])) $nb++;
126
        }
127
        return $nb;
128
    }
129
}
130