BoardController::challenge()   B
last analyzed

Complexity

Conditions 7
Paths 6

Size

Total Lines 37
Code Lines 31

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 31
nc 6
nop 1
dl 0
loc 37
rs 8.4906
c 0
b 0
f 0
1
<?php
2
3
namespace App\Http\Controllers\Contest;
4
5
use App\Models\ContestModel;
6
use App\Models\ProblemModel;
7
use App\Models\CompilerModel;
8
use App\Models\Submission\SubmissionModel;
9
use App\Http\Controllers\Controller;
10
use App\Models\Eloquent\Tool\MonacoTheme;
11
use Illuminate\Http\Request;
12
use Auth;
13
use Redirect;
14
15
class BoardController extends Controller
16
{
17
    /**
18
     * Redirect the Contest Board Page.
19
     *
20
     * @return Response
0 ignored issues
show
Bug introduced by
The type App\Http\Controllers\Contest\Response was not found. Did you mean Response? If so, make sure to prefix the type with \.
Loading history...
21
     */
22
    public function board($cid)
23
    {
24
        return Redirect::route('contest.board.challenge', ['cid' => $cid]);
0 ignored issues
show
Bug Best Practice introduced by
The expression return Redirect::route('..., array('cid' => $cid)) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type App\Http\Controllers\Contest\Response.
Loading history...
25
    }
26
27
    /**
28
     * Show the Contest Challenge Page.
29
     *
30
     * @return Response
31
     */
32
    public function challenge($cid)
33
    {
34
        $contestModel=new ContestModel();
35
        $clearance=$contestModel->judgeClearance($cid, Auth::user()->id);
0 ignored issues
show
Bug introduced by
Accessing id on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
36
        $basicInfo=$contestModel->basic($cid);
37
        if (!$clearance || time()<strtotime($basicInfo['begin_time'])) {
38
            if ($clearance==3) {
39
                return Redirect::route('contest.board.admin', ['cid' => $cid]);
0 ignored issues
show
Bug Best Practice introduced by
The expression return Redirect::route('..., array('cid' => $cid)) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type App\Http\Controllers\Contest\Response.
Loading history...
40
            } else {
41
                return Redirect::route('contest.detail', ['cid' => $cid]);
0 ignored issues
show
Bug Best Practice introduced by
The expression return Redirect::route('..., array('cid' => $cid)) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type App\Http\Controllers\Contest\Response.
Loading history...
42
            }
43
        }
44
        $contest_name=$contestModel->contestName($cid);
45
        $contest_rule=$contestModel->contestRule($cid);
46
        $problemSet=$contestModel->contestProblems($cid, Auth::user()->id);
47
        $remainingTime=$contestModel->remainingTime($cid);
48
        $customInfo=$contestModel->getCustomInfo($cid);
49
        $clarificationList=$contestModel->getLatestClarification($cid);
50
        if ($remainingTime<=0) {
51
            $remainingTime=0;
52
        }
53
        if ($basicInfo['public'] && !$basicInfo['audit_status']) {
54
            return Redirect::route('contest.detail', ['cid' => $cid]);
0 ignored issues
show
Bug Best Practice introduced by
The expression return Redirect::route('..., array('cid' => $cid)) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type App\Http\Controllers\Contest\Response.
Loading history...
55
        }
56
        return view('contest.board.challenge', [
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('contest.boa...'basic' => $basicInfo)) returns the type Illuminate\View\View which is incompatible with the documented return type App\Http\Controllers\Contest\Response.
Loading history...
57
            'page_title'=>"Challenge",
58
            'navigation' => "Contest",
59
            'site_title'=>$contest_name,
60
            'cid'=>$cid,
61
            'contest_name'=>$contest_name,
62
            'contest_rule'=>$contest_rule,
63
            'problem_set'=> $problemSet,
64
            'remaining_time'=>$remainingTime,
65
            'custom_info' => $customInfo,
66
            'clarification_list' => $clarificationList,
67
            'clearance'=> $clearance,
68
            'basic'=>$basicInfo,
69
        ]);
70
    }
71
72
    /**
73
     * Show the Contest Editor Page.
74
     *
75
     * @return Response
76
     */
77
    public function editor($cid, $ncode)
78
    {
79
        $contestModel=new ContestModel();
80
        $problemModel=new ProblemModel();
81
        $compilerModel=new CompilerModel();
82
        $submissionModel=new SubmissionModel();
83
        $clearance=$contestModel->judgeClearance($cid, Auth::user()->id);
0 ignored issues
show
Bug introduced by
Accessing id on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
84
        $basicInfo=$contestModel->basic($cid);
85
        if (!$clearance || time()<strtotime($basicInfo['begin_time'])) {
86
            if ($clearance==3) {
87
                return Redirect::route('contest.board.admin', ['cid' => $cid]);
0 ignored issues
show
Bug Best Practice introduced by
The expression return Redirect::route('..., array('cid' => $cid)) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type App\Http\Controllers\Contest\Response.
Loading history...
88
            } else {
89
                return Redirect::route('contest.detail', ['cid' => $cid]);
0 ignored issues
show
Bug Best Practice introduced by
The expression return Redirect::route('..., array('cid' => $cid)) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type App\Http\Controllers\Contest\Response.
Loading history...
90
            }
91
        }
92
        $basicInfo=$contestModel->basic($cid);
93
        if ($basicInfo['public'] && !$basicInfo['audit_status']) {
94
            return Redirect::route('contest.detail', ['cid' => $cid]);
0 ignored issues
show
Bug Best Practice introduced by
The expression return Redirect::route('..., array('cid' => $cid)) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type App\Http\Controllers\Contest\Response.
Loading history...
95
        }
96
        $contest_name=$contestModel->contestName($cid);
97
        $contest_rule=$contestModel->rule($cid);
98
        $contest_ended=$contestModel->isContestEnded($cid);
99
        $pid=$contestModel->getPid($cid, $ncode);
100
        if (empty($pid)) {
101
            return Redirect::route('contest.board.index', ['cid' => $cid]);
0 ignored issues
show
Bug Best Practice introduced by
The expression return Redirect::route('..., array('cid' => $cid)) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type App\Http\Controllers\Contest\Response.
Loading history...
102
        }
103
        $pcode=$problemModel->pcode($pid);
104
105
        $prob_detail=$problemModel->detail($pcode, $cid);
106
        if ($problemModel->isBlocked($prob_detail["pid"], $cid)) {
107
            return abort('403');
108
        }
109
        $compiler_list=$compilerModel->list($prob_detail["OJ"], $prob_detail["pid"]);
110
        $prob_status=$submissionModel->getProblemStatus($prob_detail["pid"], Auth::user()->id, $cid);
111
        $problemSet=$contestModel->contestProblems($cid, Auth::user()->id);
112
        $compiler_pref=$compilerModel->pref($compiler_list, $prob_detail["pid"], Auth::user()->id, $cid);
113
        $pref=$compiler_pref["pref"];
114
        $submit_code=$compiler_pref["code"];
115
        $oj_detail=$problemModel->ojdetail($prob_detail["OJ"]);
116
117
        if (empty($prob_status)) {
118
            $prob_status=[
119
                "verdict"=>"NOT SUBMIT",
120
                "color"=>""
121
            ];
122
        }
123
124
        $accountExt=Auth::user()->getExtra(['editor_left_width', 'editor_theme']);
0 ignored issues
show
Bug introduced by
The method getExtra() does not exist on Illuminate\Contracts\Auth\Authenticatable. It seems like you code against a sub-type of said class. However, the method does not exist in Illuminate\Auth\GenericUser. Are you sure you never get one of those? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

124
        $accountExt=Auth::user()->/** @scrutinizer ignore-call */ getExtra(['editor_left_width', 'editor_theme']);
Loading history...
125
        $editor_left_width=isset($accountExt['editor_left_width']) ? $accountExt['editor_left_width'] : '40';
126
        $editor_theme=isset($accountExt['editor_theme']) ? $accountExt['editor_theme'] : config('app.editor_theme');
127
        $themeConfig=MonacoTheme::getTheme($editor_theme);
128
129
        return view('contest.board.editor', [
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('contest.boa...MonacoTheme::getAll())) returns the type Illuminate\View\View which is incompatible with the documented return type App\Http\Controllers\Contest\Response.
Loading history...
130
            'page_title'=>"Problem Detail",
131
            'navigation' => "Contest",
132
            'site_title'=>$contest_name,
133
            'contest_name'=>$contest_name,
134
            'cid'=> $cid,
135
            'detail' => $prob_detail,
136
            'compiler_list' => $compiler_list,
137
            'status' => $prob_status,
138
            'pref' => $pref<0 ? 0 : $pref,
139
            'submit_code' => $submit_code,
140
            'contest_mode' => true,
141
            'contest_ended' => $contest_ended,
142
            'ncode' => $ncode,
143
            'contest_rule' => $contest_rule,
144
            'problem_set' => $problemSet,
145
            'clearance' => $clearance,
146
            'oj_detail' => $oj_detail,
147
            'editor_left_width'=>$editor_left_width,
148
            'theme_config'=>$themeConfig,
149
            'editor_themes'=>MonacoTheme::getAll(),
150
        ]);
151
    }
152
153
    /**
154
     * Show the Contest Rank Page.
155
     *
156
     * @return Response
157
     */
158
    public function rank($cid)
159
    {
160
        $contestModel=new ContestModel();
161
        $clearance=$contestModel->judgeClearance($cid, Auth::user()->id);
0 ignored issues
show
Bug introduced by
Accessing id on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
162
        $basicInfo=$contestModel->basic($cid);
163
        if (!$clearance || time()<strtotime($basicInfo['begin_time'])) {
164
            if ($clearance==3) {
165
                return Redirect::route('contest.board.admin', ['cid' => $cid]);
0 ignored issues
show
Bug Best Practice introduced by
The expression return Redirect::route('..., array('cid' => $cid)) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type App\Http\Controllers\Contest\Response.
Loading history...
166
            } else {
167
                return Redirect::route('contest.detail', ['cid' => $cid]);
0 ignored issues
show
Bug Best Practice introduced by
The expression return Redirect::route('..., array('cid' => $cid)) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type App\Http\Controllers\Contest\Response.
Loading history...
168
            }
169
        }
170
        $basicInfo=$contestModel->basic($cid);
171
        if ($basicInfo['public'] && !$basicInfo['audit_status']) {
172
            return Redirect::route('contest.detail', ['cid' => $cid]);
0 ignored issues
show
Bug Best Practice introduced by
The expression return Redirect::route('..., array('cid' => $cid)) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type App\Http\Controllers\Contest\Response.
Loading history...
173
        }
174
        $contest_name=$contestModel->contestName($cid);
175
        $contest_rule=$contestModel->contestRule($cid);
176
        $problemSet=$contestModel->contestProblems($cid, Auth::user()->id);
177
        $customInfo=$contestModel->getCustomInfo($cid);
178
        $contestRank=$contestModel->contestRank($cid, Auth::user()->id);
179
180
        // To determine the ranking
181
        foreach ($contestRank as $i => &$r) {
182
            if ($i!=0) {
183
                if ($r['score']==$contestRank[$i-1]['score'] && ($contest_rule==1 ? ($r['penalty']==$contestRank[$i-1]['penalty']) : 1)) {
184
                    $r['rank']=$contestRank[$i-1]['rank'];
185
                } else {
186
                    $r['rank']=$i+1;
187
                }
188
            } else {
189
                $r['rank']=1;
190
            }
191
        }
192
        $rankFrozen=$contestModel->isFrozen($cid);
193
        $frozenTime=$contestModel->frozenTime($cid);
194
        return view('contest.board.rank', [
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('contest.boa...'basic' => $basicInfo)) returns the type Illuminate\View\View which is incompatible with the documented return type App\Http\Controllers\Contest\Response.
Loading history...
195
            'page_title'=>"Rank",
196
            'navigation' => "Contest",
197
            'site_title'=>$contest_name,
198
            'contest_name'=>$contest_name,
199
            'contest_rule'=>$contest_rule,
200
            'cid'=>$cid,
201
            'problem_set'=>$problemSet,
202
            'custom_info' => $customInfo,
203
            'contest_rank' => $contestRank,
204
            'rank_frozen' => $rankFrozen,
205
            'frozen_time' => $frozenTime,
206
            'clearance'=> $clearance,
207
            'basic'=>$basicInfo,
208
        ]);
209
    }
210
211
    /**
212
     * Show the Contest Status Page.
213
     *
214
     * @return Response
215
     */
216
    public function status(Request $request)
217
    {
218
        $all_data=$request->all();
219
        $filter["ncode"]=isset($all_data["ncode"]) ? $all_data["ncode"] : null;
0 ignored issues
show
Comprehensibility Best Practice introduced by
$filter was never initialized. Although not strictly required by PHP, it is generally a good practice to add $filter = array(); before regardless.
Loading history...
220
        $filter["result"]=isset($all_data["result"]) ? $all_data["result"] : null;
221
        $filter["account"]=isset($all_data["account"]) ? $all_data["account"] : null;
222
        $cid=$request->cid;
223
        $contestModel=new ContestModel();
224
        $clearance=$contestModel->judgeClearance($cid, Auth::user()->id);
0 ignored issues
show
Bug introduced by
Accessing id on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
225
        $basicInfo=$contestModel->basic($cid);
226
        if (!$clearance || time()<strtotime($basicInfo['begin_time'])) {
227
            if ($clearance==3) {
228
                return Redirect::route('contest.board.admin', ['cid' => $cid]);
0 ignored issues
show
Bug Best Practice introduced by
The expression return Redirect::route('..., array('cid' => $cid)) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type App\Http\Controllers\Contest\Response.
Loading history...
229
            } else {
230
                return Redirect::route('contest.detail', ['cid' => $cid]);
0 ignored issues
show
Bug Best Practice introduced by
The expression return Redirect::route('..., array('cid' => $cid)) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type App\Http\Controllers\Contest\Response.
Loading history...
231
            }
232
        }
233
        $basicInfo=$contestModel->basic($cid);
234
        if ($basicInfo['public'] && !$basicInfo['audit_status']) {
235
            return Redirect::route('contest.detail', ['cid' => $cid]);
0 ignored issues
show
Bug Best Practice introduced by
The expression return Redirect::route('..., array('cid' => $cid)) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type App\Http\Controllers\Contest\Response.
Loading history...
236
        }
237
        $contest_name=$contestModel->contestName($cid);
238
        $customInfo=$contestModel->getCustomInfo($cid);
239
        $submissionRecordSet=$contestModel->getContestRecord($filter, $cid);
240
        $rankFrozen=$contestModel->isFrozen($cid);
241
        $frozenTime=$contestModel->frozenTime($cid);
242
        return view('contest.board.status', [
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('contest.boa..., 'filter' => $filter)) returns the type Illuminate\View\View which is incompatible with the documented return type App\Http\Controllers\Contest\Response.
Loading history...
243
            'page_title'=>"Status",
244
            'navigation' => "Contest",
245
            'site_title'=>$contest_name,
246
            'contest_name'=>$contest_name,
247
            'basic_info'=>$basicInfo,
248
            'cid'=>$cid,
249
            'custom_info' => $customInfo,
250
            'submission_record' => $submissionRecordSet,
251
            'rank_frozen' => $rankFrozen,
252
            'frozen_time' => $frozenTime,
253
            'clearance'=> $clearance,
254
            'filter' => $filter,
255
        ]);
256
    }
257
258
    /**
259
     * Show the Contest Clarification Page.
260
     *
261
     * @return Response
262
     */
263
    public function clarification($cid)
264
    {
265
        $contestModel=new ContestModel();
266
        $clearance=$contestModel->judgeClearance($cid, Auth::user()->id);
0 ignored issues
show
Bug introduced by
Accessing id on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
267
        $basicInfo=$contestModel->basic($cid);
268
        if (!$clearance || time()<strtotime($basicInfo['begin_time'])) {
269
            if ($clearance==3) {
270
                return Redirect::route('contest.board.admin', ['cid' => $cid]);
0 ignored issues
show
Bug Best Practice introduced by
The expression return Redirect::route('..., array('cid' => $cid)) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type App\Http\Controllers\Contest\Response.
Loading history...
271
            } else {
272
                return Redirect::route('contest.detail', ['cid' => $cid]);
0 ignored issues
show
Bug Best Practice introduced by
The expression return Redirect::route('..., array('cid' => $cid)) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type App\Http\Controllers\Contest\Response.
Loading history...
273
            }
274
        }
275
        if ($basicInfo['public'] && !$basicInfo['audit_status']) {
276
            return Redirect::route('contest.detail', ['cid' => $cid]);
0 ignored issues
show
Bug Best Practice introduced by
The expression return Redirect::route('..., array('cid' => $cid)) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type App\Http\Controllers\Contest\Response.
Loading history...
277
        }
278
        $contest_name=$contestModel->contestName($cid);
279
        $customInfo=$contestModel->getCustomInfo($cid);
280
        $clarificationList=$contestModel->getClarificationList($cid);
281
        $contest_ended=$contestModel->isContestEnded($cid);
282
        return view('contest.board.clarification', [
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('contest.boa...'basic' => $basicInfo)) returns the type Illuminate\View\View which is incompatible with the documented return type App\Http\Controllers\Contest\Response.
Loading history...
283
            'page_title'=>"Clarification",
284
            'navigation' => "Contest",
285
            'site_title'=>$contest_name,
286
            'contest_name'=>$contest_name,
287
            'cid'=>$cid,
288
            'custom_info' => $customInfo,
289
            'clarification_list' => $clarificationList,
290
            'contest_ended' => $contest_ended,
291
            'clearance'=> $clearance,
292
            'basic'=>$basicInfo,
293
        ]);
294
    }
295
296
    /**
297
     * Show the Contest Print Page.
298
     *
299
     * @return Response
300
     */
301
    public function print($cid)
302
    {
303
        $contestModel=new ContestModel();
304
        $clearance=$contestModel->judgeClearance($cid, Auth::user()->id);
0 ignored issues
show
Bug introduced by
Accessing id on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
305
        $basicInfo=$contestModel->basic($cid);
306
        if (!$clearance || time()<strtotime($basicInfo['begin_time'])) {
307
            if ($clearance==3) {
308
                return Redirect::route('contest.board.admin', ['cid' => $cid]);
0 ignored issues
show
Bug Best Practice introduced by
The expression return Redirect::route('..., array('cid' => $cid)) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type App\Http\Controllers\Contest\Response.
Loading history...
309
            } else {
310
                return Redirect::route('contest.detail', ['cid' => $cid]);
0 ignored issues
show
Bug Best Practice introduced by
The expression return Redirect::route('..., array('cid' => $cid)) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type App\Http\Controllers\Contest\Response.
Loading history...
311
            }
312
        }
313
        if ($basicInfo['public'] && !$basicInfo['audit_status']) {
314
            return Redirect::route('contest.detail', ['cid' => $cid]);
0 ignored issues
show
Bug Best Practice introduced by
The expression return Redirect::route('..., array('cid' => $cid)) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type App\Http\Controllers\Contest\Response.
Loading history...
315
        }
316
        $contest_name=$contestModel->contestName($cid);
317
        $customInfo=$contestModel->getCustomInfo($cid);
318
        return view('contest.board.print', [
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('contest.boa...'basic' => $basicInfo)) returns the type Illuminate\View\View which is incompatible with the documented return type App\Http\Controllers\Contest\Response.
Loading history...
319
            'page_title'=>"Print",
320
            'navigation' => "Contest",
321
            'site_title'=>$contest_name,
322
            'contest_name'=>$contest_name,
323
            'cid'=>$cid,
324
            'custom_info' => $customInfo,
325
            'clearance'=> $clearance,
326
            'basic'=>$basicInfo,
327
        ]);
328
    }
329
330
    public function analysis($cid) {
331
        $contestModel=new ContestModel();
332
        $clearance=$contestModel->judgeClearance($cid, Auth::user()->id);
0 ignored issues
show
Bug introduced by
Accessing id on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
333
        $basicInfo=$contestModel->basic($cid);
334
        if (!$clearance || time()<strtotime($basicInfo['begin_time'])) {
335
            if ($clearance==3) {
336
                return Redirect::route('contest.board.admin', ['cid' => $cid]);
337
            } else {
338
                return Redirect::route('contest.detail', ['cid' => $cid]);
339
            }
340
        }
341
        $basicInfo=$contestModel->basic($cid);
342
        if ($basicInfo['public'] && !$basicInfo['audit_status']) {
343
            return Redirect::route('contest.detail', ['cid' => $cid]);
344
        }
345
        $contest_name=$contestModel->contestName($cid);
346
        $customInfo=$contestModel->getCustomInfo($cid);
347
        return view('contest.board.analysis', [
348
            'page_title'=>"Analysis",
349
            'navigation' => "Contest",
350
            'site_title'=>$contest_name,
351
            'contest_name'=>$contest_name,
352
            'cid'=>$cid,
353
            'custom_info' => $customInfo,
354
            'clearance'=> $clearance,
355
            'basic'=>$basicInfo,
356
        ]);
357
    }
358
}
359