PluginProbe
VikBooking Hotel Booking Engine & PMS / 1.8.16
VikBooking Hotel Booking Engine & PMS v1.8.16
1.8.16 1.8.15 1.8.14 1.8.13 1.8.12 1.8.11 1.8.10 1.8.9 1.8.6 1.8.7 1.8.8 trunk 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 All 37 releases
← All changes | admin/helpers/admin_widget.php +176 -5 1.6.4 → 1.8.16 View file →
@@ -92,13 +92,24 @@
92 92 */
93 93 protected $widgetId = null;
94 94
95 95 /**
96 + * The widget multitask options registry.
97 + *
98 + * @var VBOMultitaskOptions
99 + *
100 + * @since 1.16.5 (J) - 1.6.5 (WP)
101 + */
102 + protected $options;
103 +
104 + /**
96 105 * Class constructors should define some vars for the widget in use.
97 106 */
98 107 public function __construct()
99 108 {
100 109 $this->vbo_app = VikBooking::getVboApplication();
110 + $this->datesep = VikBooking::getDateSeparator(true);
111 +
101 112 $nowdf = VikBooking::getDateFormat(true);
102 113 if ($nowdf == "%d/%m/%Y") {
103 114 $this->df = 'd/m/Y';
104 115 } elseif ($nowdf == "%m/%d/%Y") {
@@ -105,12 +116,49 @@
105 116 $this->df = 'm/d/Y';
106 117 } else {
107 118 $this->df = 'Y/m/d';
108 119 }
109 - $this->datesep = VikBooking::getDateSeparator(true);
120 +
121 + $this->options = VBOMultitaskOptions::getInstance();
110 122 }
111 123
112 124 /**
125 + * Tells if the admin-widget can be installed on the current environment.
126 + *
127 + * @return bool
128 + *
129 + * @since 1.16.10 (J) - 1.6.10 (WP)
130 + */
131 + public function preflight()
132 + {
133 + /**
134 + * Trigger event to let external plugins to choose whether this widget should be supported or not.
135 + *
136 + * @param string $widgetId The widget identifier.
137 + *
138 + * @return bool False to drop support to this widget.
139 + *
140 + * @since 1.18 (J) - 1.8 (WP)
141 + */
142 + $results = VBOFactory::getPlatform()->getDispatcher()->filter('onPreflightAdminWidget', [$this->widgetId]);
143 +
144 + // supported only in case none of the plugins attached to this event returned FALSE
145 + return !in_array(false, $results, true);
146 + }
147 +
148 + /**
149 + * Returns the admin-widget priority for a custom ordering.
150 + *
151 + * @return int
152 + *
153 + * @since 1.16.10 (J) - 1.6.10 (WP)
154 + */
155 + public function getPriority()
156 + {
157 + return 10;
158 + }
159 +
160 + /**
113 161 * Gets the name of the current widget.
114 162 *
115 163 * @return string the widget name.
116 164 */
@@ -208,9 +256,9 @@
208 256 * Extending classes needing to periodically watch for new events and capable
209 257 * of emitting browser notifications, can override this method. The last data
210 258 * to watch should be returned during the preloading. To be used with list().
211 259 *
212 - * @param VBONotificationWatchdata $watch_data the preloaded watch-data object.
260 + * @param ?VBONotificationWatchdata $watch_data the preloaded watch-data object.
213 261 *
214 262 * @return array data object to watch next and notifications array.
215 263 *
216 264 * @see preload()
@@ -216,9 +264,9 @@
216 264 * @see preload()
217 265 *
218 266 * @since 1.15.0 (J) - 1.5.0 (WP)
219 267 */
220 - public function getNotifications(VBONotificationWatchdata $watch_data = null)
268 + public function getNotifications(?VBONotificationWatchdata $watch_data = null)
221 269 {
222 270 $watch_next = null;
223 271 $notifications = null;
224 272
@@ -225,16 +273,139 @@
225 273 return [$watch_next, $notifications];
226 274 }
227 275
228 276 /**
277 + * Default method to return a list of browser events to dispatch.
278 + * Extending classes needing to periodically watch for new events
279 + * and capable of emitting browser events, can override this method.
280 + *
281 + * @param ?VBONotificationWatchdata $watch_data the preloaded watch-data object.
282 + *
283 + * @return array list of browser events to emit.
284 + *
285 + * @see preload()
286 + *
287 + * @since 1.16.8 (J) - 1.6.8 (WP)
288 + */
289 + public function getNotificationEvents(?VBONotificationWatchdata $watch_data = null)
290 + {
291 + return [];
292 + }
293 +
294 + /**
295 + * Binds the widget options at runtime when multitask data is available.
296 + * Options live on a separate layer than regular multitask data.
297 + *
298 + * @param VBOMultitaskData|VBOMultitaskOptions|array|object $options options to bind.
299 + *
300 + * @return self
301 + *
302 + * @since 1.16.5 (J) - 1.6.5 (WP)
303 + */
304 + public function bindOptions($options)
305 + {
306 + if ($options instanceof VBOMultitaskData) {
307 + // set options by extracting them from multitask data
308 + $this->options->setProperties($options->getDataOptions());
309 + } elseif ($options instanceof VBOMultitaskOptions) {
310 + // replace options with given instance
311 + $this->options = $options;
312 + } elseif (is_array($options) || is_object($options)) {
313 + // bind new options
314 + $this->options = VBOMultitaskOptions::getInstance($options);
315 + }
316 +
317 + return $this;
318 + }
319 +
320 + /**
321 + * Gets all widget options previously set through Multitask data.
322 + * Options live on a separate layer than regular Multitask data.
323 + *
324 + * @param bool $public true to get only the public options.
325 + *
326 + * @return array associative list of options, if any.
327 + *
328 + * @since 1.16.5 (J) - 1.6.5 (WP)
329 + */
330 + public function getOptions($public = false)
331 + {
332 + return $this->options->getProperties($public);
333 + }
334 +
335 + /**
336 + * Proxy to access the multitask options object.
337 + *
338 + * @return VBOMultitaskOptions
339 + *
340 + * @since 1.16.5 (J) - 1.6.5 (WP)
341 + */
342 + public function options()
343 + {
344 + return $this->options;
345 + }
346 +
347 + /**
348 + * Sets a widget option value.
349 + *
350 + * @param string $key the option key identifier.
351 + * @param mixed $value the option value to set.
352 + *
353 + * @return self
354 + *
355 + * @since 1.16.5 (J) - 1.6.5 (WP)
356 + */
357 + public function setOption($key, $value)
358 + {
359 + $this->options->set($key, $value);
360 +
361 + return $this;
362 + }
363 +
364 + /**
365 + * Gets the value for the given widget option key.
366 + *
367 + * @param string $key the option key identifier.
368 + * @param mixed $default the default value to get.
369 + *
370 + * @return mixed
371 + *
372 + * @since 1.16.5 (J) - 1.6.5 (WP)
373 + */
374 + public function getOption($key, $default = null)
375 + {
376 + return $this->options->get($key, $default);
377 + }
378 +
379 + /**
380 + * Returns an associative array with the current widget details.
381 + * Method's visibility should never change from public, because
382 + * the controller may call it, and widgets may override it.
383 + *
384 + * @return array
385 + *
386 + * @since 1.16.7 (J) - 1.6.7 (WP)
387 + */
388 + public function getWidgetDetails()
389 + {
390 + return [
391 + 'id' => $this->getIdentifier(),
392 + 'name' => $this->getName(),
393 + 'descr' => $this->getDescription(),
394 + 'icon' => $this->getIcon(),
395 + 'style' => $this->getStyleName(),
396 + ];
397 + }
398 +
399 + /**
229 400 * Extending Classes should define this method to render the actual
230 401 * output of the admin widget. Multitask data can be passed along.
231 402 *
232 - * @param VBOMultitaskData $data optional multitask data object.
403 + * @param ?VBOMultitaskData $data optional multitask data object.
233 404 *
234 405 * @since 1.15.0 (J) - 1.5.0 (WP) type hint added for $data argument.
235 406 */
236 - abstract public function render(VBOMultitaskData $data = null);
407 + abstract public function render(?VBOMultitaskData $data = null);
237 408
238 409 /**
239 410 * Returns the default icon for a widget.
240 411 *