Passed
Push — master ( 46d43a...ae46ae )
by John
09:19 queued 04:28
created

BoardController::analysis()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 16
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 18
rs 9.7333
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
        if (!$clearance) {
37
            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...
38
        }
39
        $contest_name=$contestModel->contestName($cid);
40
        $contest_rule=$contestModel->contestRule($cid);
41
        $problemSet=$contestModel->contestProblems($cid, Auth::user()->id);
42
        $remainingTime=$contestModel->remainingTime($cid);
43
        $customInfo=$contestModel->getCustomInfo($cid);
44
        $clarificationList=$contestModel->getLatestClarification($cid);
45
        $basicInfo=$contestModel->basic($cid);
46
        if ($remainingTime<=0) {
47
            $remainingTime=0;
48
        }
49
        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...
50
            'page_title'=>"Challenge",
51
            'navigation' => "Contest",
52
            'site_title'=>$contest_name,
53
            'cid'=>$cid,
54
            'contest_name'=>$contest_name,
55
            'contest_rule'=>$contest_rule,
56
            'problem_set'=> $problemSet,
57
            'remaining_time'=>$remainingTime,
58
            'custom_info' => $customInfo,
59
            'clarification_list' => $clarificationList,
60
            'clearance'=> $clearance,
61
            'basic'=>$basicInfo,
62
        ]);
63
    }
64
65
    /**
66
     * Show the Contest Editor Page.
67
     *
68
     * @return Response
69
     */
70
    public function editor($cid, $ncode)
71
    {
72
        $contestModel=new ContestModel();
73
        $problemModel=new ProblemModel();
74
        $compilerModel=new CompilerModel();
75
        $submissionModel=new SubmissionModel();
76
        $accountModel=new AccountModel();
77
        $clearance=$contestModel->judgeClearance($cid, Auth::user()->id);
78
        if (!$clearance) {
79
            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...
80
        }
81
        $contest_name=$contestModel->contestName($cid);
82
        $contest_rule=$contestModel->rule($cid);
83
        $contest_ended=$contestModel->isContestEnded($cid);
84
        $pid=$contestModel->getPid($cid, $ncode);
85
        if (empty($pid)) {
86
            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...
87
        }
88
        $pcode=$problemModel->pcode($pid);
89
90
        $prob_detail=$problemModel->detail($pcode, $cid);
91
        if ($problemModel->isBlocked($prob_detail["pid"], $cid)) {
92
            return abort('403');
0 ignored issues
show
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...
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...
93
        }
94
        $compiler_list=$compilerModel->list($prob_detail["OJ"], $prob_detail["pid"]);
95
        $prob_status=$submissionModel->getProblemStatus($prob_detail["pid"], Auth::user()->id, $cid);
96
        $problemSet=$contestModel->contestProblems($cid, Auth::user()->id);
97
        $compiler_pref=$compilerModel->pref($compiler_list, $prob_detail["pid"], Auth::user()->id, $cid);
98
        $pref=$compiler_pref["pref"];
99
        $submit_code=$compiler_pref["code"];
100
        $oj_detail=$problemModel->ojdetail($prob_detail["OJ"]);
101
102
        if (empty($prob_status)) {
103
            $prob_status=[
104
                "verdict"=>"NOT SUBMIT",
105
                "color"=>""
106
            ];
107
        }
108
109
        $editor_left_width = $accountModel->getExtra(Auth::user()->id, 'editor_left_width');
110
        if(empty($editor_left_width)) $editor_left_width='40';
111
112
        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...
113
            'page_title'=>"Problem Detail",
114
            'navigation' => "Contest",
115
            'site_title'=>$contest_name,
116
            'contest_name'=>$contest_name,
117
            'cid'=> $cid,
118
            'detail' => $prob_detail,
119
            'compiler_list' => $compiler_list,
120
            'status' => $prob_status,
121
            'pref' => $pref<0 ? 0 : $pref,
122
            'submit_code' => $submit_code,
123
            'contest_mode' => true,
124
            'contest_ended' => $contest_ended,
125
            'ncode' => $ncode,
126
            'contest_rule' => $contest_rule,
127
            'problem_set' => $problemSet,
128
            'clearance' => $clearance,
129
            'oj_detail' => $oj_detail,
130
            'editor_left_width'=>$editor_left_width,
131
        ]);
132
    }
133
134
    /**
135
     * Show the Contest Rank Page.
136
     *
137
     * @return Response
138
     */
139
    public function rank($cid)
140
    {
141
        $contestModel=new ContestModel();
142
        $clearance=$contestModel->judgeClearance($cid, Auth::user()->id);
143
        if (!$clearance) {
144
            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...
145
        }
146
        $contest_name=$contestModel->contestName($cid);
147
        $contest_rule=$contestModel->contestRule($cid);
148
        $problemSet=$contestModel->contestProblems($cid, Auth::user()->id);
149
        $customInfo=$contestModel->getCustomInfo($cid);
150
        $contestRank=$contestModel->contestRank($cid, Auth::user()->id);
151
152
        // To determine the ranking
153
        foreach ($contestRank as $i => &$r) {
154
            if($i != 0) {
155
                if($r['score'] == $contestRank[$i-1]['score'] && $r['penalty'] == $contestRank[$i-1]['penalty']){
156
                    $r['rank'] = $contestRank[$i-1]['rank'];
157
                }else{
158
                    $r['rank'] = $i + 1;
159
                }
160
            }else{
161
                $r['rank'] = 1;
162
            }
163
        }
164
        $rankFrozen=$contestModel->isFrozen($cid);
165
        $frozenTime=$contestModel->frozenTime($cid);
166
        $basicInfo=$contestModel->basic($cid);
167
        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...
168
            'page_title'=>"Rank",
169
            'navigation' => "Contest",
170
            'site_title'=>$contest_name,
171
            'contest_name'=>$contest_name,
172
            'contest_rule'=>$contest_rule,
173
            'cid'=>$cid,
174
            'problem_set'=>$problemSet,
175
            'custom_info' => $customInfo,
176
            'contest_rank' => $contestRank,
177
            'rank_frozen' => $rankFrozen,
178
            'frozen_time' => $frozenTime,
179
            'clearance'=> $clearance,
180
            'basic'=>$basicInfo,
181
        ]);
