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 / chat / user / admin.php

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

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