|
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 Carbon\Carbon; |
|
11
|
|
|
use App\Models\Game; |
|
12
|
|
|
use App\Models\News; |
|
13
|
|
|
use App\Models\User; |
|
14
|
|
|
use App\Models\Comment; |
|
15
|
|
|
use App\Models\Shoutbox; |
|
16
|
|
|
use App\Helpers\MiscHelper; |
|
17
|
|
|
use App\Models\BoardThread; |
|
18
|
|
|
use App\Models\GamesCoupdecoeur; |
|
19
|
|
|
|
|
20
|
|
|
class IndexController extends Controller |
|
21
|
|
|
{ |
|
22
|
|
|
public function index() |
|
23
|
|
|
{ |
|
24
|
|
|
$gametypes = \DB::table('games_files_types') |
|
25
|
|
|
->select('id', 'title', 'short') |
|
26
|
|
|
->get(); |
|
27
|
|
|
$gtypes = []; |
|
|
|
|
|
|
28
|
|
|
foreach ($gametypes as $gt) { |
|
29
|
|
|
$t['title'] = $gt->title; |
|
|
|
|
|
|
30
|
|
|
$t['short'] = $gt->short; |
|
|
|
|
|
|
31
|
|
|
$gtypes[$gt->id] = $t; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
$news = News::with('user', 'comments')->orderBy('created_at', 'desc')->where('approved', '=', 1)->get()->take(5); |
|
|
|
|
|
|
35
|
|
|
$shoutbox = Shoutbox::with('user')->orderBy('created_at', 'desc')->limit(5)->get()->reverse(); |
|
|
|
|
|
|
36
|
|
|
$cdc = GamesCoupdecoeur::with('game')->orderBy('created_at', 'desc')->get()->first(); |
|
|
|
|
|
|
37
|
|
|
$latestadded = Game::with('maker', 'gamefiles', 'language', 'developers')->orderBy('created_at', 'desc')->limit(5)->get(); |
|
|
|
|
|
|
38
|
|
|
$latestreleased = Game::where('release_type', '!=', 99)->orderBy('release_date', 'desc')->limit(5)->get(); |
|
39
|
|
|
$threads = BoardThread::with('posts', 'user', 'last_user')->orderBy('last_created_at', 'desc')->limit(10)->get(); |
|
|
|
|
|
|
40
|
|
|
|
|
41
|
|
|
$topusers = \DB::table('users as u') |
|
42
|
|
|
->leftJoin('user_role_user as uru', 'u.id', '=', 'uru.user_id') |
|
43
|
|
|
->leftJoin('user_roles as ur', 'ur.id', '=', 'uru.role_id') |
|
44
|
|
|
->select([ |
|
45
|
|
|
'u.id as userid', |
|
46
|
|
|
'u.name as username', |
|
47
|
|
|
'u.created_at as usercreated_at', |
|
48
|
|
|
'ur.display_name as rolename', |
|
49
|
|
|
'ur.description as roledesc', |
|
50
|
|
|
]) |
|
51
|
|
|
->selectRaw('(SELECT SUM(obyx.value) FROM user_obyx LEFT JOIN obyx ON obyx.id = user_obyx.obyx_id WHERE user_obyx.user_id = u.id) as obyx') |
|
52
|
|
|
->orderBy('obyx', 'desc') |
|
53
|
|
|
->limit(5) |
|
54
|
|
|
->get(); |
|
55
|
|
|
|
|
56
|
|
|
$obyxmax = \DB::table('user_obyx as uo') |
|
57
|
|
|
->leftJoin('obyx as o', 'o.id', '=', 'uo.obyx_id') |
|
58
|
|
|
->selectRaw('SUM(o.value) as value') |
|
59
|
|
|
->groupBy('uo.user_id') |
|
60
|
|
|
->orderByRaw('SUM(o.value) DESC') |
|
61
|
|
|
->first(); |
|
62
|
|
|
|
|
63
|
|
|
if (\Auth::check()) { |
|
64
|
|
|
$pm = \Auth::user()->newThreadsCount(); |
|
65
|
|
|
} else { |
|
66
|
|
|
$pm = ''; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
$stats = \DB::table('games') |
|
70
|
|
|
->selectRaw('COUNT(id) as gamecount') |
|
71
|
|
|
->selectRaw('(SELECT COUNT(id) FROM makers) as makercount') |
|
72
|
|
|
->selectRaw('(SELECT COUNT(id) FROM developer) as developercount') |
|
73
|
|
|
->selectRaw('(SELECT COUNT(id) FROM users) as usercount') |
|
74
|
|
|
->selectRaw('(SELECT COUNT(id) FROM board_threads) as threadcount') |
|
75
|
|
|
->selectRaw('(SELECT COUNT(id) FROM board_posts) as postcount') |
|
76
|
|
|
->selectRaw('(SELECT COUNT(id) FROM shoutbox) as shoutboxcount') |
|
77
|
|
|
->selectRAW('(SELECT COUNT(id) FROM comments) as commentcount') |
|
78
|
|
|
->selectRaw('(SELECT COUNT(id) FROM logos) as logocount') |
|
79
|
|
|
->selectRaw('(SELECT SUM(downloadcount) FROM games_files) as downloadcount') |
|
80
|
|
|
->selectRaw('(SELECT SUM(filesize) FROM games_files) as totalsize') |
|
81
|
|
|
->selectRaw('(SELECT COUNT(id) FROM games_files) as filecount') |
|
82
|
|
|
->first(); |
|
83
|
|
|
|
|
84
|
|
|
$size = \DB::table('games_files') |
|
85
|
|
|
->selectRaw('SUM(filesize * downloadcount) as downsize') |
|
86
|
|
|
->groupBy('id') |
|
87
|
|
|
->get(); |
|
88
|
|
|
|
|
89
|
|
|
$res = 0; |
|
90
|
|
|
foreach ($size as $s) { |
|
91
|
|
|
$res += $s->downsize; |
|
92
|
|
|
} |
|
93
|
|
|
$size = MiscHelper::getReadableBytes($res); |
|
94
|
|
|
|
|
95
|
|
|
$topmonth = \DB::table('games') |
|
96
|
|
|
->leftJoin('games_developer', 'games.id', '=', 'games_developer.game_id') |
|
97
|
|
|
->leftJoin('developer', 'games_developer.developer_id', '=', 'developer.id') |
|
98
|
|
|
->leftJoin('makers', 'makers.id', '=', 'games.maker_id') |
|
99
|
|
|
->leftJoin('languages', 'languages.id', '=', 'games.lang_id') |
|
100
|
|
|
->leftJoin('comments', function ($join) { |
|
101
|
|
|
$join->on('comments.content_id', '=', 'games.id'); |
|
102
|
|
|
$join->on('comments.content_type', '=', \DB::raw("'game'")); |
|
103
|
|
|
}) |
|
104
|
|
|
->leftJoin('games_files', 'games_files.game_id', '=', 'games.id') |
|
105
|
|
|
->leftJoin('users', 'games_developer.user_id', '=', 'users.id') |
|
106
|
|
|
->select([ |
|
107
|
|
|
'games.id as gameid', |
|
108
|
|
|
'games.title as gametitle', |
|
109
|
|
|
'games.subtitle as gamesubtitle', |
|
110
|
|
|
'developer.name as developername', |
|
111
|
|
|
'developer.id as developerid', |
|
112
|
|
|
'developer.created_at as developerdate', |
|
113
|
|
|
'developer.user_id as developeruserid', |
|
114
|
|
|
'users.name as developerusername', |
|
115
|
|
|
'games.created_at as gamecreated_at', |
|
116
|
|
|
'makers.short as makershort', |
|
117
|
|
|
'makers.title as makertitle', |
|
118
|
|
|
'makers.id as makerid', |
|
119
|
|
|
'languages.id as lang_id', |
|
120
|
|
|
'languages.name as lang_name', |
|
121
|
|
|
'languages.short as lang_short', |
|
122
|
|
|
]) |
|
123
|
|
|
->selectRaw('(SELECT COUNT(id) FROM comments WHERE content_id = games.id AND content_type = "game") as commentcount') |
|
124
|
|
|
->selectRaw('(SELECT SUM(vote_up) FROM comments WHERE content_id = games.id AND content_type = "game") as voteup') |
|
125
|
|
|
->selectRaw('(SELECT SUM(vote_down) FROM comments WHERE content_id = games.id AND content_type = "game") as votedown') |
|
126
|
|
|
->selectRaw('MAX(games_files.release_type) as gametype') |
|
127
|
|
|
->selectRaw("(SELECT STR_TO_DATE(CONCAT(release_year,'-',release_month,'-',release_day ), '%Y-%m-%d') FROM games_files WHERE game_id = games.id ORDER BY release_year DESC, release_month DESC, release_day DESC LIMIT 1) as releasedate") |
|
128
|
|
|
->selectRaw('(SELECT COUNT(id) FROM games_coupdecoeur WHERE game_id = games.id) as cdccount') |
|
129
|
|
|
->where('comments.created_at', '>', Carbon::today()->addMonth(-1)->toDateString()) |
|
130
|
|
|
->orderByRaw('(voteup - votedown) / (voteup + votedown) DESC') |
|
131
|
|
|
->groupBy('games.id') |
|
132
|
|
|
->limit(5)->get(); |
|
133
|
|
|
|
|
134
|
|
|
$topalltime = Game::orderBy('avg', 'desc')->limit(5)->get(); |
|
|
|
|
|
|
135
|
|
|
$latestcomments = Comment::with('game')->whereContentType('game')->orderBy('created_at', 'desc')->limit(5)->get(); |
|
136
|
|
|
$randomgame = Game::inRandomOrder()->first(); |
|
|
|
|
|
|
137
|
|
|
|
|
138
|
|
|
$newuser = User::orderBy('created_at', 'desc')->first(); |
|
139
|
|
|
|
|
140
|
|
|
return view('index.index', [ |
|
141
|
|
|
'news' => $news, |
|
142
|
|
|
'shoutbox' => $shoutbox, |
|
143
|
|
|
'cdc' => $cdc, |
|
144
|
|
|
'latestadded' => $latestadded, |
|
145
|
|
|
'gametypes' => $gtypes, |
|
146
|
|
|
'latestreleased' => $latestreleased, |
|
147
|
|
|
'threads' => $threads, |
|
148
|
|
|
'obeymax' => $obyxmax, |
|
149
|
|
|
'topusers' => $topusers, |
|
150
|
|
|
'pm' => $pm, |
|
151
|
|
|
'stats' => $stats, |
|
152
|
|
|
'topmonth' => $topmonth, |
|
153
|
|
|
'topalltime' => $topalltime, |
|
154
|
|
|
'latestcomments' => $latestcomments, |
|
155
|
|
|
'size' => $size, |
|
156
|
|
|
'randomgame' => $randomgame, |
|
157
|
|
|
'newuser' => $newuser, |
|
158
|
|
|
]); |
|
159
|
|
|
} |
|
160
|
|
|
} |
|
161
|
|
|
|
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.