1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Tinyissue package. |
5
|
|
|
* |
6
|
|
|
* (c) Mohamed Alsharaf <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Tinyissue\Http\Controllers\Project; |
13
|
|
|
|
14
|
|
|
use Illuminate\Http\Request; |
15
|
|
|
use Illuminate\Http\Response; |
16
|
|
|
use Tinyissue\Form\Comment as CommentForm; |
17
|
|
|
use Tinyissue\Form\Issue as IssueForm; |
18
|
|
|
use Tinyissue\Http\Controllers\Controller; |
19
|
|
|
use Tinyissue\Http\Requests\FormRequest; |
20
|
|
|
use Tinyissue\Model\Project; |
21
|
|
|
use Tinyissue\Model\Project\Issue; |
22
|
|
|
use Tinyissue\Model\Project\Issue\Attachment; |
23
|
|
|
use Tinyissue\Model\Project\Issue\Comment; |
24
|
|
|
use Tinyissue\Model\Tag; |
25
|
|
|
use Tinyissue\Model\User\Activity as UserActivity; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* IssueController is the controller class for managing request related to projects issues. |
29
|
|
|
* |
30
|
|
|
* @author Mohamed Alsharaf <[email protected]> |
31
|
|
|
*/ |
32
|
|
|
class IssueController extends Controller |
33
|
|
|
{ |
34
|
|
|
/** |
35
|
|
|
* Project issue index page (List project issues). |
36
|
|
|
* |
37
|
|
|
* @param Project $project |
38
|
|
|
* @param Issue $issue |
39
|
|
|
* @param CommentForm $form |
40
|
|
|
* |
41
|
|
|
* @return \Illuminate\View\View |
42
|
|
|
*/ |
43
|
16 |
|
public function getIndex(Project $project, Issue $issue, CommentForm $form) |
44
|
|
|
{ |
45
|
|
|
$issue->attachments->each(function (Attachment $attachment) use ($issue) { |
|
|
|
|
46
|
16 |
|
$attachment->setRelation('issue', $issue); |
47
|
16 |
|
}); |
48
|
13 |
|
$activities = $issue->activities()->with('activity', 'user', 'comment', 'assignTo', |
49
|
|
|
'comment.attachments')->get(); |
50
|
|
|
$activities->each(function (UserActivity $activity) use ($issue) { |
51
|
16 |
|
$activity->setRelation('issue', $issue); |
52
|
16 |
|
}); |
53
|
16 |
|
|
54
|
16 |
|
// Projects should be limited to issue-modify |
55
|
16 |
|
$projects = null; |
56
|
16 |
|
if (!$this->auth->guest() && $this->auth->user()->permission('issue-modify')) { |
|
|
|
|
57
|
|
|
$projects = $this->auth->user()->projects()->get(); |
|
|
|
|
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
return view('project.issue.index', [ |
|
|
|
|
61
|
|
|
'issue' => $issue, |
62
|
|
|
'project' => $project, |
63
|
|
|
'commentForm' => $form, |
64
|
|
|
'activities' => $activities, |
65
|
|
|
'sidebar' => 'project', |
66
|
|
|
'projects' => $projects, |
67
|
|
|
]); |
68
|
1 |
|
} |
69
|
|
|
|
70
|
1 |
|
/** |
71
|
1 |
|
* Ajax: Assign new user to an issue. |
72
|
1 |
|
* |
73
|
|
|
* @param Issue $issue |
74
|
|
|
* @param Request $request |
75
|
1 |
|
* |
76
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
77
|
|
|
*/ |
78
|
|
View Code Duplication |
public function postAssign(Issue $issue, Request $request) |
|
|
|
|
79
|
|
|
{ |
80
|
|
|
$response = ['status' => false]; |
81
|
|
|
if ($issue->reassign((int) $request->input('user_id'), $this->auth->user()->id)) { |
|
|
|
|
82
|
|
|
$response['status'] = true; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
return response()->json($response); |
86
|
1 |
|
} |
87
|
|
|
|
88
|
1 |
|
/** |
89
|
1 |
|
* Ajax: save comment. |
90
|
1 |
|
* |
91
|
1 |
|
* @param Comment $comment |
92
|
|
|
* @param Request $request |
93
|
|
|
* |
94
|
1 |
|
* @return \Symfony\Component\HttpFoundation\Response |
95
|
|
|
*/ |
96
|
|
|
public function postEditComment(Comment $comment, Request $request) |
97
|
|
|
{ |
98
|
|
|
$body = ''; |
99
|
|
|
if ($request->has('body')) { |
100
|
|
|
$comment->fill(['comment' => $request->input('body')])->save(); |
101
|
|
|
$body = \Html::format($comment->comment); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
return response()->json(['text' => $body]); |
105
|
|
|
} |
106
|
|
|
|
107
|
4 |
|
/** |
108
|
|
|
* To add new comment to an issue. |
109
|
4 |
|
* |
110
|
4 |
|
* @param Project $project |
111
|
4 |
|
* @param Issue $issue |
112
|
4 |
|
* @param Comment $comment |
113
|
|
|
* @param FormRequest\Comment $request |
114
|
4 |
|
* |
115
|
4 |
|
* @return \Illuminate\Http\RedirectResponse |
116
|
|
|
*/ |
117
|
|
|
public function getAddComment(Project $project, Issue $issue, Comment $comment, FormRequest\Comment $request) |
118
|
|
|
{ |
119
|
|
|
$comment->setRelation('project', $project); |
120
|
|
|
$comment->setRelation('issue', $issue); |
121
|
|
|
$comment->setRelation('user', $this->auth->user()); |
122
|
|
|
$comment->createComment($request->all()); |
123
|
|
|
|
124
|
|
|
return redirect($issue->to() . '#comment' . $comment->id) |
125
|
1 |
|
->with('notice', trans('tinyissue.your_comment_added')); |
126
|
|
|
} |
127
|
1 |
|
|
128
|
|
|
/** |
129
|
1 |
|
* Ajax: to delete a comment. |
130
|
|
|
* |
131
|
|
|
* @param Comment $comment |
132
|
|
|
* |
133
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
134
|
|
|
*/ |
135
|
|
|
public function getDeleteComment(Comment $comment) |
136
|
|
|
{ |
137
|
|
|
$comment->deleteComment(); |
138
|
|
|
|
139
|
|
|
return response()->json(['status' => true]); |
140
|
5 |
|
} |
141
|
|
|
|
142
|
5 |
|
/** |
143
|
5 |
|
* New issue form. |
144
|
5 |
|
* |
145
|
5 |
|
* @param Project $project |
146
|
|
|
* @param IssueForm $form |
147
|
|
|
* |
148
|
|
|
* @return \Illuminate\View\View |
149
|
|
|
*/ |
150
|
|
|
public function getNew(Project $project, IssueForm $form) |
151
|
|
|
{ |
152
|
|
|
return view('project.issue.new', [ |
|
|
|
|
153
|
|
|
'project' => $project, |
154
|
|
|
'form' => $form, |
155
|
|
|
'sidebar' => 'project', |
156
|
|
|
]); |
157
|
|
|
} |
158
|
2 |
|
|
159
|
|
|
/** |
160
|
2 |
|
* To create a new issue. |
161
|
2 |
|
* |
162
|
2 |
|
* @param Project $project |
163
|
|
|
* @param Issue $issue |
164
|
2 |
|
* @param FormRequest\Issue $request |
165
|
2 |
|
* |
166
|
|
|
* @return \Illuminate\Http\RedirectResponse |
167
|
|
|
*/ |
168
|
|
View Code Duplication |
public function postNew(Project $project, Issue $issue, FormRequest\Issue $request) |
|
|
|
|
169
|
|
|
{ |
170
|
|
|
$issue->setRelation('project', $project); |
171
|
|
|
$issue->setRelation('user', $this->auth->user()); |
172
|
|
|
$issue->createIssue($request->all()); |
173
|
|
|
|
174
|
|
|
return redirect($issue->to()) |
175
|
|
|
->with('notice', trans('tinyissue.issue_has_been_created')); |
176
|
|
|
} |
177
|
2 |
|
|
178
|
|
|
/** |
179
|
|
|
* Edit an existing issue form. |
180
|
2 |
|
* |
181
|
1 |
|
* @param Project $project |
182
|
1 |
|
* @param Issue $issue |
183
|
|
|
* @param IssueForm $form |
184
|
|
|
* |
185
|
2 |
|
* @return \Illuminate\View\View |
186
|
2 |
|
*/ |
187
|
2 |
|
public function getEdit(Project $project, Issue $issue, IssueForm $form) |
188
|
2 |
|
{ |
189
|
2 |
|
// Cannot edit closed issue |
190
|
|
|
if ($issue->status == Issue::STATUS_CLOSED) { |
191
|
|
|
return redirect($issue->to()) |
|
|
|
|
192
|
|
|
->with('notice', trans('tinyissue.cant_edit_closed_issue')); |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
return view('project.issue.edit', [ |
|
|
|
|
196
|
|
|
'issue' => $issue, |
197
|
|
|
'project' => $project, |
198
|
|
|
'form' => $form, |
199
|
|
|
'sidebar' => 'project', |
200
|
|
|
]); |
201
|
|
|
} |
202
|
1 |
|
|
203
|
|
|
/** |
204
|
1 |
|
* To update an existing issue details. |
205
|
1 |
|
* |
206
|
1 |
|
* @param Project $project |
207
|
|
|
* @param Issue $issue |
208
|
1 |
|
* @param FormRequest\Issue $request |
209
|
1 |
|
* |
210
|
|
|
* @return \Illuminate\Http\RedirectResponse |
211
|
|
|
*/ |
212
|
|
View Code Duplication |
public function postEdit(Project $project, Issue $issue, FormRequest\Issue $request) |
|
|
|
|
213
|
|
|
{ |
214
|
|
|
$issue->setRelation('project', $project); |
215
|
|
|
$issue->setRelation('updatedBy', $this->auth->user()); |
216
|
|
|
$issue->updateIssue($request->all()); |
217
|
|
|
|
218
|
|
|
return redirect($issue->to()) |
219
|
|
|
->with('notice', trans('tinyissue.issue_has_been_updated')); |
220
|
|
|
} |
221
|
2 |
|
|
222
|
|
|
/** |
223
|
2 |
|
* To close or reopen an issue. |
224
|
2 |
|
* |
225
|
|
|
* @param Project $project |
226
|
1 |
|
* @param Issue $issue |
227
|
|
|
* @param int $status |
228
|
|
|
* |
229
|
2 |
|
* @return \Illuminate\Http\RedirectResponse |
230
|
2 |
|
*/ |
231
|
|
|
public function getClose(Project $project, Issue $issue, $status = 0) |
232
|
2 |
|
{ |
233
|
2 |
|
if ($status == 0) { |
234
|
|
|
$message = trans('tinyissue.issue_has_been_closed'); |
235
|
|
|
} else { |
236
|
|
|
$message = trans('tinyissue.issue_has_been_reopened'); |
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
$issue->setRelation('project', $project); |
240
|
|
|
$issue->changeStatus($status, $this->auth->user()->id); |
|
|
|
|
241
|
|
|
|
242
|
|
|
return redirect($issue->to()) |
243
|
|
|
->with('notice', $message); |
244
|
|
|
} |
245
|
3 |
|
|
246
|
|
|
/** |
247
|
|
|
* To upload an attachment file. |
248
|
3 |
|
* |
249
|
|
|
* @param Project $project |
250
|
|
|
* @param Attachment $attachment |
251
|
|
|
* @param Request $request |
252
|
3 |
|
* |
253
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
254
|
|
|
*/ |
255
|
|
|
public function postUploadAttachment(Project $project, Attachment $attachment, Request $request) |
256
|
|
|
{ |
257
|
3 |
|
try { |
258
|
3 |
|
if (!$this->auth->user()->permission('project-all')) { |
|
|
|
|
259
|
3 |
|
abort(404); |
260
|
|
|
} |
261
|
|
|
|
262
|
|
|
$attachment->upload($request->all(), $project, $this->auth->user()); |
|
|
|
|
263
|
|
|
|
264
|
|
|
$response = [ |
265
|
|
|
'upload' => [ |
266
|
|
|
[ |
267
|
|
|
'name' => $attachment->filename, |
268
|
|
|
'size' => $attachment->filesize, |
269
|
|
|
'fileId' => $attachment->id, |
270
|
|
|
], |
271
|
|
|
], |
272
|
|
|
]; |
273
|
|
|
} catch (\Exception $exception) { |
274
|
3 |
|
$file = $request->file('upload'); |
275
|
|
|
|
276
|
|
|
$response = [ |
277
|
|
|
'status' => false, |
278
|
|
|
'name' => $file->getClientOriginalName(), |
279
|
|
|
'error' => $exception->getMessage(), |
280
|
|
|
'trace' => $exception->getTraceAsString(), |
281
|
|
|
]; |
282
|
|
|
} |
283
|
|
|
|
284
|
|
|
return response()->json($response); |
285
|
|
|
} |
286
|
1 |
|
|
287
|
|
|
/** |
288
|
1 |
|
* Ajax: to remove an attachment file. |
289
|
|
|
* |
290
|
1 |
|
* @param Project $project |
291
|
|
|
* @param Attachment $attachment |
292
|
|
|
* @param Request $request |
293
|
|
|
* |
294
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
295
|
|
|
*/ |
296
|
|
|
public function postRemoveAttachment(Project $project, Attachment $attachment, Request $request) |
297
|
|
|
{ |
298
|
|
|
$attachment->remove($request->all(), $project, $this->auth->user()); |
|
|
|
|
299
|
|
|
|
300
|
|
|
return response()->json(['status' => true]); |
301
|
|
|
} |
302
|
|
|
|
303
|
2 |
|
/** |
304
|
|
|
* Display an attachment file such as image. |
305
|
2 |
|
* |
306
|
2 |
|
* @param Project $project |
307
|
|
|
* @param Issue $issue |
308
|
2 |
|
* @param Attachment $attachment |
309
|
2 |
|
* @param Request $request |
310
|
2 |
|
* |
311
|
2 |
|
* @return Response |
312
|
2 |
|
*/ |
313
|
|
|
public function getDisplayAttachment(Project $project, Issue $issue, Attachment $attachment, Request $request) |
314
|
2 |
|
{ |
315
|
2 |
|
$issue->setRelation('project', $project); |
316
|
2 |
|
$attachment->setRelation('issue', $issue); |
317
|
2 |
|
|
318
|
2 |
|
$path = config('tinyissue.uploads_dir') . '/' . $issue->project_id . '/' . $attachment->upload_token . '/' . $attachment->filename; |
319
|
2 |
|
$storage = \Storage::disk('local'); |
320
|
|
|
$length = $storage->size($path); |
321
|
2 |
|
$time = $storage->lastModified($path); |
322
|
2 |
|
$type = $storage->getDriver()->getMimetype($path); |
323
|
2 |
|
|
324
|
2 |
|
$response = new Response(); |
325
|
|
|
$response->setEtag(md5($time . $path)); |
326
|
2 |
|
$response->setExpires(new \DateTime('@' . ($time + 60))); |
327
|
|
|
$response->setLastModified(new \DateTime('@' . $time)); |
328
|
|
|
$response->setPublic(); |
329
|
|
|
$response->setStatusCode(200); |
330
|
|
|
|
331
|
|
|
$response->header('Content-Type', $type); |
332
|
2 |
|
$response->header('Content-Length', $length); |
333
|
|
|
$response->header('Content-Disposition', 'inline; filename="' . $attachment->filename . '"'); |
334
|
2 |
|
$response->header('Cache-Control', 'must-revalidate'); |
335
|
|
|
|
336
|
|
|
if ($response->isNotModified($request)) { |
337
|
|
|
// Return empty response if not modified |
338
|
|
|
return $response; |
339
|
|
|
} |
340
|
|
|
|
341
|
|
|
// Return file if first request / modified |
342
|
|
|
$response->setContent($storage->get($path)); |
343
|
|
|
|
344
|
|
|
return $response; |
345
|
|
|
} |
346
|
1 |
|
|
347
|
|
|
/** |
348
|
1 |
|
* Download an attachment file. |
349
|
1 |
|
* |
350
|
|
|
* @param Project $project |
351
|
1 |
|
* @param Issue $issue |
352
|
|
|
* @param Attachment $attachment |
353
|
1 |
|
* |
354
|
|
|
* @return \Symfony\Component\HttpFoundation\BinaryFileResponse |
355
|
|
|
*/ |
356
|
|
|
public function getDownloadAttachment(Project $project, Issue $issue, Attachment $attachment) |
357
|
|
|
{ |
358
|
|
|
$issue->setRelation('project', $project); |
359
|
|
|
$attachment->setRelation('issue', $issue); |
360
|
|
|
|
361
|
|
|
$path = config('filesystems.disks.local.root') . '/' . config('tinyissue.uploads_dir') . '/' . $issue->project_id . '/' . $attachment->upload_token . '/' . $attachment->filename; |
362
|
|
|
|
363
|
|
|
return response()->download($path, $attachment->filename); |
364
|
1 |
|
} |
365
|
|
|
|
366
|
1 |
|
/** |
367
|
|
|
* Ajax: move an issue to another project. |
368
|
1 |
|
* |
369
|
|
|
* @param Issue $issue |
370
|
|
|
* @param Request $request |
371
|
|
|
* |
372
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
373
|
|
|
*/ |
374
|
|
|
public function postChangeProject(Issue $issue, Request $request) |
375
|
|
|
{ |
376
|
|
|
$issue->changeProject($request->input('project_id')); |
|
|
|
|
377
|
|
|
|
378
|
|
|
return response()->json(['status' => true, 'url' => $issue->to()]); |
379
|
|
|
} |
380
|
|
|
|
381
|
|
|
/** |
382
|
|
|
* Ajax: change status of an issue. |
383
|
|
|
* |
384
|
|
|
* @param Issue $issue |
385
|
|
|
* @param Request $request |
386
|
|
|
* |
387
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
388
|
|
|
*/ |
389
|
|
|
public function postChangeKanbanTag(Issue $issue, Request $request) |
390
|
|
|
{ |
391
|
|
|
$newTag = Tag::find((int) $request->input('newtag')); |
392
|
|
|
$oldTag = Tag::find((int) $request->input('oldtag')); |
393
|
|
|
|
394
|
|
|
$issue->changeKanbanTag($newTag, $oldTag, $this->auth->user()); |
|
|
|
|
395
|
|
|
|
396
|
|
|
return response()->json(['status' => true, 'issue' => $issue->id]); |
397
|
8 |
|
} |
398
|
|
|
} |
399
|
|
|
|
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.