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

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

205 lines 5.4 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 * 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 useAssets()
63 {
64 $document = JFactory::getDocument();
65 $document->addScript(VBO_SITE_URI . 'resources/chat/task.js');
66
67 JText::script('VBSAVE');
68 JText::script('VBO_TASK');
69 JText::script('VBO_NEW_TASK');
70 JText::script('VBO_PROJECTS_AREAS');
71 }
72
73 /**
74 * @inheritDoc
75 */
76 public function getSubject()
77 {
78 if ($task = $this->getTask()) {
79 return $task->getTitle();
80 }
81
82 return sprintf('<em>Task #%d (deleted)</em>', $this->getID());
83 }
84
85 /**
86 * @inheritDoc
87 */
88 public function getActions()
89 {
90 $actions = [];
91
92 if (JFactory::getApplication()->isClient('site')) {
93 return $actions;
94 }
95
96 // fetch task details
97 $task = $this->getTask();
98
99 if (!$task) {
100 return $actions;
101 }
102
103 // obtain all the statuses supported by the area to which the task belongs
104 $statuses = VBOTaskArea::getRecordInstance($task->getAreaID())->getStatusElements($task->getStatus());
105
106 // add option group label
107 $actions[] = [
108 'namespace' => 'task.btngroup',
109 'text' => JText::translate('VBSTATUS'),
110 'disabled' => true,
111 'class' => 'btngroup',
112 ];
113
114 foreach ($statuses as $group) {
115 // iterate over the statuses of this group
116 foreach ($group['elements'] as $statusType) {
117 // push status element
118 $actions[] = [
119 'namespace' => 'task.status',
120 'id' => $statusType['id'],
121 'text' => $statusType['text'],
122 'color' => $statusType['color'],
123 'selected' => $statusType['id'] == $task->getStatus(),
124 ];
125 }
126 }
127
128 $actions[count($actions) - 1]['separator'] = true;
129
130 if ($bookingId = $task->getBookingId()) {
131 // See booking details
132 $actions[] = [
133 'namespace' => 'task.booking',
134 'text' => JText::translate('VBO_CTA_SEE'),
135 'icon' => VikBookingIcons::i('calendar'),
136 'booking' => (int) $bookingId,
137 ];
138 }
139
140 return array_merge($actions, [
141 // See task details
142 [
143 'namespace' => 'task.see',
144 'text' => JText::translate('VBO_CHAT_SEE_TASK'),
145 'icon' => VikBookingIcons::i('eye'),
146 ],
147 // Create new task
148 [
149 'namespace' => 'task.new',
150 'text' => JText::translate('VBO_NEW_TASK'),
151 'icon' => VikBookingIcons::i('plus'),
152 'separator' => true,
153 ],
154 ]);
155 }
156
157 /**
158 * @inheritDoc
159 */
160 public function getURL()
161 {
162 return VBOFactory::getPlatform()->getUri()->route('index.php?option=com_vikbooking&view=operators&tool=task_manager&filters[calendar_type]=taskdetails&filters[task_id]=' . $this->getID());
163 }
164
165 /**
166 * @inheritDoc
167 */
168 public function can(string $scope, VBOChatUser $user)
169 {
170 $task = $this->getTask();
171
172 if (!$task) {
173 // task not found...
174 return false;
175 }
176
177 // obtain all the users currently assigned to this task
178 $assignees = $task->getAssigneeIds();
179
180 // can perform the action only if the task has no assignee or
181 // whethet the current user has been already assigned
182 return !$assignees || in_array($user->getID(), $assignees);
183 }
184
185 /**
186 * Returns the details of this task context.
187 *
188 * @return object|null
189 */
190 protected function getTask()
191 {
192 if ($this->task === null) {
193 // fetch the details of the task and internally cache them
194 $this->task = VBOTaskTaskregistry::getRecordInstance($this->getID());
195
196 if (!$this->task->getID()) {
197 // the task doesn't exist any longer
198 $this->task = false;
199 }
200 }
201
202 return $this->task;
203 }
204 }
205