|
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\AwardCat; |
|
12
|
|
|
use App\Models\AwardSubcat; |
|
13
|
|
|
use Illuminate\Http\Request; |
|
14
|
|
|
|
|
15
|
|
|
class AwardController extends Controller |
|
16
|
|
|
{ |
|
17
|
|
|
public function index() |
|
18
|
|
|
{ |
|
19
|
|
|
$awards = AwardCat::orderBy('year', 'desc') |
|
20
|
|
|
->orderBy('month', 'desc') |
|
21
|
|
|
->get(); |
|
22
|
|
|
|
|
23
|
|
|
return view('awards.index', [ |
|
24
|
|
|
'awards' => $awards, |
|
25
|
|
|
]); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function show($awardid) |
|
29
|
|
|
{ |
|
30
|
|
|
$award = AwardCat::whereId($awardid)->first(); |
|
31
|
|
|
|
|
32
|
|
|
return view('awards.show', [ |
|
33
|
|
|
'award' => $award, |
|
34
|
|
|
]); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function create() |
|
38
|
|
|
{ |
|
39
|
|
|
$pages = \DB::table('award_pages') |
|
40
|
|
|
->orderBy('title') |
|
41
|
|
|
->get(); |
|
42
|
|
|
|
|
43
|
|
|
$awards = \DB::table('award_cats') |
|
44
|
|
|
->leftJoin('award_pages', 'award_pages.id', '=', 'award_cats.award_page_id') |
|
45
|
|
|
->select([ |
|
46
|
|
|
'award_cats.id as catid', |
|
47
|
|
|
'award_pages.id as pageid', |
|
48
|
|
|
'award_pages.title as pagetitle', |
|
49
|
|
|
'award_cats.title as cattitle', |
|
50
|
|
|
'award_cats.year as year', |
|
51
|
|
|
'award_cats.month as month', |
|
52
|
|
|
]) |
|
53
|
|
|
->orderBy('award_cats.year') |
|
54
|
|
|
->orderBy('award_cats.month') |
|
55
|
|
|
->orderBy('award_cats.title') |
|
56
|
|
|
->get(); |
|
57
|
|
|
|
|
58
|
|
|
return view('awards.create', [ |
|
59
|
|
|
'pages' => $pages, |
|
60
|
|
|
'awards' => $awards, |
|
61
|
|
|
]); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function gameadd($subcatid) |
|
65
|
|
|
{ |
|
66
|
|
|
$subcat = AwardSubcat::whereId($subcatid)->first(); |
|
67
|
|
|
// Get award model from catid. |
|
68
|
|
|
$award = AwardCat::whereId($subcat->cat_id)->first(); |
|
69
|
|
|
|
|
70
|
|
|
return view('awards.gameadd', [ |
|
71
|
|
|
'subcatid' => $subcatid, |
|
72
|
|
|
'award' => $award, |
|
73
|
|
|
]); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
public function gameadd_store(Request $request) |
|
77
|
|
|
{ |
|
78
|
|
|
$this->validate($request, [ |
|
79
|
|
|
'game' => 'required|numeric', |
|
80
|
|
|
'place' => 'required|numeric', |
|
81
|
|
|
'subcatid' => 'required|numeric', |
|
82
|
|
|
]); |
|
83
|
|
|
|
|
84
|
|
|
$subcat = \DB::table('award_subcats') |
|
85
|
|
|
->where('id', '=', $request->get('subcatid')) |
|
86
|
|
|
->first(); |
|
87
|
|
|
|
|
88
|
|
|
$check = \DB::table('games_awards') |
|
89
|
|
|
->where('award_subcat_id', '=', $request->get('subcatid')) |
|
90
|
|
|
->where('game_id', '=', $request->get('game')) |
|
91
|
|
|
->get(); |
|
92
|
|
|
|
|
93
|
|
|
//dd($check); |
|
94
|
|
|
|
|
95
|
|
|
if ($check->count() == 0) { |
|
96
|
|
|
\DB::table('games_awards')->insert([ |
|
97
|
|
|
'game_id' => $request->get('game'), |
|
98
|
|
|
'developer_id' => 0, |
|
99
|
|
|
'award_cat_id' => $subcat->cat_id, |
|
100
|
|
|
'award_page_id' => $subcat->page_id, |
|
101
|
|
|
'user_id' => \Auth::id(), |
|
102
|
|
|
'created_at' => Carbon::now(), |
|
103
|
|
|
'place' => $request->get('place'), |
|
104
|
|
|
'description' => $request->get('desc'), |
|
105
|
|
|
'award_subcat_id' => $request->get('subcatid'), |
|
106
|
|
|
]); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
return redirect()->action('AwardController@show', $subcat->cat_id); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
public function store_page(Request $request) |
|
113
|
|
|
{ |
|
114
|
|
|
$this->validate($request, [ |
|
115
|
|
|
'awardpage' => 'required', |
|
116
|
|
|
]); |
|
117
|
|
|
|
|
118
|
|
|
$check = \DB::table('award_pages') |
|
119
|
|
|
->where('title', '=', $request->get('awardpage')) |
|
120
|
|
|
->get(); |
|
121
|
|
|
|
|
122
|
|
|
if ($check->count() == 0) { |
|
123
|
|
|
\DB::table('award_pages')->insert([ |
|
124
|
|
|
'title' => $request->get('awardpage'), |
|
125
|
|
|
'website_url' => $request->get('awardpageurl'), |
|
126
|
|
|
'user_id' => \Auth::id(), |
|
127
|
|
|
'created_at' => Carbon::now(), |
|
128
|
|
|
]); |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
return redirect()->action('AwardController@create'); |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
public function store_cat(Request $request) |
|
135
|
|
|
{ |
|
136
|
|
|
$this->validate($request, [ |
|
137
|
|
|
'awardpage' => 'required|not_in:0', |
|
138
|
|
|
'awardname' => 'required', |
|
139
|
|
|
'awarddate_year' => 'required|not_in:0', |
|
140
|
|
|
]); |
|
141
|
|
|
|
|
142
|
|
|
$check = \DB::table('award_cats') |
|
143
|
|
|
->where('title', '=', $request->get('awardname')) |
|
144
|
|
|
->where('year', '=', $request->get('awarddate_year')) |
|
145
|
|
|
->where('month', '=', $request->get('awarddate_month')) |
|
146
|
|
|
->where('award_page_id', '=', $request->get('awardpage')) |
|
147
|
|
|
->get(); |
|
148
|
|
|
|
|
149
|
|
|
if ($check->count() == 0) { |
|
150
|
|
|
\DB::table('award_cats')->insert([ |
|
151
|
|
|
'title' => $request->get('awardname'), |
|
152
|
|
|
'award_page_id' => $request->get('awardpage'), |
|
153
|
|
|
'year' => $request->get('awarddate_year'), |
|
154
|
|
|
'month' => $request->get('awarddate_month'), |
|
155
|
|
|
'user_id' => \Auth::id(), |
|
156
|
|
|
'created_at' => Carbon::now(), |
|
157
|
|
|
]); |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
return redirect()->action('AwardController@create'); |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
public function store_subcat(Request $request) |
|
164
|
|
|
{ |
|
165
|
|
|
$this->validate($request, [ |
|
166
|
|
|
'award' => 'required|not_in:0', |
|
167
|
|
|
'awardsubcat' => 'required', |
|
168
|
|
|
]); |
|
169
|
|
|
|
|
170
|
|
|
$aw = explode('-', $request->get('award')); |
|
171
|
|
|
|
|
172
|
|
|
$check = \DB::table('award_subcats') |
|
173
|
|
|
->where('cat_id', '=', $aw[1]) |
|
174
|
|
|
->where('page_id', '=', $aw[0]) |
|
175
|
|
|
->where('title', '=', $request->get('awardsubcat')) |
|
176
|
|
|
->get(); |
|
177
|
|
|
|
|
178
|
|
|
if ($check->count() == 0) { |
|
179
|
|
|
\DB::table('award_subcats')->insert([ |
|
180
|
|
|
'title' => $request->get('awardsubcat'), |
|
181
|
|
|
'created_at' => Carbon::now(), |
|
182
|
|
|
|
|
183
|
|
|
'cat_id' => $aw[1], |
|
184
|
|
|
'page_id' => $aw[0], |
|
185
|
|
|
]); |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
return redirect()->action('AwardController@create'); |
|
189
|
|
|
} |
|
190
|
|
|
} |
|
191
|
|
|
|