Passed
Pull Request — master (#185)
by
unknown
04:11
created

ContestController::downloadContestAccountXlsx()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 11
nc 3
nop 1
dl 0
loc 14
rs 9.9
c 0
b 0
f 0
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Models\ContestModel;
6
use App\Models\GroupModel;
7
use App\Models\ProblemModel;
8
use App\Models\CompilerModel;
9
use App\Models\SubmissionModel;
10
use App\Models\AccountModel;
11
use App\Http\Controllers\Controller;
12
use Illuminate\Http\Request;
13
use Auth;
14
use Redirect;
15
use App\Exports\AccountExport;
16
use Excel;
17
use Cache;
18
19
class ContestController extends Controller
20
{
21
    /**
22
     * Show the Contest Page.
23
     *
24
     * @return Response
0 ignored issues
show
Bug introduced by
The type App\Http\Controllers\Response was not found. Did you mean Response? If so, make sure to prefix the type with \.
Loading history...
25
     */
26
    public function index(Request $request)
27
    {
28
        $all_data=$request->all();
29
        $contestModel=new ContestModel();
30
        $filter["rule"]=isset($all_data["rule"]) ? $all_data["rule"] : 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...
31
        $filter["public"]=isset($all_data["public"]) ? $all_data["public"] : null;
32
        $filter["verified"]=isset($all_data["verified"]) ? $all_data["verified"] : null;
33
        $filter["rated"]=isset($all_data["rated"]) ? $all_data["rated"] : null;
34
        $filter["anticheated"]=isset($all_data["anticheated"]) ? $all_data["anticheated"] : null;
35
        $filter["practice"]=isset($all_data["practice"]) ? $all_data["practice"] : null;
36
        $return_list=$contestModel->list($filter,Auth::check()?Auth::user()->id:0);
37
        $featured=$contestModel->featured();
38
        if (is_null($return_list)) {
0 ignored issues
show
introduced by
The condition is_null($return_list) is always false.
Loading history...
39
            if (isset($all_data["page"]) && $all_data["page"]>1) {
40
                return redirect("/contest");
41
            } else {
42
                return view('contest.index', [
43
                    'page_title'=>"Contest",
44
                    'site_title'=>config("app.name"),
45
                    'navigation' => "Contest",
46
                    'contest_list'=> null,
47
                    'paginator' => null,
48
                    'featured'=>$featured,
49
                    'filter' => $filter
50
                ]);
51
            }
52
        } else {
53
            return view('contest.index', [
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('contest.ind..., 'filter' => $filter)) returns the type Illuminate\View\View which is incompatible with the documented return type App\Http\Controllers\Response.
Loading history...
54
                'page_title'=>"Contest",
55
                'site_title'=>config("app.name"),
56
                'navigation' => "Contest",
57
                'contest_list'=>$return_list['contents'],
58
                'paginator' => $return_list['paginator'],
59
                'featured'=>$featured,
60
                'filter' => $filter
61
            ]);
62
        }
63
    }
64
65
    /**
66
     * Show the Contest Detail Page.
67
     *
68
     * @return Response
69
     */
70
    public function detail($cid)
71
    {
72
        $contestModel=new ContestModel();
73
        $groupModel=new GroupModel();
74
        $clearance=Auth::check() ? $contestModel->judgeClearance($cid, Auth::user()->id) : 0;
75
        if (Auth::check()) {
76
            $contest_detail=$contestModel->detail($cid, Auth::user()->id);
77
            $registration=$contestModel->registration($cid, Auth::user()->id);
78
            $inGroup=$groupModel->isMember($contest_detail["data"]["contest_detail"]["gid"], Auth::user()->id);
79
        } else {
80
            $contest_detail=$contestModel->detail($cid);
81
            $registration=[];
82
            $inGroup=false;
83
        }
84
        if ($contest_detail["ret"]!=200) {
85
            return Redirect::route('contest.index');
0 ignored issues
show
Bug Best Practice introduced by
The expression return Redirect::route('contest.index') returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type App\Http\Controllers\Response.
Loading history...
86
        }
87
        return view('contest.detail', [
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('contest.det...'inGroup' => $inGroup)) returns the type Illuminate\View\View which is incompatible with the documented return type App\Http\Controllers\Response.
Loading history...
88
            'page_title'=>"Contest",
89
            'site_title'=>config("app.name"),
90
            'navigation' => "Contest",
91
            'detail'=>$contest_detail["data"]["contest_detail"],
92
            'clearance' => $clearance,
93
            'registration' => $registration,
94
            'inGroup' => $inGroup
95
        ]);
96
    }
97
98
    /**
99
     * Redirect the Contest Board Page.
100
     *
101
     * @return Response
102
     */
103
    public function board($cid)
104
    {
105
        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\Response.
Loading history...
106
    }
107
108
    /**
109
     * Show the Contest Challenge Page.
110
     *
111
     * @return Response
112
     */
113
    public function challenge($cid)
114
    {
115
        $contestModel=new ContestModel();
116
        $clearance=$contestModel->judgeClearance($cid, Auth::user()->id);
117
        if (!$clearance) {
118
            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\Response.
Loading history...
119
        }
120
        $contest_name=$contestModel->contestName($cid);
121
        $contest_rule=$contestModel->contestRule($cid);
122
        $problemSet=$contestModel->contestProblems($cid, Auth::user()->id);
123
        $remainingTime=$contestModel->remainingTime($cid);
124
        $customInfo=$contestModel->getCustomInfo($cid);
125
        $clarificationList=$contestModel->getLatestClarification($cid);
126
        $basicInfo=$contestModel->basic($cid);
127
        if ($remainingTime<=0) {
128
            $remainingTime=0;
129
        }
130
        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\Response.
Loading history...
131
            'page_title'=>"Challenge",
132
            'navigation' => "Contest",
133
            'site_title'=>$contest_name,
134
            'cid'=>$cid,
135
            'contest_name'=>$contest_name,
136
            'contest_rule'=>$contest_rule,
137
            'problem_set'=> $problemSet,
138
            'remaining_time'=>$remainingTime,
139
            'custom_info' => $customInfo,
140
            'clarification_list' => $clarificationList,
141
            'clearance'=> $clearance,
142
            'basic'=>$basicInfo,
143
        ]);
144
    }
145
146
    /**
147
     * Show the Contest Editor Page.
148
     *
149
     * @return Response
150
     */
151
    public function editor($cid, $ncode)
152
    {
153
        $contestModel=new ContestModel();
154
        $problemModel=new ProblemModel();
155
        $compilerModel=new CompilerModel();
156
        $submissionModel=new SubmissionModel();
157
        $accountModel=new AccountModel();
158
        $clearance=$contestModel->judgeClearance($cid, Auth::user()->id);
159
        if (!$clearance) {
160
            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\Response.
Loading history...
161
        }
162
        $contest_name=$contestModel->contestName($cid);
163
        $contest_rule=$contestModel->rule($cid);
164
        $contest_ended=$contestModel->isContestEnded($cid);
165
        $pid=$contestModel->getPid($cid, $ncode);
166
        if (empty($pid)) {
167
            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\Response.
Loading history...
168
        }
169
        $pcode=$problemModel->pcode($pid);
170
171
        $prob_detail=$problemModel->detail($pcode, $cid);
172
        if ($problemModel->isBlocked($prob_detail["pid"], $cid)) {
173
            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\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...
174
        }
175
        $compiler_list=$compilerModel->list($prob_detail["OJ"], $prob_detail["pid"]);
176
        $prob_status=$submissionModel->getProblemStatus($prob_detail["pid"], Auth::user()->id, $cid);
177
        $problemSet=$contestModel->contestProblems($cid, Auth::user()->id);
178
        $compiler_pref=$compilerModel->pref($compiler_list, $prob_detail["pid"], Auth::user()->id, $cid);
179
        $pref=$compiler_pref["pref"];
180
        $submit_code=$compiler_pref["code"];
181
        $oj_detail=$problemModel->ojdetail($prob_detail["OJ"]);
182
183
        if (empty($prob_status)) {
184
            $prob_status=[
185
                "verdict"=>"NOT SUBMIT",
186
                "color"=>""
187
            ];
188
        }
189
190
        $editor_left_width = $accountModel->getExtra(Auth::user()->id, 'editor_left_width');
191
        if(empty($editor_left_width)) $editor_left_width='40';
192
193
        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\Response.
Loading history...
194
            'page_title'=>"Problem Detail",
195
            'navigation' => "Contest",
196
            'site_title'=>$contest_name,
197
            'contest_name'=>$contest_name,
198
            'cid'=> $cid,
199
            'detail' => $prob_detail,
200
            'compiler_list' => $compiler_list,
201
            'status' => $prob_status,
202
            'pref' => $pref<0 ? 0 : $pref,
203
            'submit_code' => $submit_code,
204
            'contest_mode' => true,
205
            'contest_ended' => $contest_ended,
206
            'ncode' => $ncode,
207
            'contest_rule' => $contest_rule,
208
            'problem_set' => $problemSet,
209
            'clearance' => $clearance,
210
            'oj_detail' => $oj_detail,
211
            'editor_left_width'=>$editor_left_width,
212
        ]);
213
    }
