Passed
Pull Request — master (#257)
by
unknown
05:15
created

BoardController::clarification()   B

Complexity

Conditions 6
Paths 4

Size

Total Lines 30
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 25
nc 4
nop 1
dl 0
loc 30
rs 8.8977
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\Models\AccountModel;
10
use App\Http\Controllers\Controller;
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.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);
36
        $basicInfo=$contestModel->basic($cid);
37
        if (!$clearance || time() < strtotime($basicInfo['begin_time'])) {
38
            if($clearance == 3){
39
                return Redirect::route('contest.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
        $accountModel=new AccountModel();
84
        $clearance=$contestModel->judgeClearance($cid, Auth::user()->id);
85
        $basicInfo=$contestModel->basic($cid);
86
        if (!$clearance || time() < strtotime($basicInfo['begin_time'])) {
87
            if($clearance == 3){
88
                return Redirect::route('contest.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...
89
            }else{
90
                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...
91
            }
92
        }
93
        $basicInfo=$contestModel->basic($cid);
94
        if($basicInfo['public'] && !$basicInfo['audit_status']){
95
            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...
96
        }
97
        $contest_name=$contestModel->contestName($cid);
98
        $contest_rule=$contestModel->rule($cid);
99
        $contest_ended=$contestModel->isContestEnded($cid);
100
        $pid=$contestModel->getPid($cid, $ncode);
101
        if (empty($pid)) {
102
            return Redirect::route('contest.board', ['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...
103
        }
104
        $pcode=$problemModel->pcode($pid);
105
106
        $prob_detail=$problemModel->detail($pcode, $cid);
107
        if ($problemModel->isBlocked($prob_detail["pid"], $cid)) {
108
            return abort('403');
0 ignored issues
show
Bug Best Practice introduced by
The expression return abort('403') returns the type void which is incompatible with the documented return type App\Http\Controllers\Contest\Response.
Loading history...
Bug introduced by
Are you sure the usage of abort('403') is correct as it seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

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