Passed
Pull Request — master (#610)
by John
22:48
created

JudgeServer::oj()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Models\Eloquent;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Illuminate\Support\Facades\DB;
7
8
class JudgeServer extends Model
9
{
10
    protected $table='judge_server';
11
    protected $primaryKey='jsid';
12
13
    protected $fillable=[
14
        'scode', 'name', 'host', 'port', 'token', 'available', 'oid', 'usage', 'status', 'status_update_at'
15
    ];
16
17
    public static function column($key)
18
    {
19
        return Self::groupBy($key)->whereNotNull($key)->pluck($key)->toArray();
20
    }
21
22
    public function oj() {
23
        return $this->belongsTo('App\Models\Eloquent\OJ', 'oid', 'oid');
24
    }
25
26
    public static function boot()
27
    {
28
        parent::boot();
29
        static::saving(function($model) {
30
            $columns=$model->getDirty();
31
            foreach ($columns as $column => $newValue) {
32
                if ($column=="status") {
33
                    $model->status_update_at=now();
34
                    break;
35
                }
36
            }
37
        });
38
    }
39
}
40