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