|
1
|
|
|
<?php |
|
2
|
|
|
|
|
|
|
|
|
|
3
|
|
|
namespace BristolSU\Module\UploadFile\Http\Controllers\AdminApi; |
|
4
|
|
|
|
|
5
|
|
|
use BristolSU\Module\UploadFile\Events\CommentCreated; |
|
6
|
|
|
use BristolSU\Module\UploadFile\Events\CommentDeleted; |
|
7
|
|
|
use BristolSU\Module\UploadFile\Events\CommentUpdated; |
|
8
|
|
|
use BristolSU\Module\UploadFile\Http\Controllers\Controller; |
|
9
|
|
|
use BristolSU\Module\UploadFile\Models\Comment; |
|
10
|
|
|
use BristolSU\Module\UploadFile\Models\File; |
|
11
|
|
|
use BristolSU\Support\Activity\Activity; |
|
12
|
|
|
use BristolSU\Support\ActivityInstance\Contracts\ActivityInstanceResolver; |
|
13
|
|
|
use BristolSU\Support\Authentication\Contracts\Authentication; |
|
14
|
|
|
use BristolSU\Support\ModuleInstance\ModuleInstance; |
|
15
|
|
|
use Illuminate\Auth\Access\AuthorizationException; |
|
16
|
|
|
use Illuminate\Http\Request; |
|
17
|
|
|
|
|
18
|
|
|
class CommentController extends Controller |
|
|
|
|
|
|
19
|
|
|
{ |
|
20
|
|
|
|
|
21
|
3 |
|
public function index(Request $request, Activity $activity, ModuleInstance $moduleInstance, File $file) |
|
|
|
|
|
|
22
|
|
|
{ |
|
23
|
3 |
|
$this->authorize('admin.comment.index'); |
|
24
|
|
|
|
|
25
|
2 |
|
return $file->comments; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
5 |
|
public function store(Request $request, Activity $activity, ModuleInstance $moduleInstance, File $file) |
|
|
|
|
|
|
29
|
|
|
{ |
|
30
|
5 |
|
$this->authorize('admin.comment.store'); |
|
31
|
|
|
|
|
32
|
4 |
|
$comment = $file->comments()->create([ |
|
|
|
|
|
|
33
|
4 |
|
'comment' => $request->input('comment'), |
|
34
|
4 |
|
'posted_by' => app(Authentication::class)->getUser()->id |
|
|
|
|
|
|
35
|
|
|
]); |
|
|
|
|
|
|
36
|
|
|
|
|
37
|
4 |
|
event(new CommentCreated($comment)); |
|
38
|
|
|
|
|
39
|
4 |
|
return $comment; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
5 |
|
public function destroy(Request $request, Activity $activity, ModuleInstance $moduleInstance, Comment $comment) |
|
|
|
|
|
|
43
|
|
|
{ |
|
44
|
5 |
|
$this->authorize('admin.comment.destroy'); |
|
45
|
|
|
|
|
46
|
4 |
|
$comment->delete(); |
|
47
|
|
|
|
|
48
|
4 |
|
event(new CommentDeleted($comment)); |
|
49
|
|
|
|
|
50
|
4 |
|
return $comment; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
5 |
|
public function update(Request $request, Activity $activity, ModuleInstance $moduleInstance, Comment $comment) |
|
|
|
|
|
|
54
|
|
|
{ |
|
55
|
5 |
|
$this->authorize('admin.comment.update'); |
|
56
|
|
|
|
|
57
|
4 |
|
$comment->comment = $request->input('comment', $comment->comment); |
|
58
|
|
|
|
|
59
|
4 |
|
$comment->save(); |
|
60
|
|
|
|
|
61
|
4 |
|
event(new CommentUpdated($comment)); |
|
62
|
|
|
|
|
63
|
4 |
|
return $comment; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
} |