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