PluginProbe
VikBooking Hotel Booking Engine & PMS / 1.8.6
VikBooking Hotel Booking Engine & PMS v1.8.6
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 1.8.6, at admin/helpers/src/chat/user/operator.php

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