Passed
Branch dev (32180c)
by John
03:42
created

AdminController   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 46
c 0
b 0
f 0
dl 0
loc 67
rs 10
wmc 8

3 Methods

Rating   Name   Duplication   Size   Complexity  
A downloadContestAccountXlsx() 0 14 3
A admin() 0 26 2
A refreshContestRank() 0 14 3
1
<?php
2
3
namespace App\Http\Controllers\Contest;
4
5
use App\Models\ContestModel;
6
use App\Models\AccountModel;
7
use App\Http\Controllers\Controller;
8
use Auth;
9
use Redirect;
10
use App\Exports\AccountExport;
11
use Excel;
12
use Cache;
13
use DB;
14
15
class AdminController extends Controller
16
{
17
    /**
18
     * Show the Contest Admin 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 admin($cid)
23
    {
24
        $contestModel=new ContestModel();
25
        $verified=$contestModel->isVerified($cid);
26
        $clearance=$contestModel->judgeClearance($cid, Auth::user()->id);
27
        if ($clearance <= 2) {
28
            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...
29
        }
30
        $contest_name=$contestModel->contestName($cid);
31
        $customInfo=$contestModel->getCustomInfo($cid);
32
        $accountModel=new AccountModel();
33
        $basicInfo=$contestModel->basic($cid);
34
        $contest_accounts=$accountModel->getContestAccount($cid);
35
        $gcode=$contestModel->gcode($cid);
36
        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\Contest\Response.
Loading history...
37
            'page_title'=>"Admin",
38
            'navigation' => "Contest",
39
            'site_title'=>$contest_name,
40
            'contest_name'=>$contest_name,
41
            'cid'=>$cid,
42
            'custom_info' => $customInfo,
43
            'clearance'=> $clearance,
44
            'contest_accounts'=>$contest_accounts,
45
            'verified'=>$verified,
46
            'gcode'=>$gcode,
47
            'basic'=>$basicInfo,
48
        ]);
49
    }
50
51
    public function downloadContestAccountXlsx($cid)
52
    {
53
        $contestModel=new ContestModel();
54
        $clearance=$contestModel->judgeClearance($cid, Auth::user()->id);
55
        if ($clearance <= 2) {
56
            return Redirect::route('contest_detail', ['cid' => $cid]);
57
        }
58
        $account=$contestModel->getContestAccount($cid);
59
        if($account==null){
60
            return ;
61
        }else{
62
            $AccountExport=new AccountExport($account);
63
            $filename="ContestAccount$cid";
64
            return Excel::download($AccountExport, $filename.'.xlsx');
65
        }
66
    }
67
68
    public function refreshContestRank($cid){
69
        $contestModel=new ContestModel();
70
        $clearance=$contestModel->judgeClearance($cid, Auth::user()->id);
71
        if ($clearance <= 2) {
72
            return Redirect::route('contest.detail', ['cid' => $cid]);
73
        }
74
        $contestRankRaw=$contestModel->contestRankCache($cid);
75
        Cache::tags(['contest', 'rank'])->put($cid, $contestRankRaw);
76
        Cache::tags(['contest', 'rank'])->put("contestAdmin$cid", $contestRankRaw);
77
        $end_time=strtotime(DB::table("contest")->where(["cid"=>$cid])->select("end_time")->first()["end_time"]);
78
        if(time() > $end_time){
79
            $contestModel->storeContestRankInMySQL($cid, $contestRankRaw);
80
        }
81
        return Redirect::route('contest.rank', ['cid' => $cid]);
82
    }
83
}
84