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); |
|
|
|
|
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
|
|
|
|