| 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 |
|