PluginProbe
VikBooking Hotel Booking Engine & PMS / 1.8.9
VikBooking Hotel Booking Engine & PMS v1.8.9
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 / src / chat / user / admin.php

admin.php in VikBooking Hotel Booking Engine & PMS 1.8.9, at admin/helpers/src/chat/user/admin.php

133 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 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 * Chat user admin wrapper.
16 *
17 * @since 1.8
18 */
19 class VBOChatUserAdmin extends VBOChatUseraware implements VBOChatNotifiable
20 {
21 use VBOChatNotificationWebpush;
22
23 /** @var JUser */
24 protected $user;
25
26 /**
27 * Class constructor.
28 *
29 * @param JUser|null The user instance.
30 */
31 public function __construct($user = null)
32 {
33 $this->user = $user ?: JFactory::getUser();
34
35 if ($this->user->guest) {
36 throw new RuntimeException('The logged in user is not an administrator.', 403);
37 }
38 }
39
40 /**
41 * @inheritDoc
42 *
43 * @see VBOChatUser
44 */
45 public function getID()
46 {
47 // 0 always identifies an administrator
48 return 0;
49 }
50
51 /**
52 * @inheritDoc
53 *
54 * @see VBOChatUser
55 */
56 public function getName()
57 {
58 return $this->user->name;
59 }
60
61 /**
62 * @inheritDoc
63 *
64 * @see VBOChatUser
65 */
66 public function getAvatar()
67 {
68 $config = VBOFactory::getConfig();
69
70 // prefer the back-end logo image
71 $logo = $config->getString('backlogo');
72
73 if (!$logo) {
74 // back-end image not configured, use the front-end logo image
75 $logo = $config->getString('sitelogo');
76 }
77
78 if ($logo)
79 {
80 // construct full image URI
81 $logo = VBO_ADMIN_URI . 'resources/' . $logo;
82 }
83
84 return $logo;
85 }
86
87 /**
88 * @inheritDoc
89 *
90 * @see VBOChatUser
91 */
92 public function can(string $scope, ?VBOChatContext $context = null)
93 {
94 return true;
95 }
96
97 /**
98 * @inheritDoc
99 *
100 * @see VBOChatNotifiable
101 */
102 public function scheduleNotification(VBOChatMessage $message, VBOChatUser $user)
103 {
104 /** @var VBOChatContext */
105 $context = $message->getContext();
106
107 if ($context->getAlias() === 'session') {
108 /** @var array */
109 $metadata = $context->getMetadata();
110
111 // proceed only in case the AI is actually supported and the current context
112 // still supports automatic AI replies
113 if (VBOChatUserAi::isSupported() && $metadata['use_ai']) {
114 // obtain the last 2 messages for this context
115 $lastMessages = VBOFactory::getChatMediator()->getMessages((new VBOChatSearch)->limit(2)->withContext($context));
116
117 // send a notification only when the session starts (first message sent)
118 if (count($lastMessages) > 1) {
119 // the thread owns 2+ messages, we don't need to send further notifications
120 return;
121 }
122 }
123 }
124
125 /**
126 * Enqueues a message for the admin within the notification center.
127 *
128 * @see VBOChatNotificationWebpush
129 */
130 $this->sendWebPushNotification($message, $user);
131 }
132 }
133