|
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
|
|
|
|