|
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\Events\Obyx; |
|
12
|
|
|
use App\Models\Game; |
|
13
|
|
|
use App\Models\Comment; |
|
14
|
|
|
use App\Models\License; |
|
15
|
|
|
use App\Events\GameView; |
|
16
|
|
|
use App\Models\Language; |
|
17
|
|
|
use App\Models\GamesFile; |
|
18
|
|
|
use App\Models\Screenshot; |
|
19
|
|
|
use App\Models\TagRelation; |
|
20
|
|
|
use Illuminate\Http\Request; |
|
21
|
|
|
use App\Models\GamesDeveloper; |
|
22
|
|
|
use App\Helpers\DatabaseHelper; |
|
23
|
|
|
use Illuminate\Support\Facades\Input; |
|
24
|
|
|
|
|
25
|
|
|
class GameController extends Controller |
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
28
|
|
|
* Display a listing of the resource. |
|
29
|
|
|
* |
|
30
|
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
|
|
31
|
|
|
*/ |
|
32
|
|
|
public function index($orderby = 'title', $direction = 'asc') |
|
33
|
|
|
{ |
|
34
|
|
|
$rows = (\Auth::check()) ? \Auth::user()->settings->rows_per_page_games : config('app.rows_per_page_games'); |
|
35
|
|
|
|
|
36
|
|
|
if ($orderby == 'developer.name') { |
|
37
|
|
|
$games = Game::Join('games_developer', 'games.id', '=', 'games_developer.game_id') |
|
38
|
|
|
->Join('developer', 'games_developer.developer_id', '=', 'developer.id') |
|
39
|
|
|
->orderBy($orderby, $direction)->select('games.*')->paginate($rows); |
|
40
|
|
|
} else { |
|
41
|
|
|
$games = Game::orderBy($orderby, $direction)->orderBy('title')->orderBy('subtitle')->paginate($rows); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
return view('games.index', [ |
|
45
|
|
|
'games' => $games, |
|
46
|
|
|
'maxviews' => DatabaseHelper::getGameViewsMax(), |
|
47
|
|
|
'orderby' => $orderby, |
|
48
|
|
|
'direction' => $direction, |
|
49
|
|
|
]); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Show the form for creating a new resource. |
|
54
|
|
|
* |
|
55
|
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
|
|
56
|
|
|
*/ |
|
57
|
|
|
public function create() |
|
58
|
|
|
{ |
|
59
|
|
|
$maker = \DB::table('makers') |
|
60
|
|
|
->orderBy('makers.title') |
|
61
|
|
|
->get(); |
|
62
|
|
|
|
|
63
|
|
|
$langs = \DB::table('languages') |
|
64
|
|
|
->orderBy('id') |
|
65
|
|
|
->get(); |
|
66
|
|
|
|
|
67
|
|
|
$licenses = License::all(); |
|
68
|
|
|
|
|
69
|
|
|
return view('games.create', ['makers' => $maker, 'langs' => $langs, 'licenses' => $licenses]); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Store a newly created resource in storage. |
|
74
|
|
|
* |
|
75
|
|
|
* @param \Illuminate\Http\Request $request |
|
76
|
|
|
* |
|
77
|
|
|
* @return \Illuminate\Http\RedirectResponse |
|
78
|
|
|
*/ |
|
79
|
|
|
public function store(Request $request) |
|
80
|
|
|
{ |
|
81
|
|
|
$this->validate($request, [ |
|
82
|
|
|
'title' => 'required', |
|
83
|
|
|
'maker' => 'required|not_in:0', |
|
84
|
|
|
'language' => 'required|not_in:0', |
|
85
|
|
|
'developer' => 'required', |
|
86
|
|
|
]); |
|
87
|
|
|
|
|
88
|
|
|
$devid = DatabaseHelper::developerId_from_developerName($request->get('developer')); |
|
89
|
|
|
if ($devid == 0) { |
|
90
|
|
|
$devid = DatabaseHelper::developer_add_and_get_developerId($request->get('developer')); |
|
91
|
|
|
event(new Obyx('dev-add', \Auth::id())); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
$langid = DatabaseHelper::langId_from_short($request->get('language')); |
|
95
|
|
|
|
|
96
|
|
|
$g = new Game(); |
|
|
|
|
|
|
97
|
|
|
$g->title = $request->get('title'); |
|
|
|
|
|
|
98
|
|
|
$g->subtitle = $request->get('subtitle', ''); |
|
|
|
|
|
|
99
|
|
|
$g->desc_md = $request->get('msg'); |
|
|
|
|
|
|
100
|
|
|
$g->desc_html = \Markdown::convertToHtml($request->get('msg')); |
|
|
|
|
|
|
101
|
|
|
$g->website_url = $request->get('websiteurl', ''); |
|
102
|
|
|
$g->maker_id = $request->get('maker'); |
|
|
|
|
|
|
103
|
|
|
$g->lang_id = $langid; |
|
|
|
|
|
|
104
|
|
|
$g->user_id = \Auth::id(); |
|
|
|
|
|
|
105
|
|
|
$g->youtube = $request->get('youtube'); |
|
|
|
|
|
|
106
|
|
|
$g->atelier_id = $request->get('atelier_id'); |
|
|
|
|
|
|
107
|
|
|
$g->license_id = $request->get('license'); |
|
|
|
|
|
|
108
|
|
|
$g->save(); |
|
109
|
|
|
|
|
110
|
|
|
\DB::table('games_developer')->insert([ |
|
111
|
|
|
'user_id' => \Auth::id(), |
|
112
|
|
|
'game_id' => $g->id, |
|
113
|
|
|
'developer_id' => $devid, |
|
114
|
|
|
'created_at' => Carbon::now(), |
|
115
|
|
|
]); |
|
116
|
|
|
|
|
117
|
|
|
event(new Obyx('game-add', \Auth::id())); |
|
118
|
|
|
|
|
119
|
|
|
return redirect()->action('MsgBoxController@game_add', [$g->id]); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* Add developer to game. |
|
124
|
|
|
* |
|
125
|
|
|
* @param Request $request |
|
126
|
|
|
* @param $id |
|
127
|
|
|
* |
|
128
|
|
|
* @return \Illuminate\Http\RedirectResponse |
|
129
|
|
|
*/ |
|
130
|
|
|
public function store_developer(Request $request, $id) |
|
131
|
|
|
{ |
|
132
|
|
|
$this->validate($request, [ |
|
133
|
|
|
'developer' => 'required', |
|
134
|
|
|
]); |
|
135
|
|
|
|
|
136
|
|
|
$devid = DatabaseHelper::developerId_from_developerName($request->get('developer')); |
|
137
|
|
|
if ($devid == 0) { |
|
138
|
|
|
$devid = DatabaseHelper::developer_add_and_get_developerId($request->get('developer')); |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
\DB::table('games_developer')->insert([ |
|
142
|
|
|
'user_id' => \Auth::id(), |
|
143
|
|
|
'game_id' => $id, |
|
144
|
|
|
'developer_id' => $devid, |
|
145
|
|
|
'created_at' => Carbon::now(), |
|
146
|
|
|
]); |
|
147
|
|
|
|
|
148
|
|
|
return redirect()->action('GameController@edit', [$id]); |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
/** |
|
152
|
|
|
* Display the specified resource. |
|
153
|
|
|
* |
|
154
|
|
|
* @param int $id |
|
155
|
|
|
* |
|
156
|
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
|
|
157
|
|
|
*/ |
|
158
|
|
|
public function show($id) |
|
159
|
|
|
{ |
|
160
|
|
|
$game = Game::with('developers')->whereId($id)->first(); |
|
161
|
|
|
|
|
162
|
|
|
event(new GameView($id)); |
|
163
|
|
|
|
|
164
|
|
|
return view('games.show', [ |
|
165
|
|
|
'game' => $game, |
|
166
|
|
|
]); |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
/** |
|
170
|
|
|
* Show the form for editing the specified resource. |
|
171
|
|
|
* |
|
172
|
|
|
* @param int $id |
|
173
|
|
|
* |
|
174
|
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
|
|
175
|
|
|
*/ |
|
176
|
|
|
public function edit($id) |
|
177
|
|
|
{ |
|
178
|
|
|
$makers = \DB::table('makers') |
|
179
|
|
|
->get(); |
|
180
|
|
|
|
|
181
|
|
|
$langs = \DB::table('languages') |
|
182
|
|
|
->get(); |
|
183
|
|
|
|
|
184
|
|
|
$creds = \DB::table('user_credit_types') |
|
185
|
|
|
->orderBy('title') |
|
186
|
|
|
->get(); |
|
187
|
|
|
|
|
188
|
|
|
$credittypes = []; |
|
189
|
|
|
foreach ($creds as $cred) { |
|
190
|
|
|
$credittypes[$cred->id]['title'] = $cred->title; |
|
191
|
|
|
$credittypes[$cred->id]['id'] = $cred->id; |
|
|
|
|
|
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
|
|
$licenses = License::get(); |
|
195
|
|
|
|
|
196
|
|
|
$game = Game::whereId($id)->first(); |
|
197
|
|
|
|
|
198
|
|
|
return view('games.edit', [ |
|
199
|
|
|
'game' => $game, |
|
200
|
|
|
'makers' => $makers, |
|
201
|
|
|
//'developers' => $developers, |
|
|
|
|
|
|
202
|
|
|
'langs' => $langs, |
|
203
|
|
|
'licenses' => $licenses, |
|
204
|
|
|
//'credittypes' => $credittypes, |
|
|
|
|
|
|
205
|
|
|
//'credits' => $credits, |
|
|
|
|
|
|
206
|
|
|
//'tags' => $tags, |
|
|
|
|
|
|
207
|
|
|
]); |
|
208
|
|
|
} |
|
209
|
|
|
|
|
210
|
|
|
/** |
|
211
|
|
|
* Update the specified resource in storage. |
|
212
|
|
|
* |
|
213
|
|
|
* @param \Illuminate\Http\Request $request |
|
214
|
|
|
* @param int $id |
|
215
|
|
|
* |
|
216
|
|
|
* @return \Illuminate\Http\RedirectResponse |
|
217
|
|
|
*/ |
|
218
|
|
|
public function update(Request $request, $id) |
|
219
|
|
|
{ |
|
220
|
|
|
$lang = Language::whereShort($request->get('language'))->first(); |
|
221
|
|
|
|
|
222
|
|
|
$game = Game::whereId($id)->first(); |
|
|
|
|
|
|
223
|
|
|
$game->title = $request->get('title'); |
|
|
|
|
|
|
224
|
|
|
$game->subtitle = $request->get('subtitle'); |
|
|
|
|
|
|
225
|
|
|
$game->maker_id = $request->get('maker'); |
|
|
|
|
|
|
226
|
|
|
$game->lang_id = $lang->id; |
|
|
|
|
|
|
227
|
|
|
$game->desc_md = $request->get('msg'); |
|
|
|
|
|
|
228
|
|
|
$game->desc_html = \Markdown::convertToHtml($request->get('msg')); |
|
|
|
|
|
|
229
|
|
|
$game->website_url = $request->get('websiteurl'); |
|
|
|
|
|
|
230
|
|
|
$game->youtube = $request->get('youtube'); |
|
|
|
|
|
|
231
|
|
|
$game->atelier_id = $request->get('atelier_id'); |
|
|
|
|
|
|
232
|
|
|
$game->release_date = Carbon::createFromDate($request->get('releasedate_year'), $request->get('releasedate_month'), $request->get('releasedate_day')); |
|
233
|
|
|
$game->license_id = $request->get('license'); |
|
|
|
|
|
|
234
|
|
|
$game->save(); |
|
235
|
|
|
|
|
236
|
|
|
return redirect()->action('GameController@edit', [$id]); |
|
237
|
|
|
} |
|
238
|
|
|
|
|
239
|
|
|
/** |
|
240
|
|
|
* Remove the specified resource from storage. |
|
241
|
|
|
* |
|
242
|
|
|
* @param int $id |
|
243
|
|
|
* |
|
244
|
|
|
* @return \Illuminate\Http\RedirectResponse |
|
245
|
|
|
*/ |
|
246
|
|
|
public function destroy($id) |
|
247
|
|
|
{ |
|
248
|
|
|
$validate = Input::get('confirm', ''); |
|
249
|
|
|
if (\Auth::check()) { |
|
250
|
|
|
if (\Auth::user()->can('delete-games')) { |
|
251
|
|
|
if ($validate == 'CONFIRM+'.$id) { |
|
252
|
|
|
Game::whereId($id)->delete(); |
|
253
|
|
|
GamesFile::whereGameId($id)->delete(); |
|
254
|
|
|
Screenshot::whereGameId($id)->delete(); |
|
255
|
|
|
GamesDeveloper::whereGameId($id)->delete(); |
|
256
|
|
|
Comment::whereContentId($id)->where('content_type', '=', 'game')->delete(); |
|
257
|
|
|
TagRelation::whereContentId($id)->where('content_type', '=', 'game')->delete(); |
|
258
|
|
|
} else { |
|
259
|
|
|
return redirect()->action('GameController@edit', $id); |
|
|
|
|
|
|
260
|
|
|
} |
|
261
|
|
|
} |
|
262
|
|
|
} |
|
263
|
|
|
|
|
264
|
|
|
return redirect()->route('home'); |
|
265
|
|
|
} |
|
266
|
|
|
|
|
267
|
|
|
public function destroy_developer(Request $request, $id) |
|
268
|
|
|
{ |
|
269
|
|
|
\DB::table('games_developer') |
|
270
|
|
|
->where('game_id', '=', $id) |
|
271
|
|
|
->where('developer_id', '=', $request->get('devid')) |
|
272
|
|
|
->delete(); |
|
273
|
|
|
|
|
274
|
|
|
return redirect()->action('GameController@edit', [$id]); |
|
275
|
|
|
} |
|
276
|
|
|
} |
|
277
|
|
|
|
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.