PluginProbe
VikBooking Hotel Booking Engine & PMS / trunk
VikBooking Hotel Booking Engine & PMS vtrunk
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 / dooraccess / provider / offline.php

offline.php in VikBooking Hotel Booking Engine & PMS trunk, at admin/helpers/src/dooraccess/provider/offline.php

264 lines 7.6 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 E4J s.r.l.
6 * @copyright Copyright (C) 2026 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 * Door Access integration provider for "Offline" Fixed Code (no API connections).
16 *
17 * @since 1.18.15 (J) - 1.8.15 (WP)
18 */
19 final class VBODooraccessProviderOffline extends VBODooraccessIntegrationAware
20 {
21 /**
22 * @var bool Allows sorting.
23 */
24 public $isOffline = true;
25
26 /**
27 * @inheritDoc
28 */
29 public function getAlias()
30 {
31 return basename(__FILE__, '.php');
32 }
33
34 /**
35 * @inheritDoc
36 */
37 public function getName()
38 {
39 return 'Offline Fixed Code';
40 }
41
42 /**
43 * @inheritDoc
44 */
45 public function getShortName()
46 {
47 return 'Offline';
48 }
49
50 /**
51 * @inheritDoc
52 */
53 public function getIcon()
54 {
55 return '<i class="' . VikBookingIcons::i('key') . '"></i>';
56 }
57
58 /**
59 * @inheritDoc
60 */
61 public function getParams()
62 {
63 return [
64 '_help' => [
65 'type' => 'custom',
66 'html' => '<p class="info">' . JText::translate('VBO_DAC_OFFLINE_INTGR_HELP') . '</p>',
67 ],
68 'device' => [
69 'type' => 'text',
70 'label' => JText::translate('VBTRKDEVICE'),
71 'help' => rtrim(JText::translate('VBO_LOCK_NAME'), '.') . '.',
72 ],
73 'code' => [
74 'type' => 'text',
75 'label' => JText::translate('VBO_PASSCODE'),
76 'help' => rtrim(JText::translate('VBO_FIXED_CODE'), '.') . '.',
77 ],
78 'ai' => [
79 'type' => 'checkbox',
80 'label' => JText::translate('VBO_AI_SUPPORT'),
81 'help' => JText::translate('VBO_DAC_AI_SUPPORT_HELP'),
82 'default' => 1,
83 ],
84 'notes' => [
85 'type' => 'textarea',
86 'label' => JText::translate('ORDER_NOTES'),
87 'help' => JText::translate('VBO_DAC_UNLOCK_INSTR'),
88 ],
89 ];
90 }
91
92 /**
93 * @inheritDoc
94 */
95 public function canUnlockDevices()
96 {
97 // this method is called when the integration has loaded its profile record
98 // we return true only if the apposite AI setting is enabled
99
100 $settings = $this->getSettings();
101
102 return !empty($settings['ai']);
103 }
104
105 /**
106 * Device capability implementation to unlock a device.
107 *
108 * @param VBODooraccessIntegrationDevice $device The device executing the capability.
109 * @param ?array $options Optional settings populated from capability parameters.
110 *
111 * @return VBODooraccessDeviceCapabilityResult
112 */
113 public function unlockDevice(VBODooraccessIntegrationDevice $device, ?array $options = null)
114 {
115 // obtain integration settings
116 $settings = $this->getSettings();
117
118 if (empty($settings['code'])) {
119 throw new Exception('Error unlocking the device due to invalid settings.', 500);
120 }
121
122 return (new VBODooraccessDeviceCapabilityResult)
123 ->setText(
124 sprintf(
125 'The device "%s" can be unlocked with the code: %s.%s',
126 $device->getName(),
127 $settings['code'],
128 (!empty($settings['notes']) ? " \n{$settings['notes']}" : '')
129 )
130 );
131 }
132
133 /**
134 * @inheritDoc
135 */
136 public function createBookingDoorAccess(VBODooraccessIntegrationDevice $device, int $listingId, VBOBookingRegistry $registry)
137 {
138 // access the integration settings
139 $settings = $this->getSettings();
140
141 if (empty($settings['code'])) {
142 throw new Exception('Could not create passcode due to invalid settings.', 500);
143 }
144
145 // build result properties to bind
146 $resultProps = [
147 'code' => (string) $settings['code'],
148 'listingId' => $listingId,
149 ];
150
151 // get the listing name
152 $listingData = VikBooking::getRoomInfo($resultProps['listingId'], ['name'], true);
153 $listingName = sprintf('%s: ', $listingData['name'] ?? '');
154
155 // wrap and return the device capability result object
156 return (new VBODooraccessDeviceCapabilityResult($resultProps))
157 ->setPasscode($resultProps['code'])
158 ->setText($listingName . JText::sprintf('VBO_PASSCODE_GEN_OK_DEVICE', $resultProps['code'], $device->getName()));
159 }
160
161 /**
162 * @inheritDoc
163 */
164 public function modifyBookingDoorAccess(VBODooraccessIntegrationDevice $device, int $listingId, VBOBookingRegistry $registry)
165 {
166 // process the modification as a new door access creation
167 return $this->createBookingDoorAccess($device, $listingId, $registry);
168 }
169
170 /**
171 * @inheritDoc
172 */
173 public function cancelBookingDoorAccess(VBODooraccessIntegrationDevice $device, int $listingId, VBOBookingRegistry $registry)
174 {
175 // nothing to cancel, but prevent unwanted errors
176 return null;
177 }
178
179 /**
180 * @inheritDoc
181 */
182 public function handleUnlockDevice(VBODooraccessIntegrationDevice $device)
183 {
184 // unlock the requested device
185 return $this->unlockDevice($device);
186 }
187
188 /**
189 * @inheritDoc
190 */
191 public function getPasscodeFromHistoryResult(array $resultProperties)
192 {
193 // creating a passcode should bind its value within the device capability result object
194 return $resultProperties['code'] ?? null;
195 }
196
197 /**
198 * @inheritDoc
199 */
200 protected function fetchRemoteDevices()
201 {
202 $devices = [];
203
204 // obtain settings after initializing the transporter
205 $settings = $this->getSettings();
206
207 if (empty($settings['device'])) {
208 throw new Exception('Invalid settings. Please provide a default name for the lock.', 500);
209 }
210
211 if (empty($settings['code'])) {
212 throw new Exception('Invalid settings. Please provide the lock fixed access code to be used offline.', 500);
213 }
214
215 return [
216 // add one fixed/offline lock
217 [
218 'id' => uniqid(),
219 'name' => $settings['device'],
220 'ts' => time(),
221 ],
222 ];
223 }
224
225 /**
226 * @inheritDoc
227 */
228 protected function decorateDeviceProperties(VBODooraccessIntegrationDevice $decorator, array $device)
229 {
230 // set device ID
231 $decorator->setID($device['id']);
232
233 // set device name
234 $decorator->setName($device['name']);
235
236 // set device description
237 $decorator->setDescription('Fixed access code');
238
239 // set device icon
240 $decorator->setIcon('<i class="' . VikBookingIcons::i('lock') . '"></i>');
241
242 // set device model
243 $decorator->setModel(date('Y.m.d'));
244
245 // set dummy battery level
246 $decorator->setBatteryLevel(100.00);
247
248 // set device capabilities
249 $decorator->setCapabilities([
250 // unlock device
251 $this->createDeviceCapability([
252 'id' => 'unlock_device',
253 'title' => JText::translate('VBDASHUNLOCK'),
254 'description' => JText::translate('VBO_UNLOCK_DEVICE_HELP'),
255 'icon' => '<i class="' . VikBookingIcons::i('unlock') . '"></i>',
256 'callback' => 'unlockDevice',
257 ]),
258 ]);
259
260 // set device payload
261 $decorator->setPayload($device);
262 }
263 }
264