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 / user / operator.php

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

128 lines 3.0 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 user operator wrapper.
16 *
17 * @since 1.8
18 */
19 class VBOChatUserOperator extends VBOChatUseraware implements VBOChatNotifiable
20 {
21 use VBOChatNotificationEmail;
22 use VBOChatNotificationApp;
23
24 /** @var object */
25 protected $operator;
26
27 /**
28 * Class constructor.
29 *
30 * @param mixed The operator details.
31 */
32 public function __construct($operator = null)
33 {
34 if (!$operator) {
35 // fetch details of the logged in operator
36 $operator = VikBooking::getOperatorInstance()->getOperatorAccount();
37 }
38
39 if (is_numeric($operator)) {
40 // fetch details of the specified operator
41 $operator = VikBooking::getOperatorInstance()->getOne((int) $operator);
42 }
43
44 if (!$operator) {
45 throw new RuntimeException('The logged in user is not an operator.', 403);
46 }
47
48 $this->operator = (object) $operator;
49 }
50
51 /**
52 * @inheritDoc
53 *
54 * @see VBOChatUser
55 */
56 public function getID()
57 {
58 return (int) $this->operator->id;
59 }
60
61 /**
62 * @inheritDoc
63 *
64 * @see VBOChatUser
65 */
66 public function getName()
67 {
68 return trim($this->operator->first_name . ' ' . $this->operator->last_name);
69 }
70
71 /**
72 * @inheritDoc
73 *
74 * @see VBOChatUser
75 */
76 public function getAvatar()
77 {
78 $image = $this->operator->pic ?? '';
79
80 if ($image) {
81 // check whether we have an image name or a full URI
82 $image = preg_match("/^https?:\/\//i", $image) ? $image : VBO_SITE_URI . 'resources/uploads/' . $image;
83 }
84
85 return $image;
86 }
87
88 /**
89 * @inheritDoc
90 *
91 * @see VBOChatUser
92 */
93 public function can(string $scope, ?VBOChatContext $context = null)
94 {
95 if ($context) {
96 // delegate the validation to the context
97 return $context->can($scope, $this);
98 }
99
100 return true;
101 }
102
103 /**
104 * @inheritDoc
105 *
106 * @see VBOChatNotifiable
107 */
108 public function scheduleNotification(VBOChatMessage $message, VBOChatUser $user)
109 {
110 if (!empty($this->operator->email)) {
111 /**
112 * If the e-mail address exists, send a notification to this operator.
113 *
114 * @see VBOChatNotificationEmail
115 */
116 $this->sendEmailNotification($message, $this->operator->email, $this->getName());
117
118 /**
119 * Send notification to the mobile APP as well.
120 *
121 * @since 1.8.15
122 * @see VBOChatNotificationApp
123 */
124 $this->scheduleAppNotification($message, $this->operator->email);
125 }
126 }
127 }
128