PluginProbe
VikBooking Hotel Booking Engine & PMS / trunk
VikBooking Hotel Booking Engine & PMS vtrunk
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 1.7.3 All 36 releases
vikbooking / admin / helpers / src / chat / notification / app.php

app.php in VikBooking Hotel Booking Engine & PMS trunk, at admin/helpers/src/chat/notification/app.php

86 lines 2.8 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 E4J s.r.l.
6 * @copyright Copyright (C) 2026 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 * Chat APP push notification trait.
16 *
17 * @since 1.8.15
18 */
19 trait VBOChatNotificationApp
20 {
21 /**
22 * Schedules a notification for the specified device account.
23 *
24 * @param VBOChatMessage $message The message instance.
25 * @param string $deviceAccount The account (email or "admin") of the device to notify.
26 *
27 * @return bool
28 */
29 public function scheduleAppNotification(VBOChatMessage $message, string $deviceAccount)
30 {
31 // do not notify messages wrote from the front-end chat
32 if ($message->getContext()->getAlias() === 'session') {
33 return false;
34 }
35
36 // make sure VCM exposes an object to dispatch notifications
37 if (!method_exists('VCMFactory', 'getContainer')) {
38 // required VCM 1.9.27
39 return false;
40 }
41
42 /** @var VBOChatContext */
43 $context = $message->getContext();
44
45 // display the whole message as summary
46 $summary = (string) $message->getMessage();
47
48 if (strlen($summary) === 0) {
49 // no message provided, display the number of attached files
50 $attachmentsCount = count($message->getAttachments());
51
52 if ($attachmentsCount === 1) {
53 // only one attachment
54 $summary = JText::sprintf('VBO_CHAT_MESSAGE_WEBPUSH_NOTIFICATION_SUMMARY_N_FILES_1', $message->getSenderName());
55 } else {
56 // multiple attachments
57 $summary = JText::plural('VBO_CHAT_MESSAGE_WEBPUSH_NOTIFICATION_SUMMARY_N_FILES', $message->getSenderName(), $attachmentsCount);
58 }
59 } else {
60 // message provided
61 $summary = JText::sprintf('VBO_CHAT_MESSAGE_WEBPUSH_NOTIFICATION_SUMMARY', $message->getSenderName(), $summary);
62 }
63
64 // prepare notification data
65 $data = [
66 'type' => 'Messaging',
67 'from' => [
68 'id' => $message->getSenderID(),
69 'name' => $message->getSenderName(),
70 ],
71 'context' => [
72 'alias' => $context->getAlias(),
73 'id' => $context->getID(),
74 ],
75 'preview' => $summary,
76 ];
77
78 // schedule notification delivery to the involved devices
79 VCMFactory::getContainer()->get('vikchannelmanager.pnd.lazy')->sendNotification(
80 new E4J\VCM\PND\Notification($data, $deviceAccount)
81 );
82
83 return true;
84 }
85 }
86