1
|
|
|
<?php namespace Anomaly\Streams\Platform\Addon\Module; |
2
|
|
|
|
3
|
|
|
use Anomaly\Streams\Platform\Addon\Addon; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Class Module |
7
|
|
|
* |
8
|
|
|
* @link http://pyrocms.com/ |
9
|
|
|
* @author PyroCMS, Inc. <[email protected]> |
10
|
|
|
* @author Ryan Thompson <[email protected]> |
11
|
|
|
*/ |
12
|
|
|
class Module extends Addon |
13
|
|
|
{ |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* The module's sections. |
17
|
|
|
* |
18
|
|
|
* @var string|array |
19
|
|
|
*/ |
20
|
|
|
protected $sections = []; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* The module's menu. |
24
|
|
|
* |
25
|
|
|
* @var string|array |
26
|
|
|
*/ |
27
|
|
|
protected $menu = []; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* The module's icon. |
31
|
|
|
* |
32
|
|
|
* @var string |
33
|
|
|
*/ |
34
|
|
|
protected $icon = 'fa fa-puzzle-piece'; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* The navigation flag. |
38
|
|
|
* |
39
|
|
|
* @var bool |
40
|
|
|
*/ |
41
|
|
|
protected $navigation = true; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* The installed flag. |
45
|
|
|
* |
46
|
|
|
* @var bool |
47
|
|
|
*/ |
48
|
|
|
protected $installed = false; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* The enabled flag. |
52
|
|
|
* |
53
|
|
|
* @var bool |
54
|
|
|
*/ |
55
|
|
|
protected $enabled = false; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* The active flag. |
59
|
|
|
* |
60
|
|
|
* @var bool |
61
|
|
|
*/ |
62
|
|
|
protected $active = false; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Get the module's tag class. |
66
|
|
|
* |
67
|
|
|
* @var string |
68
|
|
|
*/ |
69
|
|
|
protected $tag = 'Anomaly\Streams\Platform\Addon\Module\ModuleTag'; |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Get the module's sections. |
73
|
|
|
* |
74
|
|
|
* @return array |
75
|
|
|
*/ |
76
|
|
|
public function getSections() |
77
|
|
|
{ |
78
|
|
|
return $this->sections; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Set the sections. |
83
|
|
|
* |
84
|
|
|
* @param array $sections |
85
|
|
|
* @return $this |
86
|
|
|
*/ |
87
|
|
|
public function setSections($sections) |
88
|
|
|
{ |
89
|
|
|
$this->sections = $sections; |
90
|
|
|
|
91
|
|
|
return $this; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Add a section. |
96
|
|
|
* |
97
|
|
|
* @param $slug |
98
|
|
|
* @param array $section |
99
|
|
|
* @param null $position |
100
|
|
|
* @return $this |
101
|
|
|
*/ |
102
|
|
View Code Duplication |
public function addSection($slug, array $section, $position = null) |
|
|
|
|
103
|
|
|
{ |
104
|
|
|
if ($position === null) { |
105
|
|
|
$position = count($this->sections) + 1; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
$front = array_slice($this->sections, 0, $position, true); |
109
|
|
|
$back = array_slice($this->sections, $position, count($this->sections) - $position, true); |
110
|
|
|
|
111
|
|
|
$this->sections = $front + [$slug => $section] + $back; |
112
|
|
|
|
113
|
|
|
return $this; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Add a section button. |
118
|
|
|
* |
119
|
|
|
* @param $section |
120
|
|
|
* @param $slug |
121
|
|
|
* @param array $button |
122
|
|
|
* @param null $position |
123
|
|
|
* @return $this |
124
|
|
|
*/ |
125
|
|
View Code Duplication |
public function addSectionButton($section, $slug, array $button, $position = null) |
|
|
|
|
126
|
|
|
{ |
127
|
|
|
$buttons = (array)array_get($this->sections, "{$section}.buttons"); |
128
|
|
|
|
129
|
|
|
if ($position === null) { |
130
|
|
|
$position = count($buttons) + 1; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
$front = array_slice($buttons, 0, $position, true); |
134
|
|
|
$back = array_slice($buttons, $position, count($buttons) - $position, true); |
135
|
|
|
|
136
|
|
|
$buttons = $front + [$slug => $button] + $back; |
137
|
|
|
|
138
|
|
|
array_set($this->sections, "{$section}.buttons", $buttons); |
|
|
|
|
139
|
|
|
|
140
|
|
|
return $this; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* Get the module's menu. |
145
|
|
|
* |
146
|
|
|
* @return array|string |
147
|
|
|
*/ |
148
|
|
|
public function getMenu() |
149
|
|
|
{ |
150
|
|
|
return $this->menu; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* Get the module's icon. |
155
|
|
|
* |
156
|
|
|
* @return string|null|false |
157
|
|
|
*/ |
158
|
|
|
public function getIcon() |
159
|
|
|
{ |
160
|
|
|
return $this->icon; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* Get the navigation flag. |
165
|
|
|
* |
166
|
|
|
* @return bool |
167
|
|
|
*/ |
168
|
|
|
public function getNavigation() |
169
|
|
|
{ |
170
|
|
|
return $this->navigation; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* Set the navigation flag. |
175
|
|
|
* |
176
|
|
|
* @param $navigation |
177
|
|
|
* @return $this |
178
|
|
|
*/ |
179
|
|
|
public function setNavigation($navigation) |
180
|
|
|
{ |
181
|
|
|
$this->navigation = $navigation; |
182
|
|
|
|
183
|
|
|
return $this; |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* Set the installed flag. |
188
|
|
|
* |
189
|
|
|
* @param $installed |
190
|
|
|
* @return $this |
191
|
|
|
*/ |
192
|
|
|
public function setInstalled($installed) |
193
|
|
|
{ |
194
|
|
|
$this->installed = $installed; |
195
|
|
|
|
196
|
|
|
return $this; |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* Get the installed flag. |
201
|
|
|
* |
202
|
|
|
* @return bool |
203
|
|
|
*/ |
204
|
|
|
public function isInstalled() |
205
|
|
|
{ |
206
|
|
|
return $this->installed; |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
/** |
210
|
|
|
* Set the enabled flag. |
211
|
|
|
* |
212
|
|
|
* @param $enabled |
213
|
|
|
* @return $this |
214
|
|
|
*/ |
215
|
|
|
public function setEnabled($enabled) |
216
|
|
|
{ |
217
|
|
|
$this->enabled = $enabled; |
218
|
|
|
|
219
|
|
|
return $this; |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
/** |
223
|
|
|
* Get the enabled flag. |
224
|
|
|
* |
225
|
|
|
* @return bool |
226
|
|
|
*/ |
227
|
|
|
public function isEnabled() |
228
|
|
|
{ |
229
|
|
|
return $this->enabled && $this->installed; |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
/** |
233
|
|
|
* Set the active flag. |
234
|
|
|
* |
235
|
|
|
* @param $active |
236
|
|
|
* @return $this |
237
|
|
|
*/ |
238
|
|
|
public function setActive($active) |
239
|
|
|
{ |
240
|
|
|
$this->active = $active; |
241
|
|
|
|
242
|
|
|
return $this; |
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
/** |
246
|
|
|
* Get the active flag. |
247
|
|
|
* |
248
|
|
|
* @return bool |
249
|
|
|
*/ |
250
|
|
|
public function isActive() |
251
|
|
|
{ |
252
|
|
|
return $this->active; |
253
|
|
|
} |
254
|
|
|
|
255
|
|
|
/** |
256
|
|
|
* Get the module's presenter. |
257
|
|
|
* |
258
|
|
|
* @return ModulePresenter |
259
|
|
|
*/ |
260
|
|
|
public function getPresenter() |
261
|
|
|
{ |
262
|
|
|
return app()->make('Anomaly\Streams\Platform\Addon\Module\ModulePresenter', ['object' => $this]); |
263
|
|
|
} |
264
|
|
|
} |
265
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.