214
215
    /**
216
     * Show the Contest Rank Page.
217
     *
218
     * @return Response
219
     */
220
    public function rank($cid)
221
    {
222
        $contestModel=new ContestModel();
223
        $clearance=$contestModel->judgeClearance($cid, Auth::user()->id);
224
        if (!$clearance) {
225
            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\Response.
Loading history...
226
        }
227
        $contest_name=$contestModel->contestName($cid);
228
        $contest_rule=$contestModel->contestRule($cid);
229
        $problemSet=$contestModel->contestProblems($cid, Auth::user()->id);
230
        $customInfo=$contestModel->getCustomInfo($cid);
231
        $contestRank=$contestModel->contestRank($cid, Auth::user()->id);
232
        $rankFrozen=$contestModel->isFrozen($cid);
233
        $frozenTime=$contestModel->frozenTime($cid);
234
        $basicInfo=$contestModel->basic($cid);
235
        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\Response.
Loading history...
236
            'page_title'=>"Challenge",
237
            'navigation' => "Contest",
238
            'site_title'=>$contest_name,
239
            'contest_name'=>$contest_name,
240
            'contest_rule'=>$contest_rule,
241
            'cid'=>$cid,
242
            'problem_set'=>$problemSet,
243
            'custom_info' => $customInfo,
244
            'contest_rank' => $contestRank,
245
            'rank_frozen' => $rankFrozen,
246
            'frozen_time' => $frozenTime,
247
            'clearance'=> $clearance,
248
            'basic'=>$basicInfo,
249
        ]);
