PluginProbe
VikBooking Hotel Booking Engine & PMS / 1.8.6
VikBooking Hotel Booking Engine & PMS v1.8.6
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 1.7.3 All 36 releases
vikbooking / admin / helpers / src / multitask / options.php

options.php in VikBooking Hotel Booking Engine & PMS 1.8.6, at admin/helpers/src/multitask/options.php

89 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package VikBooking
4 * @subpackage core
5 * @author Alessio Gaggii - E4J s.r.l.
6 * @copyright Copyright (C) 2022 E4J s.r.l. All Rights Reserved.
7 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
8 * @link https://vikwp.com
9 */
10
11 // No direct access
12 defined('ABSPATH') or die('No script kiddies please!');
13
14 /**
15 * Defines a registry of options to be binded to an admin widget. Options
16 * are available as multitask data, but they live on a separate layer.
17 *
18 * @since 1.16.5 (J) - 1.6.5 (WP)
19 */
20 final class VBOMultitaskOptions extends JObject
21 {
22 /**
23 * Proxy for immediately accessing the object and bind data.
24 *
25 * @param array|object $data the options data to bind.
26 */
27 public static function getInstance($data = null)
28 {
29 return new static($data);
30 }
31
32 /**
33 * Attempts to fetch the booking id from the options set. The
34 * booking ID could be a VikBooking ID or an OTA ID as well.
35 *
36 * @param string $key optional option key to fetch from.
37 *
38 * @return int|string the booking id found, or 0.
39 */
40 public function fetchBookingId($key = '')
41 {
42 $values = [
43 $this->get('id'),
44 $this->get('bid'),
45 $this->get('booking_id'),
46 $this->get('id_order'),
47 ];
48
49 if ($key) {
50 // prepend option value for the given key
51 array_unshift($values, $this->get($key));
52 }
53
54 foreach (array_filter($values) as $id) {
55 // do not cast to integer if the booking contains non-number characters
56 return preg_match("/^[0-9]+$/", $id) ? (int)$id : $id;
57 }
58
59 return 0;
60 }
61
62 /**
63 * Detects if the options come from a Push notification message posted
64 * by the ServiceWorker to the client application during rendering.
65 * Can also detect if it's a Web Notification payload.
66 *
67 * @param bool $web_or_push true for both, false only for Push.
68 *
69 * @return bool
70 */
71 public function gotPushData($web_or_push = true)
72 {
73 if ($web_or_push && !$this->get('_push') && !$this->get('_web')) {
74 // not a Push notification, nor a Web notification
75 return false;
76 }
77
78 if (!$web_or_push && !$this->get('_push')) {
79 // not a Push notification
80 return false;
81 }
82
83 $title = $this->get('title');
84 $message = $this->get('message');
85
86 return (isset($title) || isset($message));
87 }
88 }
89