| 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 |
public function getData() |
| 38 |
{ |
| 39 |
$booking_id = (int)$this->get('idorder', 0); |
| 40 |
if (empty($booking_id)) { |
| 41 |
return null; |
| 42 |
} |
| 43 |
|
| 44 |
// history event type |
| 45 |
$ev_type = $this->get('type', ''); |
| 46 |
|
| 47 |
// booking source (channel) |
| 48 |
$channel_source = $this->get('channel', ''); |
| 49 |
|
| 50 |
// customer picture |
| 51 |
$customer_pic = $this->get('pic', ''); |
| 52 |
|
| 53 |
// the notification icon |
| 54 |
$notif_icon = ''; |
| 55 |
if (!empty($channel_source)) { |
| 56 |
$ch_logo_obj = VikBooking::getVcmChannelsLogo($channel_source, true); |
| 57 |
$notif_icon = is_object($ch_logo_obj) ? $ch_logo_obj->getSmallLogoURL() : ''; |
| 58 |
} elseif (!empty($customer_pic)) { |
| 59 |
$notif_icon = strpos($customer_pic, 'http') === 0 ? $customer_pic : VBO_SITE_URI . 'resources/uploads/' . $customer_pic; |
| 60 |
} |
| 61 |
|
| 62 |
if (empty($notif_icon)) { |
| 63 |
$notif_icon = $this->getIconUrl(); |
| 64 |
} |
| 65 |
|
| 66 |
// get history helper |
| 67 |
$history_obj = VikBooking::getBookingHistoryInstance(); |
| 68 |
|
| 69 |
// compose notification title |
| 70 |
$notif_title = $history_obj->validType($ev_type, true); |
| 71 |
|
| 72 |
// compose the notification data to display |
| 73 |
$notif_data = new stdClass; |
| 74 |
$notif_data->title = $notif_title; |
| 75 |
$notif_data->message = $this->get('descr', ''); |
| 76 |
$notif_data->icon = $notif_icon; |
| 77 |
$notif_data->onclick = 'VBOCore.handleGoto'; |
| 78 |
$notif_data->gotourl = 'index.php?option=com_vikbooking&task=editorder&cid[]=' . $booking_id; |
| 79 |
if (VBOPlatformDetection::isWordPress()) { |
| 80 |
$notif_data->gotourl = str_replace('index.php', 'admin.php', $notif_data->gotourl); |
| 81 |
} |
| 82 |
|
| 83 |
return $notif_data; |
| 84 |
} |
| 85 |
|
| 86 |
/** |
| 87 |
* Returns the URL to the default icon for the history |
| 88 |
* browser notifications. Custom logos are preferred. |
| 89 |
* |
| 90 |
* @return string|null |
| 91 |
*/ |
| 92 |
private function getIconUrl() |
| 93 |
{ |
| 94 |
$config = VBOFactory::getConfig(); |
| 95 |
|
| 96 |
// back-end custom logo |
| 97 |
$use_logo = $config->get('backlogo'); |
| 98 |
if (empty($use_logo) || !strcasecmp($use_logo, 'vikbooking.png')) { |
| 99 |
// fallback to company (site) logo |
| 100 |
$use_logo = $config->get('sitelogo'); |
| 101 |
} |
| 102 |
|
| 103 |
if (!empty($use_logo) && strcasecmp($use_logo, 'vikbooking.png')) { |
| 104 |
// uploaded logo found |
| 105 |
$use_logo = VBO_ADMIN_URI . 'resources/' . $use_logo; |
| 106 |
} else { |
| 107 |
$use_logo = null; |
| 108 |
} |
| 109 |
|
| 110 |
return $use_logo; |
| 111 |
} |
| 112 |
} |
| 113 |
|