250
    }
251
252
    /**
253
     * Show the Contest Status Page.
254
     *
255
     * @return Response
256
     */
257
    public function status($cid)
258
    {
259
        $contestModel=new ContestModel();
260
        $clearance=$contestModel->judgeClearance($cid, Auth::user()->id);
261
        if (!$clearance) {
262
            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\Response.
Loading history...
263
        }
264
        $contest_name=$contestModel->contestName($cid);
265
        $customInfo=$contestModel->getCustomInfo($cid);
266
        $basicInfo=$contestModel->basic($cid);
267
        $submissionRecordSet=$contestModel->getContestRecord($cid);
268
        $rankFrozen=$contestModel->isFrozen($cid);
269
        $frozenTime=$contestModel->frozenTime($cid);
270
        return view('contest.board.status', [
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('contest.boa...arance' => $clearance)) returns the type Illuminate\View\View which is incompatible with the documented return type App\Http\Controllers\Response.
Loading history...
271
            'page_title'=>"Status",
272
            'navigation' => "Contest",
273
            'site_title'=>$contest_name,
274
            'contest_name'=>$contest_name,
275
            'basic_info'=>$basicInfo,
276
            'cid'=>$cid,
277
            'custom_info' => $customInfo,
278
            'submission_record' => $submissionRecordSet,
279
            'rank_frozen' => $rankFrozen,
280
            'frozen_time' => $frozenTime,
281
            'clearance'=> $clearance,
282
        ]);
283
    }
284
285
    /**
286
     * Show the Contest Clarification Page.
287
     *
288
     * @return Response
289
     */
290
    public function clarification($cid)
291
    {
292
        $contestModel=new ContestModel();
293
        $clearance=$contestModel->judgeClearance($cid, Auth::user()->id);
294
        if (!$clearance) {
295
            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\Response.
Loading history...
296
        }
297
        $basicInfo=$contestModel->basic($cid);
298
        $contest_name=$contestModel->contestName($cid);
299
        $customInfo=$contestModel->getCustomInfo($cid);
300
        $clarificationList=$contestModel->getClarificationList($cid);
301
        $contest_ended=$contestModel->isContestEnded($cid);
302
        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\Response.
Loading history...
303
            'page_title'=>"Clarification",
304
            'navigation' => "Contest",
305
            'site_title'=>$contest_name,
306
            'contest_name'=>$contest_name,
307
            'cid'=>$cid,
308
            'custom_info' => $customInfo,
309
            'clarification_list' => $clarificationList,
310
            'contest_ended' => $contest_ended,
311
            'clearance'=> $clearance,
312
            'basic'=>$basicInfo,
313
        ]);
