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

JudgeServer   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 14
dl 0
loc 27
rs 10
c 1
b 0
f 1
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A oj() 0 2 1
A boot() 0 9 3
A column() 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
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