1 | <?php |
||
8 | class WidgetGroup |
||
9 | { |
||
10 | use ViewExpressionTrait; |
||
11 | |||
12 | /** |
||
13 | * The widget group name. |
||
14 | * |
||
15 | * @var string |
||
16 | */ |
||
17 | protected $name; |
||
18 | |||
19 | /** |
||
20 | * The application wrapper. |
||
21 | * |
||
22 | * @var ApplicationWrapperContract |
||
23 | */ |
||
24 | protected $app; |
||
25 | |||
26 | /** |
||
27 | * The array of widgets to display in this group. |
||
28 | * |
||
29 | * @var array |
||
30 | */ |
||
31 | protected $widgets = []; |
||
32 | |||
33 | /** |
||
34 | * The position of a widget in this group. |
||
35 | * |
||
36 | * @var int |
||
37 | */ |
||
38 | protected $position = 100; |
||
39 | |||
40 | /** |
||
41 | * The separator to display between widgets in the group. |
||
42 | * |
||
43 | * @var string |
||
44 | */ |
||
45 | protected $separator = ''; |
||
46 | |||
47 | /** |
||
48 | * The number of widgets in the group. |
||
49 | * |
||
50 | * @var int |
||
51 | */ |
||
52 | protected $count = 0; |
||
53 | |||
54 | /** |
||
55 | * A callback that defines extra markup that wraps every widget in the group. |
||
56 | * |
||
57 | * @var callable |
||
58 | */ |
||
59 | protected $wrapCallback; |
||
60 | |||
61 | /** |
||
62 | * @param $name |
||
63 | * @param ApplicationWrapperContract $app |
||
64 | */ |
||
65 | public function __construct($name, ApplicationWrapperContract $app) |
||
71 | |||
72 | /** |
||
73 | * Display all widgets from this group in correct order. |
||
74 | * |
||
75 | * @return string |
||
76 | */ |
||
77 | public function display() |
||
95 | |||
96 | /** |
||
97 | * Set widget position. |
||
98 | * |
||
99 | * @param int $position |
||
100 | * |
||
101 | * @return $this |
||
102 | */ |
||
103 | public function position($position) |
||
109 | |||
110 | /** |
||
111 | * Add a widget to the group. |
||
112 | */ |
||
113 | public function addWidget() |
||
117 | |||
118 | /** |
||
119 | * Add an async widget to the group. |
||
120 | */ |
||
121 | public function addAsyncWidget() |
||
125 | |||
126 | /** |
||
127 | * Getter for position. |
||
128 | * |
||
129 | * @return int |
||
130 | */ |
||
131 | public function getPosition() |
||
135 | |||
136 | /** |
||
137 | * Set a separator to display between widgets in the group. |
||
138 | * |
||
139 | * @param string $separator |
||
140 | * |
||
141 | * @return $this |
||
142 | */ |
||
143 | public function setSeparator($separator) |
||
149 | |||
150 | /** |
||
151 | * Setter for $this->wrapCallback. |
||
152 | * |
||
153 | * @param callable $callable |
||
154 | * |
||
155 | * @return $this |
||
156 | */ |
||
157 | public function wrap(callable $callable) |
||
163 | |||
164 | /** |
||
165 | * Check if there are any widgets in the group. |
||
166 | * |
||
167 | * @return bool |
||
168 | */ |
||
169 | public function any() |
||
173 | |||
174 | /** |
||
175 | * Check if there are no widgets in the group. |
||
176 | * |
||
177 | * @return bool |
||
178 | */ |
||
179 | public function isEmpty() |
||
183 | |||
184 | /** |
||
185 | * Count the number of widgets in this group. |
||
186 | * |
||
187 | * @return int |
||
188 | */ |
||
189 | public function count() |
||
198 | |||
199 | /** |
||
200 | * Add a widget with a given type to the array. |
||
201 | * |
||
202 | * @param string $type |
||
203 | * @param array $arguments |
||
204 | */ |
||
205 | protected function addWidgetWithType($type, array $arguments = []) |
||
220 | |||
221 | /** |
||
222 | * Display a widget according to its type. |
||
223 | * |
||
224 | * @param $widget |
||
225 | * |
||
226 | * @return mixed |
||
227 | */ |
||
228 | protected function displayWidget($widget) |
||
234 | |||
235 | /** |
||
236 | * Reset the position property back to the default. |
||
237 | * So it does not affect the next widget. |
||
238 | */ |
||
239 | protected function resetPosition() |
||
243 | |||
244 | /** |
||
245 | * Wraps widget content in a special markup defined by $this->wrap(). |
||
246 | * |
||
247 | * @param string $content |
||
248 | * @param int $index |
||
249 | * @param int $total |
||
250 | * |
||
251 | * @return string |
||
252 | */ |
||
253 | protected function performWrap($content, $index, $total) |
||
263 | } |
||
264 |