1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Http\Controllers; |
4
|
|
|
|
5
|
|
|
use App\Models\ProblemModel; |
6
|
|
|
use App\Models\Submission\SubmissionModel; |
7
|
|
|
use App\Models\CompilerModel; |
8
|
|
|
use App\Models\AccountModel; |
9
|
|
|
use App\Http\Controllers\Controller; |
10
|
|
|
use Illuminate\Http\Request; |
11
|
|
|
use App\Models\Eloquent\Tool\MonacoTheme; |
12
|
|
|
use JavaScript; |
13
|
|
|
use Auth; |
14
|
|
|
|
15
|
|
|
class ProblemController extends Controller |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* Show the Problem Index Page. |
19
|
|
|
* |
20
|
|
|
* @return Response |
|
|
|
|
21
|
|
|
*/ |
22
|
|
|
public function index(Request $request) |
23
|
|
|
{ |
24
|
|
|
$all_data=$request->all(); |
25
|
|
|
$problem=new ProblemModel(); |
26
|
|
|
$filter["oj"]=isset($all_data["oj"]) ? $all_data["oj"] : null; |
|
|
|
|
27
|
|
|
$filter["tag"]=isset($all_data["tag"]) ? $all_data["tag"] : null; |
28
|
|
|
$list_return=$problem->list($filter, Auth::check() ?Auth::user()->id : null); |
|
|
|
|
29
|
|
|
$tags=$problem->tags(); |
30
|
|
|
$ojs=$problem->ojs(); |
31
|
|
|
if (is_null($list_return)) { |
32
|
|
|
if (isset($all_data["page"]) && $all_data["page"]>1) { |
33
|
|
|
return redirect("/problem"); |
|
|
|
|
34
|
|
|
} else { |
35
|
|
|
return view('problem.index', [ |
|
|
|
|
36
|
|
|
'page_title' => "Problem", |
37
|
|
|
'site_title' => config("app.name"), |
38
|
|
|
'navigation' => "Problem", |
39
|
|
|
'prob_list' => null, |
40
|
|
|
'prob_paginate' => null, |
41
|
|
|
'tags' => $tags, |
42
|
|
|
'ojs' => $ojs, |
43
|
|
|
'filter' => $filter |
44
|
|
|
]); |
45
|
|
|
} |
46
|
|
|
} else { |
47
|
|
|
return view('problem.index', [ |
|
|
|
|
48
|
|
|
'page_title' => "Problem", |
49
|
|
|
'site_title' => config("app.name"), |
50
|
|
|
'navigation' => "Problem", |
51
|
|
|
'prob_list' => $list_return['problems'], |
52
|
|
|
'paginator' => $list_return['paginator'], |
53
|
|
|
'tags' => $tags, |
54
|
|
|
'ojs' => $ojs, |
55
|
|
|
'filter' => $filter |
56
|
|
|
]); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
/** |
60
|
|
|
* Show the Problem Detail Page. |
61
|
|
|
* |
62
|
|
|
* @return Response |
63
|
|
|
*/ |
64
|
|
|
public function detail($pcode) |
65
|
|
|
{ |
66
|
|
|
$problem=new ProblemModel(); |
67
|
|
|
$prob_detail=$problem->detail($pcode); |
68
|
|
|
if(blank($prob_detail) || $problem->isHidden($prob_detail["pid"])) { |
69
|
|
|
return redirect("/problem"); |
|
|
|
|
70
|
|
|
} |
71
|
|
|
if ($problem->isBlocked($prob_detail["pid"])) { |
72
|
|
|
return abort('403'); |
73
|
|
|
} |
74
|
|
|
return view('problem.detail', [ |
|
|
|
|
75
|
|
|
'page_title'=>$prob_detail["title"], |
76
|
|
|
'site_title'=>config("app.name"), |
77
|
|
|
'navigation' => "Problem", |
78
|
|
|
'detail' => $prob_detail |
79
|
|
|
]); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Show the Problem Solution Page. |
84
|
|
|
* |
85
|
|
|
* @return Response |
86
|
|
|
*/ |
87
|
|
|
public function solution($pcode) |
88
|
|
|
{ |
89
|
|
|
$problem=new ProblemModel(); |
90
|
|
|
$prob_detail=$problem->detail($pcode); |
91
|
|
|
if ($problem->isBlocked($prob_detail["pid"]) || $problem->isHidden($prob_detail["pid"])) { |
92
|
|
|
return abort('403'); |
93
|
|
|
} |
94
|
|
|
$solution=$problem->solutionList($prob_detail["pid"], Auth::check() ?Auth::user()->id : null); |
|
|
|
|
95
|
|
|
$submitted=Auth::check() ? $problem->solution($prob_detail["pid"], Auth::user()->id) : []; |
96
|
|
|
return is_null($prob_detail) ? redirect("/problem") : view('problem.solution', [ |
|
|
|
|
97
|
|
|
'page_title'=> "Solution", |
98
|
|
|
'site_title'=>config("app.name"), |
99
|
|
|
'navigation' => $prob_detail["title"], |
100
|
|
|
'detail' => $prob_detail, |
101
|
|
|
'solution'=>$solution, |
102
|
|
|
'submitted'=>$submitted |
103
|
|
|
]); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Show the Problem Editor Page. |
108
|
|
|
* |
109
|
|
|
* @return Response |
110
|
|
|
*/ |
111
|
|
|
public function editor($pcode) |
112
|
|
|
{ |
113
|
|
|
$problem=new ProblemModel(); |
114
|
|
|
$compiler=new CompilerModel(); |
115
|
|
|
$submission=new SubmissionModel(); |
116
|
|
|
$account=new AccountModel(); |
|
|
|
|
117
|
|
|
|
118
|
|
|
$prob_detail=$problem->detail($pcode); |
119
|
|
|
if ($problem->isBlocked($prob_detail["pid"]) || $problem->isHidden($prob_detail["pid"])) { |
120
|
|
|
return abort('403'); |
121
|
|
|
} |
122
|
|
|
$compiler_list=$compiler->list($prob_detail["OJ"], $prob_detail["pid"]); |
123
|
|
|
$prob_status=$submission->getProblemStatus($prob_detail["pid"], Auth::user()->id); |
|
|
|
|
124
|
|
|
|
125
|
|
|
$compiler_pref=$compiler->pref($compiler_list, $prob_detail["pid"], Auth::user()->id); |
126
|
|
|
$pref=$compiler_pref["pref"]; |
127
|
|
|
$submit_code=$compiler_pref["code"]; |
128
|
|
|
|
129
|
|
|
$oj_detail=$problem->ojdetail($prob_detail["OJ"]); |
130
|
|
|
|
131
|
|
|
if (empty($prob_status)) { |
132
|
|
|
$prob_status=[ |
133
|
|
|
"verdict"=>"NOT SUBMIT", |
134
|
|
|
"color"=>"" |
135
|
|
|
]; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
$accountExt=Auth::user()->getExtra(['editor_left_width', 'editor_theme']); |
|
|
|
|
139
|
|
|
$editor_left_width=isset($accountExt['editor_left_width']) ? $accountExt['editor_left_width'] : '40'; |
140
|
|
|
$editor_theme=isset($accountExt['editor_theme']) ? $accountExt['editor_theme'] : config('app.editor_theme'); |
141
|
|
|
$themeConfig=MonacoTheme::getTheme($editor_theme); |
142
|
|
|
|
143
|
|
|
return is_null($prob_detail) ? redirect("/problem") : view('problem.editor', [ |
|
|
|
|
144
|
|
|
'page_title'=>$prob_detail["title"], |
145
|
|
|
'site_title'=>config("app.name"), |
146
|
|
|
'navigation' => "Problem", |
147
|
|
|
'detail' => $prob_detail, |
148
|
|
|
'compiler_list' => $compiler_list, |
149
|
|
|
'status' => $prob_status, |
150
|
|
|
'pref'=>$pref<0 ? 0 : $pref, |
151
|
|
|
'submit_code'=>$submit_code, |
152
|
|
|
'contest_mode'=> false, |
153
|
|
|
'oj_detail'=>$oj_detail, |
154
|
|
|
'editor_left_width'=>$editor_left_width, |
155
|
|
|
'theme_config'=>$themeConfig, |
156
|
|
|
'editor_themes'=>MonacoTheme::getAll(), |
157
|
|
|
]); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* Show the Problem Discussion Page. |
162
|
|
|
* |
163
|
|
|
* @return Response |
164
|
|
|
*/ |
165
|
|
|
public function discussion($pcode) |
166
|
|
|
{ |
167
|
|
|
//TODO |
168
|
|
|
$problem=new ProblemModel(); |
169
|
|
|
$prob_detail=$problem->detail($pcode); |
170
|
|
|
if ($problem->isBlocked($prob_detail["pid"])) { |
171
|
|
|
return abort('403'); |
172
|
|
|
} |
173
|
|
|
$list=$problem->discussionList($prob_detail["pid"]); |
174
|
|
|
$discussion=$list['list']; |
175
|
|
|
$paginator=$list['paginator']; |
176
|
|
|
return is_null($prob_detail) ? redirect("/problem") : view('problem.discussion', [ |
|
|
|
|
177
|
|
|
'page_title'=> "Discussion", |
178
|
|
|
'site_title'=>config("app.name"), |
179
|
|
|
'navigation' => $prob_detail["title"], |
180
|
|
|
'detail' => $prob_detail, |
181
|
|
|
'discussion'=>$discussion, |
182
|
|
|
'paginator'=>$paginator |
183
|
|
|
]); |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* Show the Problem Discussion Post Page. |
188
|
|
|
* |
189
|
|
|
* @return Response |
190
|
|
|
*/ |
191
|
|
|
public function discussionPost($dcode) |
192
|
|
|
{ |
193
|
|
|
//TODO |
194
|
|
|
$problem=new ProblemModel(); |
195
|
|
|
$pcode=$problem->pcodeByPdid($dcode); |
196
|
|
|
$prob_detail=$problem->detail($pcode); |
197
|
|
|
if ($problem->isBlocked($prob_detail["pid"])) { |
198
|
|
|
return abort('403'); |
199
|
|
|
} |
200
|
|
|
$detail=$problem->discussionDetail($dcode); |
201
|
|
|
$main=$detail['main']; |
202
|
|
|
$paginator=$detail['paginator']; |
203
|
|
|
$comment=$detail['comment']; |
204
|
|
|
$comment_count=$detail['comment_count']; |
205
|
|
|
return is_null($prob_detail) ? redirect("/problem") : view('problem.discussion_post', [ |
|
|
|
|
206
|
|
|
'page_title'=> "Discussion", |
207
|
|
|
'site_title'=>config("app.name"), |
208
|
|
|
'navigation' => $prob_detail["title"], |
209
|
|
|
'detail' => $prob_detail, |
210
|
|
|
'main'=>$main, |
211
|
|
|
'paginator'=>$paginator, |
212
|
|
|
'comment'=>$comment, |
213
|
|
|
'comment_count'=>$comment_count |
214
|
|
|
]); |
215
|
|
|
} |
216
|
|
|
} |
217
|
|
|
|