← All changes
|
admin/helpers/src/notification/display/review.php
+115
-0
1.6.2
→
1.8.16
View file →
| @@ -1,0 +1,115 @@ | ||
| 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 review left by a guest. | |
| 16 | + * | |
| 17 | + * @since 1.15.0 (J) - 1.5.0 (WP) | |
| 18 | + */ | |
| 19 | +final class VBONotificationDisplayReview 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 | + $review_id = (int)$this->get('id_review', 0); | |
| 43 | + if (empty($booking_id) || empty($review_id)) { | |
| 44 | + return null; | |
| 45 | + } | |
| 46 | + | |
| 47 | + // guest avatar and channel logo | |
| 48 | + $guest_avatar = $this->get('guest_avatar', ''); | |
| 49 | + $channel_logo = $this->get('channel_logo', ''); | |
| 50 | + | |
| 51 | + // the notification icon | |
| 52 | + $notif_icon = ''; | |
| 53 | + if (!empty($guest_avatar)) { | |
| 54 | + $notif_icon = $guest_avatar; | |
| 55 | + } elseif (!empty($channel_logo)) { | |
| 56 | + $notif_icon = $channel_logo; | |
| 57 | + } else { | |
| 58 | + $notif_icon = $this->getIconUrl(); | |
| 59 | + } | |
| 60 | + | |
| 61 | + // compose notification title | |
| 62 | + $guest_name = $this->get('customer_name', ''); | |
| 63 | + if (empty($guest_name)) { | |
| 64 | + $guest_name = $this->get('first_name', '') . ' ' . $this->get('last_name', ''); | |
| 65 | + } | |
| 66 | + $notif_title = $guest_name . ' - ' . JText::translate('VBOSEEGUESTREVIEW'); | |
| 67 | + | |
| 68 | + // compose the notification data to display | |
| 69 | + $notif_data = new stdClass; | |
| 70 | + $notif_data->title = $notif_title; | |
| 71 | + $notif_data->message = $this->get('score', '') . ' ' . $this->get('content', ''); | |
| 72 | + $notif_data->icon = $notif_icon; | |
| 73 | + $notif_data->onclick = 'VBOCore.handleDisplayWidgetNotification'; | |
| 74 | + $notif_data->gotourl = VBOFactory::getPlatform()->getUri()->admin("index.php?option=com_vikbooking&task=editorder&cid[]={$booking_id}", false); | |
| 75 | + | |
| 76 | + // set additional properties to the (Web, not Push) notification payload | |
| 77 | + $notif_data->widget_id = 'guest_reviews'; | |
| 78 | + // data options for a Web notification should NOT set a "type" or this will be overridden | |
| 79 | + $notif_data->_options = [ | |
| 80 | + '_web' => 1, | |
| 81 | + 'title' => $notif_data->title, | |
| 82 | + 'message' => $notif_data->message, | |
| 83 | + 'bid' => $booking_id, | |
| 84 | + ]; | |
| 85 | + | |
| 86 | + return $notif_data; | |
| 87 | + } | |
| 88 | + | |
| 89 | + /** | |
| 90 | + * Returns the URL to the default icon for the history | |
| 91 | + * browser notifications. Custom logos are preferred. | |
| 92 | + * | |
| 93 | + * @return string|null | |
| 94 | + */ | |
| 95 | + private function getIconUrl() | |
| 96 | + { | |
| 97 | + $config = VBOFactory::getConfig(); | |
| 98 | + | |
| 99 | + // back-end custom logo | |
| 100 | + $use_logo = $config->get('backlogo'); | |
| 101 | + if (empty($use_logo) || !strcasecmp($use_logo, 'vikbooking.png')) { | |
| 102 | + // fallback to company (site) logo | |
| 103 | + $use_logo = $config->get('sitelogo'); | |
| 104 | + } | |
| 105 | + | |
| 106 | + if (!empty($use_logo) && strcasecmp($use_logo, 'vikbooking.png')) { | |
| 107 | + // uploaded logo found | |
| 108 | + $use_logo = VBO_ADMIN_URI . 'resources/' . $use_logo; | |
| 109 | + } else { | |
| 110 | + $use_logo = null; | |
| 111 | + } | |
| 112 | + | |
| 113 | + return $use_logo; | |
| 114 | + } | |
| 115 | +} | |