PluginProbe
VikBooking Hotel Booking Engine & PMS / 1.6.4
VikBooking Hotel Booking Engine & PMS v1.6.4
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
vikbooking / admin / helpers / src / notification / display / reminder.php

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

111 lines 3.3 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) 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 reminders.
16 *
17 * @since 1.15.0 (J) - 1.5.0 (WP)
18 */
19 final class VBONotificationDisplayReminder 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. In case of errors while
34 * retrieving the reminder, the response is closed. Therefore,
35 * it's assumed that this process will run during an AJAX request.
36 *
37 * @return null|object the notification display data payload.
38 */
39 public function getData()
40 {
41 $reminder_id = $this->get('id');
42 if (empty($reminder_id)) {
43 VBOHttpDocument::getInstance()->close(500, 'Empty notification reminder id to display');
44 }
45
46 $reminder = VBORemindersHelper::getInstance()->getReminder($reminder_id);
47 if (!$reminder) {
48 VBOHttpDocument::getInstance()->close(404, 'Notification reminder id not found');
49 }
50
51 // compose the notification data to display
52 $notif_data = new stdClass;
53 $notif_data->title = $reminder->title;
54 $notif_data->message = empty($reminder->descr) ? $reminder->title : $reminder->descr;
55 $notif_data->icon = $this->getIconUrl();
56
57 // check if click handler should be attached
58 if (!empty($reminder->idorder)) {
59 // register click event callback data
60 $notif_data->onclick = 'VBOCore.handleGoto';
61 $notif_data->gotourl = 'index.php?option=com_vikbooking&task=editorder&cid[]=' . $reminder->idorder;
62 if (VBOPlatformDetection::isWordPress()) {
63 $notif_data->gotourl = str_replace('index.php', 'admin.php', $notif_data->gotourl);
64 }
65 if (is_object($reminder->payload) && !empty($reminder->payload->airbnb_host_guest_review)) {
66 // append callback to trigger the host-to-guest review
67 $notif_data->gotourl .= '&notif_action=airbnb_host_guest_review';
68 // attempt to get the proper channel logo
69 $vcm_logos = VikBooking::getVcmChannelsLogo('airbnb', $get_istance = true);
70 if ($vcm_logos) {
71 $channel_logo = $vcm_logos->getSmallLogoURL();
72 if (!empty($channel_logo)) {
73 $notif_data->icon = $channel_logo;
74 }
75 }
76 }
77 } else {
78 $notif_data->onclick = null;
79 }
80
81 return $notif_data;
82 }
83
84 /**
85 * Returns the URL to the default icon for the reminders
86 * browser notifications. Custom logos are preferred.
87 *
88 * @return string|null
89 */
90 private function getIconUrl()
91 {
92 $config = VBOFactory::getConfig();
93
94 // back-end custom logo
95 $use_logo = $config->get('backlogo');
96 if (empty($use_logo) || !strcasecmp($use_logo, 'vikbooking.png')) {
97 // fallback to company (site) logo
98 $use_logo = $config->get('sitelogo');
99 }
100
101 if (!empty($use_logo) && strcasecmp($use_logo, 'vikbooking.png')) {
102 // uploaded logo found
103 $use_logo = VBO_ADMIN_URI . 'resources/' . $use_logo;
104 } else {
105 $use_logo = null;
106 }
107
108 return $use_logo;
109 }
110 }
111