/
ShowTicket.php
253 lines (205 loc) · 11.1 KB
/
ShowTicket.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
<?php
namespace Leantime\Domain\Tickets\Controllers {
use Illuminate\Contracts\Container\BindingResolutionException;
use Leantime\Core\Controller;
use Leantime\Domain\Projects\Services\Projects as ProjectService;
use Leantime\Domain\Tickets\Services\Tickets as TicketService;
use Leantime\Domain\Sprints\Services\Sprints as SprintService;
use Leantime\Domain\Files\Services\Files as FileService;
use Leantime\Domain\Comments\Services\Comments as CommentService;
use Leantime\Domain\Timesheets\Services\Timesheets as TimesheetService;
use Leantime\Domain\Users\Services\Users as UserService;
use Symfony\Component\HttpFoundation\Response;
use Leantime\Core\Frontcontroller;
/**
*
*/
class ShowTicket extends Controller
{
private ProjectService $projectService;
private TicketService $ticketService;
private SprintService $sprintService;
private FileService $fileService;
private CommentService $commentService;
private TimesheetService $timesheetService;
private UserService $userService;
/**
* @param ProjectService $projectService
* @param TicketService $ticketService
* @param SprintService $sprintService
* @param FileService $fileService
* @param CommentService $commentService
* @param TimesheetService $timesheetService
* @param UserService $userService
* @return void
*/
public function init(
ProjectService $projectService,
TicketService $ticketService,
SprintService $sprintService,
FileService $fileService,
CommentService $commentService,
TimesheetService $timesheetService,
UserService $userService
): void {
$this->projectService = $projectService;
$this->ticketService = $ticketService;
$this->sprintService = $sprintService;
$this->fileService = $fileService;
$this->commentService = $commentService;
$this->timesheetService = $timesheetService;
$this->userService = $userService;
if (isset($_SESSION['lastPage']) === false) {
$_SESSION['lastPage'] = BASE_URL . "/tickets/showKanban";
}
}
/**
* @param $params
* @return Response
* @throws BindingResolutionException
*/
public function get($params): Response
{
if (! isset($params['id'])) {
return $this->tpl->displayPartial('errors.error400', responseCode: 400);
}
$id = (int)($params['id']);
$ticket = $this->ticketService->getTicket($id);
if ($ticket === false) {
return $this->tpl->display('errors.error500', responseCode: 500);
}
//Ensure this ticket belongs to the current project
if ($_SESSION["currentProject"] != $ticket->projectId) {
$this->projectService->changeCurrentSessionProject($ticket->projectId);
return Frontcontroller::redirect(BASE_URL . "/tickets/showTicket/" . $id);
}
//Delete file
if (isset($params['delFile']) === true) {
if ($result = $this->fileService->deleteFile($params['delFile'])) {
$this->tpl->setNotification($this->language->__("notifications.file_deleted"), "success");
return Frontcontroller::redirect(BASE_URL . "/tickets/showTicket/" . $id . "#files");;
}
$this->tpl->setNotification($result["msg"], "error");
}
//Delete comment
if (isset($params['delComment']) === true) {
$commentId = (int)($params['delComment']);
if ($this->commentService->deleteComment($commentId)) {
$this->tpl->setNotification($this->language->__("notifications.comment_deleted"), "success");
$response = Frontcontroller::redirect(BASE_URL . "/tickets/showTicket/" . $id);
$response->headers->set('HX-Trigger', 'ticketUpdate');
return $response;
}
$this->tpl->setNotification($this->language->__("notifications.comment_deleted_error"), "error");
}
//Delete Subtask
if (isset($params['delSubtask']) === true) {
}
$this->tpl->assign('ticket', $ticket);
$this->tpl->assign('ticketParents', $this->ticketService->getAllPossibleParents($ticket));
$this->tpl->assign('statusLabels', $this->ticketService->getStatusLabels());
$this->tpl->assign('ticketTypes', $this->ticketService->getTicketTypes());
$this->tpl->assign('ticketTypeIcons', $this->ticketService->getTypeIcons());
$this->tpl->assign('efforts', $this->ticketService->getEffortLabels());
$this->tpl->assign('priorities', $this->ticketService->getPriorityLabels());
$allProjectMilestones = $this->ticketService->getAllMilestones([
"sprint" => '',
"type" => "milestone",
"currentProject" => $_SESSION["currentProject"],
]);
$this->tpl->assign('milestones', $allProjectMilestones);
$this->tpl->assign('sprints', $this->sprintService->getAllSprints($_SESSION["currentProject"]));
$this->tpl->assign('kind', $this->timesheetService->getLoggableHourTypes());
$this->tpl->assign('ticketHours', $this->timesheetService->getLoggedHoursForTicketByDate($id));
$this->tpl->assign('userHours', $this->timesheetService->getUsersTicketHours($id, $_SESSION['userdata']['id']));
$this->tpl->assign('timesheetsAllHours', $this->timesheetService->getSumLoggedHoursForTicket($id));
$this->tpl->assign('remainingHours', $this->timesheetService->getRemainingHours($ticket));
$this->tpl->assign('userInfo', $this->userService->getUser($_SESSION['userdata']['id']));
$this->tpl->assign('users', $this->projectService->getUsersAssignedToProject($ticket->projectId));
$projectData = $this->projectService->getProject($ticket->projectId);
$this->tpl->assign('projectData', $projectData);
$comments = $this->commentService->getComments('ticket', $id);
$this->tpl->assign('numComments', count($comments));
$this->tpl->assign('comments', $comments);
$files = $this->fileService->getFilesByModule('ticket', $id);
$this->tpl->assign('numFiles', count($files));
$this->tpl->assign('files', $files);
$this->tpl->assign('onTheClock', $this->timesheetService->isClocked($_SESSION["userdata"]["id"]));
$this->tpl->assign("timesheetValues", array("kind" => "", "date" => date($this->language->__("language.dateformat")), "hours" => "", "description" => ""));
//TODO: Refactor thumbnail generation in file manager
$this->tpl->assign('imgExtensions', array('jpg', 'jpeg', 'png', 'gif', 'psd', 'bmp', 'tif', 'thm', 'yuv'));
$allAssignedprojects = $this->projectService->getProjectsAssignedToUser($_SESSION['userdata']['id'], 'open');
$this->tpl->assign('allAssignedprojects', $allAssignedprojects);
$response = $this->tpl->displayPartial('tickets.showTicketModal');
$response->headers->set('HX-Trigger', 'ticketUpdate');
return $response;
}
/**
* @param $params
* @return Response
* @throws BindingResolutionException
*/
public function post($params): Response
{
if (! isset($_GET['id'])) {
return $this->tpl->display('errors.error400', responseCode: 400);
}
$tab = "";
$id = (int)($_GET['id']);
$ticket = $this->ticketService->getTicket($id);
if ($ticket === false) {
return $this->tpl->display('errors.error500', responseCode: 500);
}
//Upload File
if (isset($params['upload'])) {
if ($this->fileService->uploadFile($_FILES, "ticket", $id, $ticket)) {
$this->tpl->setNotification($this->language->__("notifications.file_upload_success"), "success");
} else {
$this->tpl->setNotification($this->language->__("notifications.file_upload_error"), "error");
}
$tab = "#files";
}
//Add a comment
if (isset($params['comment']) === true && isset($params['text']) && $params['text'] != '') {
if ($this->commentService->addComment($_POST, "ticket", $id, $ticket)) {
$this->tpl->setNotification($this->language->__("notifications.comment_create_success"), "success");
} else {
$this->tpl->setNotification($this->language->__("notifications.comment_create_error"), "error");
}
$tab = "#comment";
}
//Log time
if (isset($params['saveTimes']) === true) {
$result = $this->timesheetService->logTime($id, $params);
if ($result === true) {
$this->tpl->setNotification($this->language->__("notifications.time_logged_success"), "success");
} else {
$this->tpl->setNotification($this->language->__($result['msg']), "error");
}
}
//Save Ticket
if (isset($params["saveTicket"]) === true || isset($params["saveAndCloseTicket"]) === true) {
$params["projectId"] = $ticket->projectId;
$params['id'] = $id;
//Prepare values, time comes in as 24hours from time input. Service expects time to be in local user format
$params['timeToFinish'] = format($params['timeToFinish'] ?? '')->time24toLocalTime(ignoreTimezone: true);
$params['timeFrom'] = format($params['timeFrom'] ?? '')->time24toLocalTime(ignoreTimezone: true);
$params['timeTo'] = format($params['timeTo'] ?? '')->time24toLocalTime(ignoreTimezone: true);
$result = $this->ticketService->updateTicket($params);
if ($result === true) {
$this->tpl->setNotification($this->language->__("notifications.ticket_saved"), "success");
} else {
$this->tpl->setNotification($this->language->__($result["msg"]), "error");
}
if (isset($params["saveAndCloseTicket"]) === true && $params["saveAndCloseTicket"] == 1) {
$response = Frontcontroller::redirect(BASE_URL . "/tickets/showTicket/" . $id . "?closeModal=1");
$response->headers->set('HX-Trigger', 'ticketUpdate');
return $response;
}
}
$response = Frontcontroller::redirect(BASE_URL . "/tickets/showTicket/" . $id . "" . $tab);
$response->headers->set('HX-Trigger', 'ticketUpdate');
return $response;
}
}
}