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 / context / task.php

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

206 lines 5.5 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 * Task manager chat context class.
16 *
17 * @since 1.8
18 */
19 class VBOChatContextTask extends VBOChatContextaware
20 {
21 /** @var object */
22 private $task;
23
24 /**
25 * @inheritDoc
26 */
27 final public function getAlias()
28 {
29 return 'task';
30 }
31
32 /**
33 * @inheritDoc
34 */
35 public function getRecipients()
36 {
37 $recipients = [];
38
39 // adds support to administrator (create a placeholder to simulate a false login)
40 $recipients[] = new VBOChatUserAdmin((object) [
41 'id' => 0,
42 'guest' => false,
43 'name' => '',
44 ]);
45
46 if ($task = $this->getTask()) {
47 // obtain all the IDs of the operators involved in this context
48 $ids = $task->getAssigneeIds();
49
50 // fetch information for all the operators
51 foreach (VikBooking::getOperatorInstance()->getAll($ids) as $operator) {
52 $recipients[] = new VBOChatUserOperator($operator);
53 }
54 }
55
56 return $recipients;
57 }
58
59 /**
60 * @inheritDoc
61 */
62 public function getSubject()
63 {
64 if ($task = $this->getTask()) {
65 return $task->getTitle();
66 }
67
68 return sprintf('<em>Task #%d (deleted)</em>', $this->getID());
69 }
70
71 /**
72 * @inheritDoc
73 */
74 public function getURL()
75 {
76 return VBOFactory::getPlatform()->getUri()->route('index.php?option=com_vikbooking&view=operators&tool=task_manager&filters[calendar_type]=taskdetails&filters[task_id]=' . $this->getID());
77 }
78
79 /**
80 * @inheritDoc
81 */
82 public function useAssets(VBOChatUser $user)
83 {
84 $document = JFactory::getDocument();
85 $document->addScript(VBO_SITE_URI . 'resources/chat/task.js');
86
87 JText::script('VBSAVE');
88 JText::script('VBO_TASK');
89 JText::script('VBO_NEW_TASK');
90 JText::script('VBO_PROJECTS_AREAS');
91 }
92
93 /**
94 * @inheritDoc
95 */
96 public function getActions(VBOChatUser $user)
97 {
98 $actions = [];
99
100 // proceed only if the authenticated user is an administrator
101 if ($user->getID() != 0) {
102 return $actions;
103 }
104
105 // fetch task details
106 $task = $this->getTask();
107
108 if (!$task) {
109 return $actions;
110 }
111
112 // obtain all the statuses supported by the area to which the task belongs
113 $statuses = VBOTaskArea::getRecordInstance($task->getAreaID())->getStatusElements($task->getStatus());
114
115 // add option group label
116 $actions[] = [
117 'namespace' => 'task.btngroup',
118 'text' => JText::translate('VBSTATUS'),
119 'disabled' => true,
120 'class' => 'btngroup',
121 ];
122
123 foreach ($statuses as $group) {
124 // iterate over the statuses of this group
125 foreach ($group['elements'] as $statusType) {
126 // push status element
127 $actions[] = [
128 'namespace' => 'task.status',
129 'id' => $statusType['id'],
130 'text' => $statusType['text'],
131 'color' => $statusType['color'],
132 'selected' => $statusType['id'] == $task->getStatus(),
133 ];
134 }
135 }
136
137 $actions[count($actions) - 1]['separator'] = true;
138
139 if ($bookingId = $task->getBookingId()) {
140 // See booking details
141 $actions[] = [
142 'namespace' => 'task.booking',
143 'text' => JText::translate('VBO_CTA_SEE'),
144 'icon' => VikBookingIcons::i('calendar'),
145 'booking' => (int) $bookingId,
146 ];
147 }
148
149 return array_merge($actions, [
150 // See task details
151 [
152 'namespace' => 'task.see',
153 'text' => JText::translate('VBO_CHAT_SEE_TASK'),
154 'icon' => VikBookingIcons::i('eye'),
155 ],
156 // Create new task
157 [
158 'namespace' => 'task.new',
159 'text' => JText::translate('VBO_NEW_TASK'),
160 'icon' => VikBookingIcons::i('plus'),
161 'separator' => true,
162 ],
163 ]);
164 }
165
166 /**
167 * @inheritDoc
168 */
169 public function can(string $scope, VBOChatUser $user)
170 {
171 $task = $this->getTask();
172
173 if (!$task) {
174 // task not found...
175 return false;
176 }
177
178 // obtain all the users currently assigned to this task
179 $assignees = $task->getAssigneeIds();
180
181 // can perform the action only if the task has no assignee or
182 // whethet the current user has been already assigned
183 return !$assignees || in_array($user->getID(), $assignees);
184 }
185
186 /**
187 * Returns the details of this task context.
188 *
189 * @return object|null
190 */
191 protected function getTask()
192 {
193 if ($this->task === null) {
194 // fetch the details of the task and internally cache them
195 $this->task = VBOTaskTaskregistry::getRecordInstance($this->getID());
196
197 if (!$this->task->getID()) {
198 // the task doesn't exist any longer
199 $this->task = false;
200 }
201 }
202
203 return $this->task;
204 }
205 }
206