Passed
Pull Request — master (#264)
by John
04:37
created

ProblemController::discussionPost()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 23
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 19
c 0
b 0
f 0
nc 3
nop 1
dl 0
loc 23
rs 9.6333
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Models\ProblemModel;
6
use App\Models\Submission\SubmissionModel;
7
use App\Models\CompilerModel;
8
use App\Models\AccountModel;
9
use App\Http\Controllers\Controller;
10
use Illuminate\Http\Request;
11
use JavaScript;
12
use Auth;
13
14
class ProblemController extends Controller
15
{
16
    /**
17
     * Show the Problem Index Page.
18
     *
19
     * @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...
20
     */
21
    public function index(Request $request)
22
    {
23
        $all_data=$request->all();
24
        $problem=new ProblemModel();
25
        $filter["oj"]=isset($all_data["oj"]) ? $all_data["oj"] : 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...
26
        $filter["tag"]=isset($all_data["tag"]) ? $all_data["tag"] : null;
27
        $list_return=$problem->list($filter, Auth::check() ?Auth::user()->id : null);
28
        $tags=$problem->tags();
29
        $ojs=$problem->ojs();
30
        if (is_null($list_return)) {
31
            if (isset($all_data["page"]) && $all_data["page"]>1) {
32
                return redirect("/problem");
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect('/problem') returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type App\Http\Controllers\Response.
Loading history...
33
            } else {
34
                return view('problem.index', [
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('problem.ind..., 'filter' => $filter)) returns the type Illuminate\View\View which is incompatible with the documented return type App\Http\Controllers\Response.
Loading history...
35
                    'page_title' => "Problem",
36
                    'site_title' => config("app.name"),
37
                    'navigation' => "Problem",
38
                    'prob_list' => null,
39
                    'prob_paginate' => null,
40
                    'tags' => $tags,
41
                    'ojs' => $ojs,
42
                    'filter' => $filter
43
                ]);
44
            }
45
        } else {
46
            return view('problem.index', [
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('problem.ind..., 'filter' => $filter)) returns the type Illuminate\View\View which is incompatible with the documented return type App\Http\Controllers\Response.
Loading history...
47
                'page_title' => "Problem",
48
                'site_title' => config("app.name"),
49
                'navigation' => "Problem",
50
                'prob_list' => $list_return['problems'],
51
                'paginator' => $list_return['paginator'],
52
                'tags' => $tags,
53
                'ojs' => $ojs,
54
                'filter' => $filter
55
            ]);
56
        }
57
    }
58
    /**
59
     * Show the Problem Detail Page.
60
     *
61
     * @return Response
62
     */
63
    public function detail($pcode)
64
    {
65
        $problem=new ProblemModel();
66
        $prob_detail=$problem->detail($pcode);
67
        if ($problem->isBlocked($prob_detail["pid"]) || $problem->isHidden($prob_detail["pid"])) {
68
            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\Response.
Loading history...
69
        }
70
        return is_null($prob_detail) ?  redirect("/problem") : view('problem.detail', [
0 ignored issues
show
Bug Best Practice introduced by
The expression return is_null($prob_det...tail' => $prob_detail)) returns the type Illuminate\Http\Redirect...se|Illuminate\View\View which is incompatible with the documented return type App\Http\Controllers\Response.
Loading history...
71
                                            'page_title'=>$prob_detail["title"],
72
                                            'site_title'=>config("app.name"),
73
                                            'navigation' => "Problem",
74
                                            'detail' => $prob_detail
75
                                        ]);
76
    }
77
78
    /**
79
     * Show the Problem Solution Page.
80
     *
81
     * @return Response
82
     */
83
    public function solution($pcode)
84
    {
85
        $problem=new ProblemModel();
86
        $prob_detail=$problem->detail($pcode);
87
        if ($problem->isBlocked($prob_detail["pid"]) || $problem->isHidden($prob_detail["pid"])) {
88
            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...
89
        }
90
        $solution=$problem->solutionList($prob_detail["pid"], Auth::check() ?Auth::user()->id : null);
91
        $submitted=Auth::check() ? $problem->solution($prob_detail["pid"], Auth::user()->id) : [];
92
        return is_null($prob_detail) ?  redirect("/problem") : view('problem.solution', [
0 ignored issues
show
Bug Best Practice introduced by
The expression return is_null($prob_det...mitted' => $submitted)) returns the type Illuminate\Http\Redirect...se|Illuminate\View\View which is incompatible with the documented return type App\Http\Controllers\Response.
Loading history...
93
                                            'page_title'=> "Solution",
94
                                            'site_title'=>config("app.name"),
95
                                            'navigation' => $prob_detail["title"],
96
                                            'detail' => $prob_detail,
97
                                            'solution'=>$solution,
98
                                            'submitted'=>$submitted
99
                                        ]);
100
    }
101
102
    /**
103
     * Show the Problem Editor Page.
104
     *
105
     * @return Response
106
     */
107
    public function editor($pcode)
108
    {
109
        $problem=new ProblemModel();
110
        $compiler=new CompilerModel();
111
        $submission=new SubmissionModel();
112
        $account=new AccountModel();
113
114
        $prob_detail=$problem->detail($pcode);
115
        if ($problem->isBlocked($prob_detail["pid"]) || $problem->isHidden($prob_detail["pid"])) {
116
            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...
117
        }
118
        $compiler_list=$compiler->list($prob_detail["OJ"], $prob_detail["pid"]);
119
        $prob_status=$submission->getProblemStatus($prob_detail["pid"], Auth::user()->id);
120
121
        $compiler_pref=$compiler->pref($compiler_list, $prob_detail["pid"], Auth::user()->id);
122
        $pref=$compiler_pref["pref"];
123
        $submit_code=$compiler_pref["code"];
124
125
        $oj_detail=$problem->ojdetail($prob_detail["OJ"]);
126
127
        if (empty($prob_status)) {
128
            $prob_status=[
129
                "verdict"=>"NOT SUBMIT",
130
                "color"=>""
131
            ];
132
        }
133
134
        $editor_left_width = $account->getExtra(Auth::user()->id, 'editor_left_width');
135
        if(empty($editor_left_width)) $editor_left_width='40';
136
137
        return is_null($prob_detail) ?  redirect("/problem") : view('problem.editor', [
0 ignored issues
show
Bug Best Practice introduced by
The expression return is_null($prob_det...=> $editor_left_width)) returns the type Illuminate\Http\Redirect...se|Illuminate\View\View which is incompatible with the documented return type App\Http\Controllers\Response.
Loading history...
138
                                            'page_title'=>$prob_detail["title"],
139
                                            'site_title'=>config("app.name"),
140
                                            'navigation' => "Problem",
141
                                            'detail' => $prob_detail,
142
                                            'compiler_list' => $compiler_list,
143
                                            'status' => $prob_status,
144
                                            'pref'=>$pref<0 ? 0 : $pref,
145
                                            'submit_code'=>$submit_code,
146
                                            'contest_mode'=> false,
147
                                            'oj_detail'=>$oj_detail,
148
                                            'editor_left_width'=>$editor_left_width,
149
                                        ]);
150
    }
151
152
        /**
153
     * Show the Problem Discussion Page.
154
     *
155
     * @return Response
156
     */
157
    public function discussion($pcode)
158
    {
159
        //TODO
160
        $problem=new ProblemModel();
161
        $prob_detail=$problem->detail($pcode);
162
        if ($problem->isBlocked($prob_detail["pid"])) {
163
            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\Response.
Loading history...
164
        }
165
        $list=$problem->discussionList($prob_detail["pid"]);
166
        $discussion=$list['list'];
167
        $paginator=$list['paginator'];
168
        return is_null($prob_detail) ?  redirect("/problem") : view('problem.discussion', [
0 ignored issues
show
Bug Best Practice introduced by
The expression return is_null($prob_det...inator' => $paginator)) returns the type Illuminate\Http\Redirect...se|Illuminate\View\View which is incompatible with the documented return type App\Http\Controllers\Response.
Loading history...
169
                                            'page_title'=> "Discussion",
170
                                            'site_title'=>config("app.name"),
171
                                            'navigation' => $prob_detail["title"],
172
                                            'detail' => $prob_detail,
173
                                            'discussion'=>$discussion,
174
                                            'paginator'=>$paginator
175
                                        ]);
176
    }
177
178
    /**
179
     * Show the Problem Discussion Post Page.
180
     *
181
     * @return Response
182
     */
183
    public function discussionPost($dcode)
184
    {
185
        //TODO
186
        $problem=new ProblemModel();
187
        $pcode=$problem->pcodeByPdid($dcode);
188
        $prob_detail=$problem->detail($pcode);
189
        if ($problem->isBlocked($prob_detail["pid"])) {
190
            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...
191
        }
192
        $detail=$problem->discussionDetail($dcode);
193
        $main=$detail['main'];
194
        $paginator=$detail['paginator'];
195
        $comment=$detail['comment'];
196
        $comment_count=$detail['comment_count'];
197
        return is_null($prob_detail) ?  redirect("/problem") : view('problem.discussion_post', [
0 ignored issues
show
Bug Best Practice introduced by
The expression return is_null($prob_det...nt' => $comment_count)) returns the type Illuminate\Http\Redirect...se|Illuminate\View\View which is incompatible with the documented return type App\Http\Controllers\Response.
Loading history...
198
                                            'page_title'=> "Discussion",
199
                                            'site_title'=>config("app.name"),
200
                                            'navigation' => $prob_detail["title"],
201
                                            'detail' => $prob_detail,
202
                                            'main'=>$main,
203
                                            'paginator'=>$paginator,
204
                                            'comment'=>$comment,
205
                                            'comment_count'=>$comment_count
206
                                        ]);
207
    }
208
}
209