PluginProbe
VikBooking Hotel Booking Engine & PMS / 1.8.15
VikBooking Hotel Booking Engine & PMS v1.8.15
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 / notification / display / operatormessage.php

operatormessage.php in VikBooking Hotel Booking Engine & PMS 1.8.15, at admin/helpers/src/notification/display/operatormessage.php

115 lines 3.9 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 Alessio Gaggii - E4J s.r.l.
6 * @copyright Copyright (C) 2025 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 * Browser notification displayer handler for a new operator message.
16 *
17 * @since 1.18.0 (J) - 1.8.0 (WP)
18 */
19 final class VBONotificationDisplayOperatormessage extends JObject implements VBONotificationDisplayer
20 {
21 /**
22 * Proxy for immediately getting the object and bind data.
23 *
24 * @param array|object $data the notification payload data to bind.
25 */
26 public static function getInstance($data = null)
27 {
28 return new static($data);
29 }
30
31 /**
32 * Composes an object with the necessary properties to display
33 * the notification in the browser.
34 *
35 * @return null|object The notification display data payload.
36 *
37 * @throws Exception
38 */
39 public function getData()
40 {
41 $id_sender = (int) $this->get('id_sender', 0);
42 if (empty($id_sender)) {
43 return null;
44 }
45
46 // get the operator record
47 $operator = (array) VikBooking::getOperatorInstance()->getOne($id_sender);
48
49 // operator picture
50 $operator_pic = $this->get('pic', $this->get('avatar', '')) ?: $operator['pic'] ?? '';
51
52 // the notification icon
53 $notif_icon = '';
54 if (!empty($operator_pic)) {
55 $notif_icon = strpos($operator_pic, 'http') === 0 ? $operator_pic : VBO_SITE_URI . 'resources/uploads/' . $operator_pic;
56 } else {
57 $notif_icon = $this->getIconUrl();
58 }
59
60 // compose notification title
61 $operator_name = $this->get('sender_name', trim(($operator['first_name'] ?? '') . ' ' . ($operator['last_name'] ?? '')));
62 $notif_title = JText::sprintf('VBO_MESSAGE_FROM', $operator_name);
63
64 // compose the notification data to display
65 $notif_data = new stdClass;
66 $notif_data->title = $notif_title;
67 $notif_data->message = strip_tags($this->get('message', ''));
68 $notif_data->icon = $notif_icon;
69 $notif_data->onclick = 'VBOCore.handleDisplayWidgetNotification';
70 $notif_data->gotourl = VBOFactory::getPlatform()->getUri()->admin("index.php?option=com_vikbooking&view=taskmanager", false);
71
72 // set additional properties to the notification payload related to the operator message
73 $notif_data->widget_id = 'operators_chat';
74 $notif_data->id_sender = $this->get('id_sender', null);
75 $notif_data->id_message = $this->get('id', null);
76 $notif_data->context_id = $this->get('id_context', null);
77 $notif_data->context_alias = $this->get('context', null);
78 // set additional data options to ensure the conversation will be found
79 $notif_data->_options = [
80 '_web' => 1,
81 'context_id' => $this->get('id_context', null),
82 'context_alias' => $this->get('context', null),
83 ];
84
85 return $notif_data;
86 }
87
88 /**
89 * Returns the URL to the default icon for the history
90 * browser notifications. Custom logos are preferred.
91 *
92 * @return ?string
93 */
94 private function getIconUrl()
95 {
96 $config = VBOFactory::getConfig();
97
98 // back-end custom logo
99 $use_logo = $config->get('backlogo');
100 if (empty($use_logo) || !strcasecmp($use_logo, 'vikbooking.png')) {
101 // fallback to company (site) logo
102 $use_logo = $config->get('sitelogo');
103 }
104
105 if (!empty($use_logo) && strcasecmp($use_logo, 'vikbooking.png')) {
106 // uploaded logo found
107 $use_logo = VBO_ADMIN_URI . 'resources/' . $use_logo;
108 } else {
109 $use_logo = null;
110 }
111
112 return $use_logo;
113 }
114 }
115