| 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 booking history event. |
| 16 |
* |
| 17 |
* @since 1.15.0 (J) - 1.5.0 (WP) |
| 18 |
*/ |
| 19 |
final class VBONotificationDisplayHistory 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 |
// history event type |
| 47 |
$ev_type = $this->get('type', ''); |
| 48 |
|
| 49 |
// booking source (channel) |
| 50 |
$channel_source = $this->get('channel', ''); |
| 51 |
|
| 52 |
// customer picture |
| 53 |
$customer_pic = $this->get('pic', ''); |
| 54 |
|
| 55 |
// the notification icon |
| 56 |
$notif_icon = ''; |
| 57 |
if (!empty($channel_source)) { |
| 58 |
$ch_logo_obj = VikBooking::getVcmChannelsLogo($channel_source, true); |
| 59 |
$notif_icon = is_object($ch_logo_obj) ? $ch_logo_obj->getSmallLogoURL() : ''; |
| 60 |
} elseif (!empty($customer_pic)) { |
| 61 |
$notif_icon = strpos($customer_pic, 'http') === 0 ? $customer_pic : VBO_SITE_URI . 'resources/uploads/' . $customer_pic; |
| 62 |
} |
| 63 |
|
| 64 |
if (empty($notif_icon)) { |
| 65 |
$notif_icon = $this->getIconUrl(); |
| 66 |
} |
| 67 |
|
| 68 |
// get history helper |
| 69 |
$history_obj = VikBooking::getBookingHistoryInstance(); |
| 70 |
|
| 71 |
// compose notification title |
| 72 |
$notif_title = $history_obj->validType($ev_type, true); |
| 73 |
|
| 74 |
// compose the notification data to display |
| 75 |
$notif_data = new stdClass; |
| 76 |
$notif_data->title = $notif_title; |
| 77 |
$notif_data->message = $this->get('descr', ''); |
| 78 |
$notif_data->icon = $notif_icon; |
| 79 |
$notif_data->onclick = 'VBOCore.handleDisplayWidgetNotification'; |
| 80 |
$notif_data->gotourl = VBOFactory::getPlatform()->getUri()->admin("index.php?option=com_vikbooking&task=editorder&cid[]={$booking_id}", false); |
| 81 |
|
| 82 |
// set additional properties to the (Web, not Push) notification payload |
| 83 |
$notif_data->widget_id = 'booking_details'; |
| 84 |
// data options for a Web notification should NOT set a "type" or this will be overridden |
| 85 |
$notif_data->_options = [ |
| 86 |
'_web' => 1, |
| 87 |
'title' => $notif_data->title, |
| 88 |
'message' => $notif_data->message, |
| 89 |
'bid' => $booking_id, |
| 90 |
]; |
| 91 |
|
| 92 |
return $notif_data; |
| 93 |
} |
| 94 |
|
| 95 |
/** |
| 96 |
* Returns the URL to the default icon for the history |
| 97 |
* browser notifications. Custom logos are preferred. |
| 98 |
* |
| 99 |
* @return string|null |
| 100 |
*/ |
| 101 |
private function getIconUrl() |
| 102 |
{ |
| 103 |
$config = VBOFactory::getConfig(); |
| 104 |
|
| 105 |
// back-end custom logo |
| 106 |
$use_logo = $config->get('backlogo'); |
| 107 |
if (empty($use_logo) || !strcasecmp($use_logo, 'vikbooking.png')) { |
| 108 |
// fallback to company (site) logo |
| 109 |
$use_logo = $config->get('sitelogo'); |
| 110 |
} |
| 111 |
|
| 112 |
if (!empty($use_logo) && strcasecmp($use_logo, 'vikbooking.png')) { |
| 113 |
// uploaded logo found |
| 114 |
$use_logo = VBO_ADMIN_URI . 'resources/' . $use_logo; |
| 115 |
} else { |
| 116 |
$use_logo = null; |
| 117 |
} |
| 118 |
|
| 119 |
return $use_logo; |
| 120 |
} |
| 121 |
} |
| 122 |
|