Completed
Push — master ( d7ee0c...02dfbd )
by Christopher
01:22
created

Task::assignToProject()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Chriscreates\Projects\Models;
4
5
use Chriscreates\Projects\Traits\HasPriority;
6
use Chriscreates\Projects\Traits\IsRecordable;
7
use Illuminate\Database\Eloquent\Model;
8
use Illuminate\Database\Eloquent\Relations\BelongsTo;
9
use Illuminate\Database\Eloquent\Relations\MorphMany;
10
use Illuminate\Database\Eloquent\Relations\MorphToMany;
11
12
class Task extends Model
13
{
14
    use IsRecordable, HasPriority;
15
16
    protected $table = 'tasks';
17
18
    public $primaryKey = 'id';
19
20
    public $guarded = ['id'];
21
22
    public $timestamps = true;
23
24
    protected $casts = [
25
        'complete' => 'bool',
26
    ];
27
28
    public function creator() : BelongsTo
29
    {
30
        return $this->belongsTo(get_class(user_model()));
31
    }
32
33
    public function priority() : BelongsTo
34
    {
35
        return $this->belongsTo(Priority::class);
36
    }
37
38
    public function projects() : MorphToMany
39
    {
40
        return $this->morphToMany(Project::class, 'projectable');
41
    }
42
43
    public function records() : MorphMany
44
    {
45
        return $this->morphMany(Record::class, 'recordable');
46
    }
47
48
    public function assignToProject(Project $project) : void
49
    {
50
        $this->projects()->save($project);
51
52
        $this->refresh();
53
    }
54
55
    public function markCompletion(bool $bool) : void
56
    {
57
        $this->update(['complete' => $bool]);
58
    }
59
60
    public function completed() : bool
61
    {
62
        return $this->attributes['complete'];
63
    }
64
}
65