Completed
Pull Request — master (#83)
by D.
10:45 queued 08:12
created

Training::trainingType()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace SET;
4
5
use Illuminate\Database\Eloquent\Model;
6
7
class Training extends Model
8
{
9
    protected $table = 'trainings';
10
    public $timestamps = true;
11
12
    protected $fillable = ['name', 'renews_in', 'description', 'administrative', 'training_type_id'];
13
    protected $dates = ['created_at', 'updated_at'];
14
    protected $appends = ['incompleted'];
15
16 43
    public function assignedUsers()
17
    {
18 43
        return $this->hasMany('SET\TrainingUser', 'training_id');
19
    }
20
21 20
    public function users()
22
    {
23 20
        return $this->belongsToMany('SET\User');
24
    }
25
26
    public function groups()
27
    {
28
        return $this->belongsToMany('SET\Group');
29
    }
30
31 4
    public function attachments()
32
    {
33 4
        return $this->morphMany('SET\Attachment', 'imageable');
34
    }
35
36 2
    public function getIncompletedAttribute()
37
    {
38 2
        return $this->users()
39 2
            ->whereNull('training_user.completed_date')
40 2
            ->active()
41 2
            ->count();
42
    }
43
44
    /**
45
     * @param $query
46
     * @param $input
47
     */
48 3
    public function scopeSearchTraining($query, $input)
49
    {
50 3
        return $query->where('name', 'LIKE', "%$input%");
51
    }
52
53
    /**
54
     * Get the training type for the training.
55
     */
56 2
    public function trainingType()
57
    {
58 2
        return $this->belongsTo('SET\TrainingType', 'training_type_id'); // One To Many (Inverse)
59
    }
60
}
61