PluginProbe
VikBooking Hotel Booking Engine & PMS / 1.7.0
VikBooking Hotel Booking Engine & PMS v1.7.0
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
vikbooking / admin / helpers / widgets / aitools.php

aitools.php in VikBooking Hotel Booking Engine & PMS 1.7.0, at admin/helpers/widgets/aitools.php

127 lines 3.2 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 com_vikbooking
5 * @author Alessio Gaggii - E4J srl
6 * @copyright Copyright (C) 2024 E4J srl. All rights reserved.
7 * @license GNU General Public License version 2 or later; see LICENSE
8 * @link https://vikwp.com
9 */
10
11 defined('ABSPATH') or die('No script kiddies please!');
12
13 /**
14 * Class handler for admin widget "AI Tools".
15 *
16 * @since 1.17 (J) - 1.7 (WP)
17 */
18 class VikBookingAdminWidgetAitools extends VikBookingAdminWidget
19 {
20 /**
21 * @inheritDOc
22 */
23 public function __construct()
24 {
25 // call parent constructor
26 parent::__construct();
27
28 $this->widgetName = JText::translate('VBO_W_AITOOLS_TITLE');
29 $this->widgetDescr = JText::translate('VBO_W_AITOOLS_DESCR');
30 $this->widgetId = basename(__FILE__, '.php');
31
32 $this->widgetIcon = '<i class="' . VikBookingIcons::i('magic') . '"></i>';
33 $this->widgetStyleName = 'violet';
34 }
35
36 /**
37 * @inheritDoc
38 */
39 public function getPriority()
40 {
41 // give this widget a higher priority
42 return 15;
43 }
44
45 /**
46 * @inheritDoc
47 */
48 public function preflight()
49 {
50 // can be used only if VCM is installed and the account has the AI channel
51 return class_exists('VikChannelManager') && defined('VikChannelManagerConfig::AI') && VikChannelManager::getChannel(VikChannelManagerConfig::AI);
52 }
53
54 /**
55 * @inheritDoc
56 */
57 public function preload()
58 {
59 $options = [
60 'version' => VIKCHANNELMANAGER_SOFTWARE_VERSION ?? VIKBOOKING_SOFTWARE_VERSION,
61 ];
62
63 // manually load required dependencies
64 JHtml::fetch('script', VCM_ADMIN_URI . 'layouts/ai/assistant/aitools.js', $options);
65 JHtml::fetch('stylesheet', VCM_ADMIN_URI . 'layouts/ai/assistant/aitools.css', $options);
66
67 // language definitions
68 JText::script('VBO_AI_ASSISTANT_DISCLAIMER');
69 JText::script('VBO_AI_ASSISTANT_DISCOVER_HINT');
70 JText::script('VBO_AI_ASSISTANT_DISCOVER_TITLE');
71 }
72
73 /**
74 * @inheritDoc
75 */
76 public function render(VBOMultitaskData $data = null)
77 {
78 $auto_focus = false;
79 $prompt = null;
80
81 // if we are rendering the widget on a modal, register a script to prevent the latter
82 // from dismissing whenever the ESC key is pressed
83 if ($data && $data->isModalRendering()) {
84 $auto_focus = true;
85 $prompt = (array) $this->getOption('prompt', null);
86 ?>
87 <script>
88 (function() {
89 const vbo_modal_ai_assistant_dismiss = (event) => {
90 if (event.key == 'Escape') {
91 event.preventDefault();
92 event.stopPropagation();
93 return false;
94 }
95 };
96
97 document.addEventListener('keyup', vbo_modal_ai_assistant_dismiss);
98
99 document.addEventListener(VBOCore.widget_modal_dismissed + '<?php echo $data->getModalJsIdentifier(); ?>', (e) => {
100 document.removeEventListener('keyup', vbo_modal_ai_assistant_dismiss);
101 VBOCore.emitEvent('vbo-widget-ai-tools-dismissed');
102 });
103 })();
104 </script>
105 <?php
106 }
107
108 // display by using a specific layout provided by VCM
109 echo JLayoutHelper::render(
110 'ai.assistant.chat',
111 [
112 // prevent the layout from loading the required assets
113 'load_assets' => false,
114 // auto-focus textarea
115 'auto_focus' => $auto_focus,
116 // default prompt
117 'prompt' => $prompt,
118 ],
119 null,
120 [
121 'client' => 'administrator',
122 'component' => 'com_vikchannelmanager',
123 ]
124 );
125 }
126 }
127