182
    }
183
184
    /**
185
     * Show the Contest Status Page.
186
     *
187
     * @return Response
188
     */
189
    public function status(Request $request)
190
    {
191
        $all_data=$request->all();
192
        $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...
193
        $filter["result"]=isset($all_data["result"]) ? $all_data["result"] : null;
194
        $filter["account"]=isset($all_data["account"]) ? $all_data["account"] : null;
195
        $cid=$request->cid;
196
        $contestModel=new ContestModel();
197
        $clearance=$contestModel->judgeClearance($cid, Auth::user()->id);
198
        if (!$clearance) {
199
            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...
200
        }
201
        $contest_name=$contestModel->contestName($cid);
202
        $customInfo=$contestModel->getCustomInfo($cid);
203
        $basicInfo=$contestModel->basic($cid);
204
        $submissionRecordSet=$contestModel->getContestRecord($filter, $cid);
205
        $rankFrozen=$contestModel->isFrozen($cid);
206
        $frozenTime=$contestModel->frozenTime($cid);
207
        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...
208
            'page_title'=>"Status",
209
            'navigation' => "Contest",
210
            'site_title'=>$contest_name,
211
            'contest_name'=>$contest_name,
212
            'basic_info'=>$basicInfo,
213
            'cid'=>$cid,
214
            'custom_info' => $customInfo,
215
            'submission_record' => $submissionRecordSet,
216
            'rank_frozen' => $rankFrozen,
217
            'frozen_time' => $frozenTime,
218
            'clearance'=> $clearance,
219
            'filter' => $filter,
220
        ]);
221
    }
222
223
    /**
224
     * Show the Contest Clarification Page.
225
     *
226
     * @return Response
227
     */
228
    public function clarification($cid)
229
    {
230
        $contestModel=new ContestModel();
231
        $clearance=$contestModel->judgeClearance($cid, Auth::user()->id);
232
        if (!$clearance) {
233
            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...
234
        }
235
        $basicInfo=$contestModel->basic($cid);
236
        $contest_name=$contestModel->contestName($cid);
237
        $customInfo=$contestModel->getCustomInfo($cid);
238
        $clarificationList=$contestModel->getClarificationList($cid);
239
        $contest_ended=$contestModel->isContestEnded($cid);
240
        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...
241
            'page_title'=>"Clarification",
242
            'navigation' => "Contest",
243
            'site_title'=>$contest_name,
244
            'contest_name'=>$contest_name,
245
            'cid'=>$cid,
246
            'custom_info' => $customInfo,
247
            'clarification_list' => $clarificationList,
248
            'contest_ended' => $contest_ended,
249
            'clearance'=> $clearance,
250
            'basic'=>$basicInfo,
251
        ]);
252
    }
253
254
    /**
255
     * Show the Contest Print Page.
256
     *
257
     * @return Response
258
     */
259
    public function print($cid)
260
    {
261
        $contestModel=new ContestModel();
262
        $clearance=$contestModel->judgeClearance($cid, Auth::user()->id);
263
        if (!$clearance) {
264
            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...
265
        }
266
        $basicInfo=$contestModel->basic($cid);
267
        $contest_name=$contestModel->contestName($cid);
268
        $customInfo=$contestModel->getCustomInfo($cid);
269
        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...
270
            'page_title'=>"Print",
271
            'navigation' => "Contest",
272
            'site_title'=>$contest_name,
273
            'contest_name'=>$contest_name,
274
            'cid'=>$cid,
275
            'custom_info' => $customInfo,
276
            'clearance'=> $clearance,
277
            'basic'=>$basicInfo,
278
        ]);
279
    }
280
281
    public function analysis($cid){
282
        $contestModel=new ContestModel();
283
        $clearance=$contestModel->judgeClearance($cid, Auth::user()->id);
284
        if (!$clearance) {
285
            return Redirect::route('contest.detail', ['cid' => $cid]);
286
        }
287
        $contest_name=$contestModel->contestName($cid);
288
        $customInfo=$contestModel->getCustomInfo($cid);
289
        $basicInfo=$contestModel->basic($cid);
290
        return view('contest.board.analysis', [
291
            'page_title'=>"Analysis",
292
            'navigation' => "Contest",
293
            'site_title'=>$contest_name,
294
            'contest_name'=>$contest_name,
295
            'cid'=>$cid,
296
            'custom_info' => $customInfo,
297
            'clearance'=> $clearance,
298
            'basic'=>$basicInfo,
299
        ]);
300
    }
301
}
302