Test Setup Failed
Push — master ( e2b9fb...698287 )
by
unknown
04:27
created

PTA::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
namespace App\Http\Controllers\VirtualJudge\PTA;
3
4
use App\Http\Controllers\VirtualJudge\Curl;
5
use App\Models\JudgerModel;
6
use App\Models\ProblemModel;
7
use App\Models\ResponseModel;
8
use App\Models\SubmissionModel;
9
use App\Models\CompilerModel;
10
use Illuminate\Support\Facades\Validator;
11
use Requests;
12
13
class PTA extends Curl
14
{
15
    protected $sub;
16
    public $post_data=[];
17
18
    public function __construct(& $sub, $all_data)
19
    {
20
        $this->sub=& $sub;
21
        $this->post_data=$all_data;
22
    }
23
24
    private function ojLogin()
25
    {
26
        // F**k capcha
27
    }
28
29
    private function submitSolution()
30
    {
31
        $compilerModel = new CompilerModel();
32
        $lang = $compilerModel->detail($this->post_data["coid"]);
33
        $pid = $this->post_data['iid'];
0 ignored issues
show
Unused Code introduced by
The assignment to $pid is dead and can be removed.
Loading history...
34
        $this->sub['language']=$lang['display_name'];
35
        $this->sub['solution']=$this->post_data["solution"];
36
        $this->sub['pid']=$this->post_data["pid"];
37
        $this->sub['coid']=$this->post_data["coid"];
38
        if (isset($this->post_data["contest"])) {
39
            $this->sub['cid']=$this->post_data["contest"];
40
        } else {
41
            $this->sub['cid']=null;
42
        }
43
44
        $response = $this->post_data("https://pintia.cn/api/problem-sets/{$this->post_data['cid']}/exams", null, 'pta', true, false, false, true);
45
46
        if (strpos($response, 'PROBLEM_SET_NOT_FOUND') !== false) {
47
            header('HTTP/1.1 404 Not Found');
48
            die();
49
        }
50
        $generalDetails=json_decode($response,true);
51
        $examId = $generalDetails['exam']['id'];
52
53
        $params = [
54
            'details' => [
55
                [
56
                    'problemSetProblemId' => $this->post_data['iid'],
57
                    'programmingSubmissionDetail' => [
58
                        'compiler' => $lang['lcode'],
59
                        'program' => $this->post_data["solution"]
60
                    ]
61
                ]
62
            ],
63
            'problemType' => 'PROGRAMMING'
64
        ];
65
66
        $response=$this->post_data("https://pintia.cn/api/problem-sets/$examId/submissions?exam_id=".$examId, $params, 'pta', true, false, false, true);
67
        $ret = json_decode($response, true);
68
        if (isset($ret['submissionId'])) {
69
            $this->sub['remote_id'] = $examId.'|'.$ret['submissionId'];
70
        } else {
71
            $this->sub['verdict'] = 'Submission Error';
72
        }
73
    }
74
75
    public function submit()
76
    {
77
        Validator::make($this->post_data, [
78
            'pid' => 'required|integer',
79
            'cid' => 'required|integer',
80
            'coid' => 'required|integer',
81
            'iid' => 'required|integer',
82
            'solution' => 'required',
83
        ])->validate();
84
85
        $this->ojLogin();
86
        $this->submitSolution();
87
    }
88
}
89