PluginProbe
VikBooking Hotel Booking Engine & PMS / 1.8.16
VikBooking Hotel Booking Engine & PMS v1.8.16
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
← All changes | admin/helpers/src/notification/display/message.php +117 -0 1.6.3 → 1.8.16 View file →
@@ -1,0 +1,117 @@
1 +<?php
2 +/**
3 + * @package VikBooking
4 + * @subpackage core
5 + * @author Alessio Gaggii - E4J s.r.l.
6 + * @copyright Copyright (C) 2022 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 guest message.
16 + *
17 + * @since 1.15.0 (J) - 1.5.0 (WP)
18 + */
19 +final class VBONotificationDisplayMessage 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 + $booking_id = (int)$this->get('idorder', 0);
42 + if (empty($booking_id)) {
43 + return null;
44 + }
45 +
46 + // customer picture
47 + $customer_pic = $this->get('pic', '');
48 +
49 + // channel logo
50 + $channel_logo = $this->get('channel_logo', '');
51 +
52 + // the notification icon
53 + $notif_icon = '';
54 + if (!empty($customer_pic)) {
55 + $notif_icon = strpos($customer_pic, 'http') === 0 ? $customer_pic : VBO_SITE_URI . 'resources/uploads/' . $customer_pic;
56 + } elseif (!empty($channel_logo)) {
57 + $notif_icon = $channel_logo;
58 + } else {
59 + $notif_icon = $this->getIconUrl();
60 + }
61 +
62 + // compose notification title
63 + $conv_subject = $this->get('subject', '');
64 + $guest_name = $this->get('first_name', '') . ' ' . $this->get('last_name', '');
65 + $notif_title = $guest_name . (!empty($conv_subject) ? (' - ' . $conv_subject) : '');
66 +
67 + // compose the notification data to display
68 + $notif_data = new stdClass;
69 + $notif_data->title = $notif_title;
70 + $notif_data->message = $this->get('content', '');
71 + $notif_data->icon = $notif_icon;
72 + $notif_data->onclick = 'VBOCore.handleDisplayWidgetNotification';
73 + $notif_data->gotourl = VBOFactory::getPlatform()->getUri()->admin("index.php?option=com_vikbooking&task=editorder&cid[]={$booking_id}", false);
74 +
75 + // set additional properties to the notification payload related to the guest message
76 + $notif_data->widget_id = 'guest_messages';
77 + $notif_data->channel = $this->get('channel', null);
78 + $notif_data->id_order = $booking_id;
79 + $notif_data->id_customer = $this->get('id_customer', null);
80 + $notif_data->id_message = $this->get('id_message', null);
81 + $notif_data->id_thread = $this->get('id_thread', null);
82 + // set additional data options to ensure the conversation will be found
83 + $notif_data->_options = [
84 + '_web' => 1,
85 + 'bid' => $booking_id,
86 + ];
87 +
88 + return $notif_data;
89 + }
90 +
91 + /**
92 + * Returns the URL to the default icon for the history
93 + * browser notifications. Custom logos are preferred.
94 + *
95 + * @return string|null
96 + */
97 + private function getIconUrl()
98 + {
99 + $config = VBOFactory::getConfig();
100 +
101 + // back-end custom logo
102 + $use_logo = $config->get('backlogo');
103 + if (empty($use_logo) || !strcasecmp($use_logo, 'vikbooking.png')) {
104 + // fallback to company (site) logo
105 + $use_logo = $config->get('sitelogo');
106 + }
107 +
108 + if (!empty($use_logo) && strcasecmp($use_logo, 'vikbooking.png')) {
109 + // uploaded logo found
110 + $use_logo = VBO_ADMIN_URI . 'resources/' . $use_logo;
111 + } else {
112 + $use_logo = null;
113 + }
114 +
115 + return $use_logo;
116 + }
117 +}