Passed
Branch dev (6ac00b)
by John
04:53
created

IndexController::analysis()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 1
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Http\Controllers\Group;
4
5
use App\Models\GroupModel;
6
use App\Models\ContestModel;
7
use App\Exports\GroupAnalysisExport;
8
use App\Http\Controllers\Controller;
9
use Illuminate\Http\Request;
10
use Excel;
11
use Auth;
12
use Redirect;
13
14
15
class IndexController extends Controller
16
{
17
    /**
18
     * Show the Group Page.
19
     *
20
     * @return Response
0 ignored issues
show
Bug introduced by
The type App\Http\Controllers\Group\Response was not found. Did you mean Response? If so, make sure to prefix the type with \.
Loading history...
21
     */
22
    public function index()
23
    {
24
        $groupModel=new GroupModel();
25
        $trending_groups=$groupModel->trendingGroups();
26
        $user_groups=Auth::check() ? $groupModel->userGroups(Auth::user()->id) : [];
27
        return view('group.index', [
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('group.index...mine' => $user_groups)) returns the type Illuminate\View\View which is incompatible with the documented return type App\Http\Controllers\Group\Response.
Loading history...
28
            'page_title' => "Group",
29
            'site_title' => config("app.name"),
30
            'navigation' => "Group",
31
            'trending' => $trending_groups,
32
            'mine' => $user_groups
33
        ]);
34
    }
35
36
    /**
37
     * Show the Group Detail Page.
38
     *
39
     * @return Response
40
     */
41
    public function detail($gcode)
42
    {
43
        $groupModel=new GroupModel();
44
        $contestModel=new ContestModel();
45
        $basic_info=$groupModel->details($gcode);
46
        if(empty($basic_info)) return Redirect::route('group.index');
0 ignored issues
show
Bug Best Practice introduced by
The expression return Redirect::route('group.index') returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type App\Http\Controllers\Group\Response.
Loading history...
47
        $my_profile=$groupModel->userProfile(Auth::user()->id, $basic_info["gid"]);
48
        $clearance=$groupModel->judgeClearance($basic_info["gid"], Auth::user()->id);
49
        $member_list=$groupModel->userList($basic_info["gid"]);
50
        $group_notice=$groupModel->groupNotice($basic_info["gid"]);
51
        $contest_list=$contestModel->listByGroup($basic_info["gid"])['contest_list'];
52
        $paginator=$contestModel->listByGroup($basic_info["gid"])['paginator'];
53
        return view('group.detail', [
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('group.detai...arance' => $clearance)) returns the type Illuminate\View\View which is incompatible with the documented return type App\Http\Controllers\Group\Response.
Loading history...
54
            'page_title'=>"Group Detail",
55
            'site_title'=>config("app.name"),
56
            'navigation'=>"Group",
57
            "basic_info"=>$basic_info,
58
            'my_profile'=>$my_profile,
59
            'member_list'=>$member_list,
60
            'group_notice'=>$group_notice,
61
            'contest_list'=>$contest_list,
62
            'paginator'=>$paginator,
63
            'group_clearance'=>$clearance
64
        ]);
65
    }
66
67
    /**
68
     * Show the Group Create Page.
69
     *
70
     * @return Response
71
     */
72
    public function create()
73
    {
74
        $groupModel=new GroupModel();
0 ignored issues
show
Unused Code introduced by
The assignment to $groupModel is dead and can be removed.
Loading history...
75
        //$basic_info=$groupModel->details($gcode);
76
        return view('group.create', [
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('group.creat...avigation' => 'Group')) returns the type Illuminate\View\View which is incompatible with the documented return type App\Http\Controllers\Group\Response.
Loading history...
77
            'page_title'=>"Group Create",
78
            'site_title'=>config("app.name"),
79
            'navigation'=>"Group",
80
            //"basic_info"=>$basic_info,
81
        ]);
82
    }
83
84
    /*
85
     * Show the Contest Analysis Tab.
86
     *
87
     * @return Response
88
     */
89
    public function analysis($gcode){
90
        $groupModel = new GroupModel();
91
        $group_info = $groupModel->details($gcode);
92
        return view('group.settings.analysis', [
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('group.setti..._info' => $group_info)) returns the type Illuminate\View\View which is incompatible with the documented return type App\Http\Controllers\Group\Response.
Loading history...
93
            'page_title'=>"Group Analysis",
94
            'site_title'=>"NOJ",
95
            'navigation'=>"Group",
96
            'group_info'=>$group_info,
97
            "basic_info"=>$group_info,
98
        ]);
99
    }
100
101
    public function analysisDownload($gcode,Request $request){
102
        $all_data = $request->all();
103
        $groupModel = new GroupModel();
104
        $group_info = $groupModel->details($gcode);
105
        $mode = $all_data['mode'] ?? 'contest';
106
        if($mode == 'contest'){
107
            $data = $groupModel->groupMemberPracticeContestStat($group_info['gid']);
108
            return Excel::download(
109
                new GroupAnalysisExport(
110
                    [
111
                        'contest_data' => $data['contest_list'],
112
                        'member_data' => $data['member_data'],
113
                    ],
114
                    [
115
                        'mode' => $all_data['mode'] ?? 'contest',
116
                        'maxium' => $all_data['maxium'] ?? true,
117
                        'percent' => $all_data['percent'] ?? false,
118
                    ]
119
                ),
120
                $gcode . '_Group_Contest_Analysis.xlsx'
121
            );
122
        }else{
123
            $data = $groupModel->groupMemberPracticeTagStat($group_info['gid']);
124
            return Excel::download(
125
                new GroupAnalysisExport(
126
                    [
127
                        'tag_problems' => $data['tag_problems'],
128
                        'member_data' => $data['member_data'],
129
                    ],
130
                    [
131
                        'mode' => $all_data['mode'] ?? 'tag',
132
                        'maxium' => $all_data['maxium'] ?? true,
133
                        'percent' => $all_data['percent'] ?? false,
134
                    ]
135
                ),
136
                $gcode . '_Group_Tag_Analysis.xlsx'
137
            );
138
        }
139
    }
140
}
141