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 / widgets / operators_chat.php

operators_chat.php in VikBooking Hotel Booking Engine & PMS trunk, at admin/helpers/widgets/operators_chat.php

93 lines 2.8 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) 2025 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 "operators chat".
15 *
16 * @since 1.18.0 (J) - 1.8.0 (WP)
17 */
18 class VikBookingAdminWidgetOperatorsChat extends VBOChatWidgetAdmin
19 {
20 /**
21 * A list holding all the supported chat categories.
22 *
23 * @var string[]
24 * @since 1.8.8
25 */
26 protected $involvedCategories = ['task'];
27
28 /**
29 * Class constructor will define the widget name and identifier.
30 */
31 public function __construct()
32 {
33 // call parent constructor
34 parent::__construct();
35
36 $this->widgetName = JText::translate('VBO_W_OPERATORSCHAT_TITLE');
37 $this->widgetDescr = JText::translate('VBO_W_OPERATORSCHAT_DESCR');
38 $this->widgetId = basename(__FILE__, '.php');
39
40 $this->widgetIcon = '<i class="' . VikBookingIcons::i('comments') . '"></i>';
41 $this->widgetStyleName = 'light-red';
42 }
43
44 /**
45 * Checks for new notifications by using the previous preloaded watch-data.
46 *
47 * @param ?VBONotificationWatchdata $watch_data The preloaded watch-data object.
48 *
49 * @return array Data object to watch next and notifications array.
50 *
51 * @see preload()
52 */
53 public function getNotifications(?VBONotificationWatchdata $watch_data = null)
54 {
55 // default empty values
56 $watch_next = null;
57 $notifications = null;
58
59 if (!$watch_data) {
60 return [$watch_next, $notifications];
61 }
62
63 $latest_message_id = (int) $watch_data->get('message_id', 0);
64 if (!$latest_message_id) {
65 return [$watch_next, $notifications];
66 }
67
68 // get the latest message for the administrators
69 $messages = VBOFactory::getChatMediator()->getMessages(
70 (new VBOChatSearch)
71 ->aggregate()
72 ->forCategories($this->involvedCategories)
73 ->sender(0, false)
74 // search only the messages newer than the latest ID
75 ->message($latest_message_id, '>')
76 ->limit(3)
77 );
78
79 if (!$messages) {
80 return [$watch_next, $notifications];
81 }
82
83 // build the next watch data for this widget
84 $watch_next = new stdClass;
85 $watch_next->message_id = $messages[0]->getID();
86
87 // compose the notification(s) to dispatch
88 $notifications = VBONotificationScheduler::getInstance()->buildOperatorsChatDataObjects($messages);
89
90 return [$watch_next, $notifications];
91 }
92 }
93