1 | <?php |
||
48 | final class WidgetTemplate implements JsonSerializable { |
||
49 | |||
50 | |||
51 | /** @var string */ |
||
52 | private $icon = ''; |
||
53 | |||
54 | /** @var array */ |
||
55 | private $css = []; |
||
56 | |||
57 | /** @var array */ |
||
58 | private $js = []; |
||
59 | |||
60 | /** @var string */ |
||
61 | private $content = ''; |
||
62 | |||
63 | /** @var string */ |
||
64 | private $function = ''; |
||
65 | |||
66 | /** @var WidgetSetting[] */ |
||
67 | private $settings = []; |
||
68 | |||
69 | |||
70 | /** |
||
71 | * Get the icon class of the widget. |
||
72 | * |
||
73 | * @since 15.0.0 |
||
74 | * |
||
75 | * @return string |
||
76 | */ |
||
77 | public function getIcon(): string { |
||
80 | |||
81 | /** |
||
82 | * Set the icon class of the widget. |
||
83 | * This class must be defined in one of the CSS file used by the widget. |
||
84 | * |
||
85 | * @see addCss |
||
86 | * |
||
87 | * @since 15.0.0 |
||
88 | * |
||
89 | * @param string $icon |
||
90 | * |
||
91 | * @return WidgetTemplate |
||
92 | */ |
||
93 | public function setIcon(string $icon): WidgetTemplate { |
||
98 | |||
99 | /** |
||
100 | * Get CSS files to be included when displaying a widget |
||
101 | * |
||
102 | * @since 15.0.0 |
||
103 | * |
||
104 | * @return array |
||
105 | */ |
||
106 | public function getCss(): array { |
||
109 | |||
110 | /** |
||
111 | * path and name of CSS files |
||
112 | * |
||
113 | * @since 15.0.0 |
||
114 | * |
||
115 | * @param array $css |
||
116 | * |
||
117 | * @return WidgetTemplate |
||
118 | */ |
||
119 | public function setCss(array $css): WidgetTemplate { |
||
124 | |||
125 | /** |
||
126 | * Add a CSS file to be included when displaying a widget. |
||
127 | * |
||
128 | * @since 15.0.0 |
||
129 | * |
||
130 | * @param string $css |
||
131 | * |
||
132 | * @return WidgetTemplate |
||
133 | */ |
||
134 | public function addCss(string $css): WidgetTemplate { |
||
139 | |||
140 | /** |
||
141 | * Get JS files to be included when loading a widget |
||
142 | * |
||
143 | * @since 15.0.0 |
||
144 | * |
||
145 | * @return array |
||
146 | */ |
||
147 | public function getJs(): array { |
||
150 | |||
151 | /** |
||
152 | * Set an array of JS files to be included when loading a widget. |
||
153 | * |
||
154 | * @since 15.0.0 |
||
155 | * |
||
156 | * @param array $js |
||
157 | * |
||
158 | * @return WidgetTemplate |
||
159 | */ |
||
160 | public function setJs(array $js): WidgetTemplate { |
||
165 | |||
166 | /** |
||
167 | * Add a JS file to be included when loading a widget. |
||
168 | * |
||
169 | * @since 15.0.0 |
||
170 | * |
||
171 | * @param string $js |
||
172 | * |
||
173 | * @return WidgetTemplate |
||
174 | */ |
||
175 | public function addJs(string $js): WidgetTemplate { |
||
180 | |||
181 | /** |
||
182 | * Get the HTML file that contains the content of the widget. |
||
183 | * |
||
184 | * @since 15.0.0 |
||
185 | * |
||
186 | * @return string |
||
187 | */ |
||
188 | public function getContent(): string { |
||
191 | |||
192 | /** |
||
193 | * Set the HTML file that contains the content of the widget. |
||
194 | * |
||
195 | * @since 15.0.0 |
||
196 | * |
||
197 | * @param string $content |
||
198 | * |
||
199 | * @return WidgetTemplate |
||
200 | */ |
||
201 | public function setContent(string $content): WidgetTemplate { |
||
206 | |||
207 | /** |
||
208 | * Get the JS function to be called when loading the widget. |
||
209 | * |
||
210 | * @since 15.0.0 |
||
211 | * |
||
212 | * @return string |
||
213 | */ |
||
214 | public function getInitFunction(): string { |
||
217 | |||
218 | /** |
||
219 | * JavaScript function to be called when loading the widget on the |
||
220 | * dashboard |
||
221 | * |
||
222 | * @since 15.0.0 |
||
223 | * |
||
224 | * @param string $function |
||
225 | * |
||
226 | * @return WidgetTemplate |
||
227 | */ |
||
228 | public function setInitFunction(string $function): WidgetTemplate { |
||
233 | |||
234 | /** |
||
235 | * Get all WidgetSetting defined for the widget. |
||
236 | * |
||
237 | * @see WidgetSetting |
||
238 | * |
||
239 | * @since 15.0.0 |
||
240 | * |
||
241 | * @return WidgetSetting[] |
||
242 | */ |
||
243 | public function getSettings(): array { |
||
246 | |||
247 | /** |
||
248 | * Define all WidgetSetting for the widget. |
||
249 | * |
||
250 | * @since 15.0.0 |
||
251 | * |
||
252 | * @see WidgetSetting |
||
253 | * |
||
254 | * @param WidgetSetting[] $settings |
||
255 | * |
||
256 | * @return WidgetTemplate |
||
257 | */ |
||
258 | public function setSettings(array $settings): WidgetTemplate { |
||
263 | |||
264 | /** |
||
265 | * Add a WidgetSetting. |
||
266 | * |
||
267 | * @see WidgetSetting |
||
268 | * |
||
269 | * @since 15.0.0 |
||
270 | * |
||
271 | * @param WidgetSetting $setting |
||
272 | * |
||
273 | * @return WidgetTemplate |
||
274 | */ |
||
275 | public function addSetting(WidgetSetting $setting): WidgetTemplate { |
||
280 | |||
281 | /** |
||
282 | * Get a WidgetSetting by its name |
||
283 | * |
||
284 | * @see WidgetSetting::setName |
||
285 | * |
||
286 | * @since 15.0.0 |
||
287 | * |
||
288 | * @param string $key |
||
289 | * |
||
290 | * @return WidgetSetting |
||
291 | */ |
||
292 | public function getSetting(string $key): WidgetSetting { |
||
299 | |||
300 | |||
301 | /** |
||
302 | * @since 15.0.0 |
||
303 | * |
||
304 | * @return array |
||
305 | */ |
||
306 | public function jsonSerialize() { |
||
316 | |||
317 | |||
318 | } |
||
319 | |||
320 |