|
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 DELETED_AT=null; |
|
15
|
|
|
const UPDATED_AT="update_date"; |
|
16
|
|
|
const CREATED_AT=null; |
|
17
|
|
|
|
|
18
|
|
|
public function submissions() |
|
19
|
|
|
{ |
|
20
|
|
|
return $this->hasMany('App\Models\Eloquent\Submission','pid','pid'); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
public function problemSamples() |
|
24
|
|
|
{ |
|
25
|
|
|
return $this->hasMany('App\Models\Eloquent\ProblemSample','pid','pid'); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function getProblemStatusAttribute() |
|
29
|
|
|
{ |
|
30
|
|
|
if(Auth::check()){ |
|
31
|
|
|
$prob_status=(new OutdatedSubmissionModel())->getProblemStatus($this->pid, Auth::user()->id); |
|
32
|
|
|
if (empty($prob_status)) { |
|
33
|
|
|
return [ |
|
34
|
|
|
"icon"=>"checkbox-blank-circle-outline", |
|
35
|
|
|
"color"=>"wemd-grey-text" |
|
36
|
|
|
]; |
|
37
|
|
|
} else { |
|
38
|
|
|
return [ |
|
39
|
|
|
"icon"=>$prob_status["verdict"]=="Accepted" ? "checkbox-blank-circle" : "cisco-webex", |
|
40
|
|
|
"color"=>$prob_status["color"] |
|
41
|
|
|
]; |
|
42
|
|
|
} |
|
43
|
|
|
} else { |
|
44
|
|
|
return [ |
|
45
|
|
|
"icon"=>"checkbox-blank-circle-outline", |
|
46
|
|
|
"color"=>"wemd-grey-text" |
|
47
|
|
|
]; |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/* public function getSamplesAttribute() |
|
52
|
|
|
{ |
|
53
|
|
|
return array_map(function($sample) { |
|
54
|
|
|
return [ |
|
55
|
|
|
'sample_input' => $sample->sample_input, |
|
56
|
|
|
'sample_output' => $sample->sample_output, |
|
57
|
|
|
'sample_note' => $sample->sample_note, |
|
58
|
|
|
]; |
|
59
|
|
|
}, $this->problemSamples()->select('sample_input', 'sample_output', 'sample_note')->get()->all()); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function setSamplesAttribute($value) |
|
63
|
|
|
{ |
|
64
|
|
|
return; |
|
65
|
|
|
} */ |
|
66
|
|
|
} |
|
67
|
|
|
|