1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* rmarchiv.tk |
5
|
|
|
* (c) 2016-2017 by Marcel 'ryg' Hering |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace App\Http\Controllers; |
9
|
|
|
|
10
|
|
|
use App\Events\Obyx; |
11
|
|
|
use App\Models\Comment; |
12
|
|
|
use Illuminate\Http\Request; |
13
|
|
|
use App\Helpers\DatabaseHelper; |
14
|
|
|
use GrahamCampbell\Markdown\Facades\Markdown; |
15
|
|
|
|
16
|
|
|
class CommentController extends Controller |
17
|
|
|
{ |
18
|
|
View Code Duplication |
public function delete(Request $request, $comment_id) |
|
|
|
|
19
|
|
|
{ |
20
|
|
|
$c = Comment::whereId($comment_id)->first(); |
|
|
|
|
21
|
|
|
$c->deleted = 1; |
|
|
|
|
22
|
|
|
$c->delete_reason = $request->get('reason'); |
23
|
|
|
$c->save(); |
24
|
|
|
|
25
|
|
|
return redirect()->back(); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
View Code Duplication |
public function restore(Request $request, $comment_id) |
|
|
|
|
29
|
|
|
{ |
30
|
|
|
$c = Comment::whereId($comment_id)->first(); |
|
|
|
|
31
|
|
|
$c->deleted = 0; |
|
|
|
|
32
|
|
|
$c->delete_reason = ''; |
33
|
|
|
$c->save(); |
34
|
|
|
|
35
|
|
|
return redirect()->back(); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function add(Request $request) |
39
|
|
|
{ |
40
|
|
|
$comment = new Comment(); |
41
|
|
|
|
42
|
|
|
$comment->user_id = \Auth::id(); |
|
|
|
|
43
|
|
|
$comment->content_id = $request->get('content_id'); |
|
|
|
|
44
|
|
|
$comment->content_type = $request->get('content_type'); |
45
|
|
|
$comment->comment_md = $request->get('msg'); |
|
|
|
|
46
|
|
|
$comment->comment_html = Markdown::convertToHtml($request->get('msg')); |
47
|
|
|
|
48
|
|
|
$rate = $request->get('rating'); |
49
|
|
|
|
50
|
|
|
if ($rate == 'up') { |
51
|
|
|
$comment->vote_up = 1; |
|
|
|
|
52
|
|
|
$comment->vote_down = 0; |
53
|
|
|
event(new Obyx('rating', \Auth::id())); |
54
|
|
|
} elseif ($rate == 'down') { |
55
|
|
|
$comment->vote_up = 0; |
|
|
|
|
56
|
|
|
$comment->vote_down = 1; |
57
|
|
|
event(new Obyx('rating', \Auth::id())); |
58
|
|
|
} else { |
59
|
|
|
$comment->vote_up = 0; |
|
|
|
|
60
|
|
|
$comment->vote_down = 0; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
$comment->save(); |
64
|
|
|
|
65
|
|
|
event(new Obyx('comment', \Auth::id())); |
66
|
|
|
|
67
|
|
|
if ($request->get('content_type') == 'game') { |
68
|
|
|
DatabaseHelper::setVotesAndComments($request->get('content_id')); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
return redirect()->action('MsgBoxController@comment_add', [$request->get('content_type'), $request->get('content_id')]); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.