1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This class contains a standard way of displaying side/drop down menus. |
5
|
|
|
* |
6
|
|
|
* @name ElkArte Forum |
7
|
|
|
* @copyright ElkArte Forum contributors |
8
|
|
|
* @license BSD http://opensource.org/licenses/BSD-3-Clause |
9
|
|
|
* |
10
|
|
|
* @version 2.0 dev |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace ElkArte\Menu; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class MenuArea |
17
|
|
|
* |
18
|
|
|
* This class implements a standard way of creating menus |
19
|
|
|
* |
20
|
|
|
* @package ElkArte\Menu |
21
|
|
|
*/ |
22
|
|
|
class MenuArea extends MenuItem |
23
|
|
|
{ |
24
|
|
|
/** @var callable $function function to call when area is selected. */ |
25
|
|
|
protected $function; |
26
|
|
|
|
27
|
|
|
/** @var string $icon File name of an icon to use on the menu, if using the sprite class, set as transparent.png */ |
28
|
|
|
protected $icon = ''; |
29
|
|
|
|
30
|
|
|
/** @var string $controller URL to use for this menu item. */ |
31
|
|
|
protected $controller = ''; |
32
|
|
|
|
33
|
|
|
/** @var string $select References another area to be highlighted while this one is active */ |
34
|
|
|
public $select = ''; |
35
|
|
|
|
36
|
|
|
/** @var string $class Class name to apply to the icon img, used to apply a sprite icon */ |
37
|
|
|
protected $class = ''; |
38
|
|
|
|
39
|
|
|
/** @var bool $enabled Should this area even be accessible? */ |
40
|
|
|
protected $enabled = true; |
41
|
|
|
|
42
|
|
|
/** @var bool $hidden Should this area be visible? */ |
43
|
|
|
protected $hidden = false; |
44
|
|
|
|
45
|
|
|
/** @var array $subsections Array of subsections from this area. */ |
46
|
|
|
private $subsections = []; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @param array $arr |
50
|
|
|
* |
51
|
|
|
* @return MenuArea |
52
|
|
|
*/ |
53
|
41 |
|
protected function buildMoreFromArray(array $arr): MenuArea |
54
|
|
|
{ |
55
|
41 |
|
if (isset($arr['custom_url'])) |
56
|
|
|
{ |
57
|
2 |
|
$this->setUrl($arr['custom_url']); |
58
|
|
|
} |
59
|
41 |
|
if (isset($arr['subsections'])) |
60
|
|
|
{ |
61
|
41 |
|
foreach ($arr['subsections'] as $var => $subsection) |
62
|
|
|
{ |
63
|
41 |
|
$this->addSubsection($var, $subsection); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
67
|
41 |
|
return $this; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @param string $id |
72
|
|
|
* @param MenuSubsection $subsection |
73
|
|
|
* |
74
|
|
|
* @return $this |
75
|
|
|
*/ |
76
|
41 |
|
public function addSubsection(string $id, MenuSubsection $subsection): MenuArea |
77
|
|
|
{ |
78
|
41 |
|
$this->subsections[$id] = $subsection; |
79
|
|
|
|
80
|
41 |
|
return $this; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @return callable |
85
|
|
|
*/ |
86
|
1 |
|
public function getFunction() |
87
|
|
|
{ |
88
|
1 |
|
return $this->function; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @param callable $function |
93
|
|
|
* |
94
|
|
|
* @return MenuArea |
95
|
|
|
*/ |
96
|
41 |
|
public function setFunction($function): MenuArea |
97
|
|
|
{ |
98
|
41 |
|
$this->function = $function; |
99
|
|
|
|
100
|
41 |
|
return $this; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @return string |
105
|
|
|
*/ |
106
|
38 |
|
public function getIcon(): string |
107
|
|
|
{ |
108
|
38 |
|
return $this->icon; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @param string $icon |
113
|
|
|
* |
114
|
|
|
* @return MenuArea |
115
|
|
|
*/ |
116
|
41 |
|
public function setIcon(string $icon): MenuArea |
117
|
|
|
{ |
118
|
41 |
|
$this->icon = $icon; |
119
|
|
|
|
120
|
41 |
|
return $this; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @return string |
125
|
|
|
*/ |
126
|
1 |
|
public function getController(): string |
127
|
|
|
{ |
128
|
1 |
|
return $this->controller; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* @param string $controller |
133
|
|
|
* |
134
|
|
|
* @return MenuArea |
135
|
|
|
*/ |
136
|
41 |
|
public function setController(string $controller): MenuArea |
137
|
|
|
{ |
138
|
41 |
|
$this->controller = $controller; |
139
|
|
|
|
140
|
41 |
|
return $this; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* @return string |
145
|
|
|
*/ |
146
|
38 |
|
public function getSelect(): string |
147
|
|
|
{ |
148
|
38 |
|
return $this->select; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* @param string $select |
153
|
|
|
* |
154
|
|
|
* @return MenuArea |
155
|
|
|
*/ |
156
|
41 |
|
public function setSelect(string $select): MenuArea |
157
|
|
|
{ |
158
|
41 |
|
$this->select = $select; |
159
|
|
|
|
160
|
41 |
|
return $this; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* @return string |
165
|
|
|
*/ |
166
|
1 |
|
public function getClass(): string |
167
|
|
|
{ |
168
|
1 |
|
return $this->class; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* @param string $class |
173
|
|
|
* |
174
|
|
|
* @return MenuArea |
175
|
|
|
*/ |
176
|
41 |
|
public function setClass(string $class): MenuArea |
177
|
|
|
{ |
178
|
41 |
|
$this->class = $class; |
179
|
|
|
|
180
|
41 |
|
return $this; |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* @return boolean |
185
|
|
|
*/ |
186
|
38 |
|
public function isHidden(): bool |
187
|
|
|
{ |
188
|
38 |
|
return $this->hidden; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* @param boolean $hidden |
193
|
|
|
* |
194
|
|
|
* @return MenuArea |
195
|
|
|
*/ |
196
|
41 |
|
public function setHidden(bool $hidden): MenuArea |
197
|
|
|
{ |
198
|
41 |
|
$this->hidden = $hidden; |
199
|
|
|
|
200
|
41 |
|
return $this; |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
/** |
204
|
|
|
* @return array |
205
|
|
|
*/ |
206
|
38 |
|
public function toArray(): array |
207
|
|
|
{ |
208
|
38 |
|
return get_object_vars($this); |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
/** |
212
|
|
|
* @return array |
213
|
|
|
*/ |
214
|
39 |
|
public function getSubsections(): array |
215
|
|
|
{ |
216
|
39 |
|
return $this->subsections; |
217
|
|
|
} |
218
|
|
|
} |
219
|
|
|
|