314
    }
315
316
    /**
317
     * Show the Contest Print Page.
318
     *
319
     * @return Response
320
     */
321
    public function print($cid)
322
    {
323
        $contestModel=new ContestModel();
324
        $clearance=$contestModel->judgeClearance($cid, Auth::user()->id);
325
        if (!$clearance) {
326
            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\Response.
Loading history...
327
        }
328
        $basicInfo=$contestModel->basic($cid);
329
        $contest_name=$contestModel->contestName($cid);
330
        $customInfo=$contestModel->getCustomInfo($cid);
331
        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\Response.
Loading history...
332
            'page_title'=>"Print",
333
            'navigation' => "Contest",
334
            'site_title'=>$contest_name,
335
            'contest_name'=>$contest_name,
336
            'cid'=>$cid,
337
            'custom_info' => $customInfo,
338
            'clearance'=> $clearance,
339
            'basic'=>$basicInfo,
340
        ]);
341
    }
342
343
    /**
344
     * Show the Contest Admin Page.
345
     *
346
     * @return Response
347
     */
348
    public function admin($cid)
349
    {
350
        $contestModel=new ContestModel();
351
        $verified=$contestModel->isVerified($cid);
352
        $clearance=$contestModel->judgeClearance($cid, Auth::user()->id);
353
        if ($clearance <= 2) {
354
            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\Response.
Loading history...
355
        }
356
        $contest_name=$contestModel->contestName($cid);
357
        $customInfo=$contestModel->getCustomInfo($cid);
358
        $accountModel=new AccountModel();
359
        $basicInfo=$contestModel->basic($cid);
360
        $contest_accounts=$accountModel->getContestAccount($cid);
361
        $gcode=$contestModel->gcode($cid);
362
        return view('contest.board.admin', [
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\Response.
Loading history...
363
            'page_title'=>"Admin",
364
            'navigation' => "Contest",
365
            'site_title'=>$contest_name,
366
            'contest_name'=>$contest_name,
367
            'cid'=>$cid,
368
            'custom_info' => $customInfo,
369
            'clearance'=> $clearance,
370
            'contest_accounts'=>$contest_accounts,
371
            'verified'=>$verified,
372
            'gcode'=>$gcode,
373
            'basic'=>$basicInfo,
374
        ]);
375
    }
376
377
    public function downloadContestAccountXlsx($cid)
378
    {
379
        $contestModel=new ContestModel();
380
        $clearance=$contestModel->judgeClearance($cid, Auth::user()->id);
381
        if ($clearance <= 2) {
382
            return Redirect::route('contest_detail', ['cid' => $cid]);
383
        }
384
        $account=$contestModel->getContestAccount($cid);
385
        if($account==null){
386
            return ;
387
        }else{
388
            $AccountExport=new AccountExport($account);
389
            $filename="ContestAccount$cid";
390
            return Excel::download($AccountExport, $filename.'.xlsx');
391
        }
392
    }
393
394
    public function analysis($cid){
395
        $contestModel=new ContestModel();
396
        $clearance=$contestModel->judgeClearance($cid, Auth::user()->id);
397
        if (!$clearance) {
398
            return Redirect::route('contest.detail', ['cid' => $cid]);
399
        }
400
        $contest_name=$contestModel->contestName($cid);
401
        $customInfo=$contestModel->getCustomInfo($cid);
402
        $basicInfo=$contestModel->basic($cid);
403
        return view('contest.board.analysis', [
404
            'page_title'=>"Analysis",
405
            'navigation' => "Contest",
406
            'site_title'=>$contest_name,
407
            'contest_name'=>$contest_name,
408
            'cid'=>$cid,
409
            'custom_info' => $customInfo,
410
            'clearance'=> $clearance,
411
            'basic'=>$basicInfo,
412
        ]);
413
    }
414
415
    public function refreshContestRank($cid){
416
        $contestModel=new ContestModel();
417
        $clearance=$contestModel->judgeClearance($cid, Auth::user()->id);
418
        if ($clearance <= 2) {
419
            return Redirect::route('contest_detail', ['cid' => $cid]);
420
        }
421
        $contestRankRaw=$contestModel->contestRankCache($cid);
422
        Cache::tags(['contest', 'rank'])->put($cid, $contestRankRaw);
423
        Cache::tags(['contest', 'rank'])->put("contestAdmin$cid", $contestRankRaw);
424
        dd("success");
425
    }
426
}
427