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\Models\Tag; |
11
|
|
|
use App\Models\Game; |
12
|
|
|
use App\Models\TagRelation; |
13
|
|
|
use Illuminate\Http\Request; |
14
|
|
|
|
15
|
|
|
class TaggingController extends Controller |
16
|
|
|
{ |
17
|
|
|
public function index($orderby = 'tag', $direction = 'asc') |
18
|
|
|
{ |
19
|
|
|
$tags = Tag::all()->sortBy('title'); |
20
|
|
|
|
21
|
|
|
return view('tags.index', [ |
22
|
|
|
'tags' => $tags, |
23
|
|
|
'orderby' => $orderby, |
24
|
|
|
'direction' => $direction, |
25
|
|
|
]); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function showGames($id, $orderby = 'title', $direction = 'asc') |
29
|
|
|
{ |
30
|
|
|
$tag = Tag::whereId($id)->first(); |
31
|
|
|
|
32
|
|
|
if ($orderby == 'developer.name') { |
33
|
|
|
$games = Game::Join('games_developer', 'games.id', '=', 'games_developer.game_id') |
34
|
|
|
->Join('developer', 'games_developer.developer_id', '=', 'developer.id') |
35
|
|
|
->Join('tag_relations', 'tag_relations.content_id', '=', 'games.id') |
36
|
|
|
->Where('tag_relations.tag_id', '=', $id) |
37
|
|
|
->where('tag_relations.content_type', '=', 'game') |
38
|
|
|
->orderBy($orderby, $direction) |
39
|
|
|
->select('games.*') |
40
|
|
|
->paginate(25); |
41
|
|
|
} else { |
42
|
|
|
$games = Game::Join('tag_relations', 'tag_relations.content_id', '=', 'games.id') |
43
|
|
|
->Where('tag_relations.tag_id', '=', $id) |
44
|
|
|
->where('tag_relations.content_type', '=', 'game') |
45
|
|
|
->orderBy($orderby, $direction) |
46
|
|
|
->orderBy('title') |
47
|
|
|
->orderBy('subtitle') |
48
|
|
|
->select('games.*') |
49
|
|
|
->paginate(25); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
return view('tags.show', [ |
53
|
|
|
'games' => $games, |
54
|
|
|
'tag' => $tag, |
55
|
|
|
'orderby' => $orderby, |
56
|
|
|
'direction' => $direction, |
57
|
|
|
]); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function store(Request $request) |
61
|
|
|
{ |
62
|
|
|
$this->validate($request, [ |
63
|
|
|
'title' => 'required', |
64
|
|
|
'content_id' => 'required', |
65
|
|
|
'content_type' => 'required', |
66
|
|
|
]); |
67
|
|
|
|
68
|
|
|
$tag = Tag::firstOrCreate(['title' => $request->get('title')]); |
|
|
|
|
69
|
|
|
$tagid = $tag->id; |
70
|
|
|
|
71
|
|
|
TagRelation::firstOrCreate([ |
72
|
|
|
'tag_id' => $tagid, |
73
|
|
|
'user_id' => \Auth::id(), |
74
|
|
|
'content_id' => $request->get('content_id'), |
75
|
|
|
'content_type' => $request->get('content_type'), |
76
|
|
|
]); |
77
|
|
|
|
78
|
|
|
if ($request->get('content_type') == 'news') { |
79
|
|
|
return \Redirect::action('NewsController@show', $request->get('content_id')); |
80
|
|
|
} elseif ($request->get('content_type') == 'game') { |
81
|
|
|
return \Redirect::action('GameController@show', $request->get('content_id')); |
82
|
|
|
} elseif ($request->get('content_type') == 'resource') { |
83
|
|
|
return \Redirect::action('ResourceController@show', $request->get('content_id')); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
return \Redirect::action('IndexController@index'); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function delete_gametag($gameid, $tagid) |
90
|
|
|
{ |
91
|
|
|
$tag = TagRelation::whereContentId($gameid)->where('content_type', '=', 'game')->where('tag_id', '=', $tagid)->first(); |
92
|
|
|
$tag->delete(); |
93
|
|
|
|
94
|
|
|
return redirect()->action('GameController@edit', $gameid); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.