MissingController::index_gamescreens()   B
last analyzed

Complexity

Conditions 4
Paths 6

Size

Total Lines 42
Code Lines 33

Duplication

Lines 42
Ratio 100 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 42
loc 42
rs 8.5806
cc 4
eloc 33
nc 6
nop 2
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\Game;
11
12
class MissingController extends Controller
13
{
14
    //Spiele mit fehlenden Tags
15
    public function index_notags($orderby = 'title', $direction = 'asc')
16
    {
17
        $rows = (\Auth::check()) ? \Auth::user()->settings->rows_per_page_games : config('app.rows_per_page_games');
18
19
        if ($orderby == 'developer.name') {
20
            $games = Game::Join('games_developer', 'games.id', '=', 'games_developer.game_id')
21
                ->Join('developer', 'games_developer.developer_id', '=', 'developer.id')
22
                ->leftJoin('tag_relations as tr', function ($join) {
23
                    $join->on('tr.content_id', '=', 'games.id');
24
                    $join->on('tr.content_type', '=', \DB::raw("'game'"));
25
                })
26
                ->groupBy('games.id')
27
                ->groupBy('tr.tag_id')
28
                ->orderBy($orderby, $direction)
29
                ->havingRaw('COUNT(tr.id) < 1')
30
                ->paginate($rows, [
31
                    'games.*',
32
                ]);
33
        } elseif ($orderby == 'game.release_date') {
34
            $games = Game::Join('games_files', 'games.id', '=', 'games_files.game_id')
35
                ->leftJoin('tag_relations as tr', function ($join) {
36
                    $join->on('tr.content_id', '=', 'games.id');
37
                    $join->on('tr.content_type', '=', \DB::raw("'game'"));
38
                })
39
                ->groupBy('games.id')
40
                ->groupBy('tr.tag_id')
41
                ->orderBy('games_files.release_year', $direction)
42
                ->orderBy('games_files.release_month', $direction)
43
                ->orderBy('games_files.release_day', $direction)
44
                ->havingRaw('COUNT(tr.id) < 1')
45
                ->paginate($rows, [
46
                    'games.*',
47
                ]);
48
        } else {
49
            $games = Game::with(['tags'])->select(['games.*', \DB::raw('COUNT(tr.id) as ctr')])
50
                ->leftJoin('tag_relations as tr', function ($join) {
51
                    $join->on('tr.content_id', '=', 'games.id');
52
                    $join->on('tr.content_type', '=', \DB::raw("'game'"));
53
                })
54
                ->groupBy('games.id')
55
                ->groupBy('tr.tag_id')
56
                ->orderBy($orderby, $direction)
57
                ->havingRaw('COUNT(tr.id) < 1')
58
                ->paginate($rows, [
59
                    'games.*',
60
                ]);
61
        }
62
63
        return view('missing.notags.index', [
64
            'games'     => $games,
65
            'orderby'   => $orderby,
66
            'direction' => $direction,
67
        ]);
68
    }
69
70
    //Spiele mit fehlenden Screenshots anzeigen
71 View Code Duplication
    public function index_gamescreens($orderby = 'title', $direction = 'asc')
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
72
    {
73
        $rows = (\Auth::check()) ? \Auth::user()->settings->rows_per_page_games : config('app.rows_per_page_games');
74
75
        if ($orderby == 'developer.name') {
76
            $games = Game::Join('games_developer', 'games.id', '=', 'games_developer.game_id')
77
                ->Join('developer', 'games_developer.developer_id', '=', 'developer.id')
78
                ->leftJoin('screenshots as tr', 'tr.game_id', '=', 'games.id')
79
                ->groupBy('games.id')
80
                ->orderBy($orderby, $direction)
81
                ->havingRaw('COUNT(tr.id) < 1')
82
                ->paginate($rows, [
83
                    'games.*',
84
                ]);
85
        } elseif ($orderby == 'game.release_date') {
86
            $games = Game::Join('games_files', 'games.id', '=', 'games_files.game_id')
87
                ->leftJoin('screenshots as tr', 'tr.game_id', '=', 'games.id')
88
                ->groupBy('games.id')
89
                ->orderBy('games_files.release_year', $direction)
90
                ->orderBy('games_files.release_month', $direction)
91
                ->orderBy('games_files.release_day', $direction)
92
                ->havingRaw('COUNT(tr.id) < 1')
93
                ->paginate($rows, [
94
                    'games.*',
95
                ]);
96
        } else {
97
            $games = Game::with(['tags'])->select(['games.*', \DB::raw('COUNT(tr.id) as ctr')])
98
                ->leftJoin('screenshots as tr', 'tr.game_id', '=', 'games.id')
99
                ->groupBy('games.id')
100
                ->orderBy($orderby, $direction)
101
                ->havingRaw('COUNT(tr.id) < 1')
102
                ->paginate($rows, [
103
                    'games.*',
104
                ]);
105
        }
106
107
        return view('missing.gamescreens.index', [
108
            'games'     => $games,
109
            'orderby'   => $orderby,
110
            'direction' => $direction,
111
        ]);
112
    }
113
114
    //Spiele mit fehlenden Spieledateien anzeigen
115 View Code Duplication
    public function index_gamefiles($orderby = 'title', $direction = 'asc')
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
116
    {
117
        $rows = (\Auth::check()) ? \Auth::user()->settings->rows_per_page_games : config('app.rows_per_page_games');
118
119
        if ($orderby == 'developer.name') {
120
            $games = Game::Join('games_developer', 'games.id', '=', 'games_developer.game_id')
121
                ->leftJoin('games_files as tr', 'tr.game_id', '=', 'games.id')
122
                ->leftJoin('screenshots as tr', 'tr.game_id', '=', 'games.id')
123
                ->groupBy('games.id')
124
                ->orderBy($orderby, $direction)
125
                ->havingRaw('COUNT(tr.id) < 1')
126
                ->paginate($rows, [
127
                    'games.*',
128
                ]);
129
        } elseif ($orderby == 'game.release_date') {
130
            $games = Game::Join('games_files', 'games.id', '=', 'games_files.game_id')
131
                ->leftJoin('games_files as tr', 'tr.game_id', '=', 'games.id')
132
                ->groupBy('games.id')
133
                ->orderBy('games_files.release_year', $direction)
134
                ->orderBy('games_files.release_month', $direction)
135
                ->orderBy('games_files.release_day', $direction)
136
                ->havingRaw('COUNT(tr.id) < 1')
137
                ->paginate($rows, [
138
                    'games.*',
139
                ]);
140
        } else {
141
            $games = Game::with(['tags'])->select(['games.*', \DB::raw('COUNT(tr.id) as ctr')])
142
                ->leftJoin('games_files as tr', 'tr.game_id', '=', 'games.id')
143
                ->groupBy('games.id')
144
                ->orderBy($orderby, $direction)
145
                ->havingRaw('COUNT(tr.id) < 1')
146
                ->paginate($rows, [
147
                    'games.*',
148
                ]);
149
        }
150
151
        return view('missing.gamefiles.index', [
152
            'games'     => $games,
153
            'orderby'   => $orderby,
154
            'direction' => $direction,
155
        ]);
156
    }
157
158
    //Spiele mit fehlender Spielebeschreibung anzeigen
159
    public function index_gamedesc($orderby = 'title', $direction = 'asc')
160
    {
161
        $rows = (\Auth::check()) ? \Auth::user()->settings->rows_per_page_games : config('app.rows_per_page_games');
162
163
        if ($orderby == 'developer.name') {
164
            $games = Game::Join('games_developer', 'games.id', '=', 'games_developer.game_id')
165
                ->where('games.desc_md', '=', '')
166
                ->groupBy('games.id')
167
                ->orderBy($orderby, $direction)
168
                ->paginate($rows, [
169
                    'games.*',
170
                ]);
171
        } elseif ($orderby == 'game.release_date') {
172
            $games = Game::Join('games_files', 'games.id', '=', 'games_files.game_id')
173
                ->where('games.desc_md', '=', '')
174
                ->groupBy('games.id')
175
                ->orderBy('games_files.release_year', $direction)
176
                ->orderBy('games_files.release_month', $direction)
177
                ->orderBy('games_files.release_day', $direction)
178
                ->paginate($rows, [
179
                    'games.*',
180
                ]);
181
        } else {
182
            $games = Game::with(['tags'])->select(['games.*'])
183
                ->where('games.desc_md', '=', '')
184
                ->groupBy('games.id')
185
                ->orderBy($orderby, $direction)
186
                ->paginate($rows, [
187
                    'games.*',
188
                ]);
189
        }
190
191
        return view('missing.gamedesc.index', [
192
            'games'     => $games,
193
            'orderby'   => $orderby,
194
            'direction' => $direction,
195
        ]);
196
    }
197
}
198