Passed
Pull Request — master (#648)
by John
06:12
created

Problem   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 2
Bugs 1 Features 1
Metric Value
eloc 22
c 2
b 1
f 1
dl 0
loc 45
rs 10
wmc 8

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getReadableNameAttribute() 0 3 1
A submissions() 0 3 1
A problemSamples() 0 3 1
A getProblemStatusAttribute() 0 19 4
A onlinejudge() 0 3 1
1
<?php
2
3
namespace App\Models\Eloquent;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Illuminate\Support\Facades\DB;
7
use App\Models\Submission\SubmissionModel as OutdatedSubmissionModel;
8
use Auth;
9
10
class Problem extends Model
11
{
12
    protected $table='problem';
13
    protected $primaryKey='pid';
14
    const UPDATED_AT="update_date";
15
16
    public function getReadableNameAttribute()
17
    {
18
        return $this->pcode.'. '.$this->title;
19
    }
20
21
    public function submissions()
22
    {
23
        return $this->hasMany('App\Models\Eloquent\Submission', 'pid', 'pid');
24
    }
25
26
    public function problemSamples()
27
    {
28
        return $this->hasMany('App\Models\Eloquent\ProblemSample', 'pid', 'pid');
29
    }
30
31
    public function onlinejudge()
32
    {
33
        return $this->belongsTo('App\Models\Eloquent\OJ', 'OJ', 'oid');
34
    }
35
36
    public function getProblemStatusAttribute()
37
    {
38
        if (Auth::check()) {
39
            $prob_status=(new OutdatedSubmissionModel())->getProblemStatus($this->pid, Auth::user()->id);
0 ignored issues
show
Bug introduced by
Accessing id on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
40
            if (empty($prob_status)) {
41
                return [
42
                    "icon"=>"checkbox-blank-circle-outline",
43
                    "color"=>"wemd-grey-text"
44
                ];
45
            } else {
46
                return [
47
                    "icon"=>$prob_status["verdict"]=="Accepted" ? "checkbox-blank-circle" : "cisco-webex",
48
                    "color"=>$prob_status["color"]
49
                ];
50
            }
51
        } else {
52
            return [
53
                "icon"=>"checkbox-blank-circle-outline",
54
                "color"=>"wemd-grey-text"
55
            ];
56
        }
57
    }
58
59
/*     public function getSamplesAttribute()
60
    {
61
        return array_map(function($sample) {
62
            return [
63
                'sample_input' => $sample->sample_input,
64
                'sample_output' => $sample->sample_output,
65
                'sample_note' => $sample->sample_note,
66
            ];
67
        }, $this->problemSamples()->select('sample_input', 'sample_output', 'sample_note')->get()->all());
68
    }
69
70
    public function setSamplesAttribute($value)
71
    {
72
        return;
73
    } */
74
}
75