|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* GitScrum v0.1. |
|
4
|
|
|
* |
|
5
|
|
|
* @author Renato Marinho <[email protected]> |
|
6
|
|
|
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 |
|
7
|
|
|
*/ |
|
8
|
|
|
namespace GitScrum\Models; |
|
9
|
|
|
|
|
10
|
|
|
use Illuminate\Database\Eloquent\Model; |
|
11
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes; |
|
12
|
|
|
|
|
13
|
|
|
class Note extends Model |
|
14
|
|
|
{ |
|
15
|
|
|
use SoftDeletes; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* The database table used by the model. |
|
19
|
|
|
* |
|
20
|
|
|
* @var string |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $table = 'notes'; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Attributes that should be mass-assignable. |
|
26
|
|
|
* |
|
27
|
|
|
* @var array |
|
28
|
|
|
*/ |
|
29
|
|
|
protected $fillable = ['noteable_type', 'noteable_id', 'user_id', |
|
30
|
|
|
'slug', 'title', 'position', 'closed_at', ]; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* The attributes excluded from the model's JSON form. |
|
34
|
|
|
* |
|
35
|
|
|
* @var array |
|
36
|
|
|
*/ |
|
37
|
|
|
protected $hidden = []; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* The attributes that should be casted to native types. |
|
41
|
|
|
* |
|
42
|
|
|
* @var array |
|
43
|
|
|
*/ |
|
44
|
|
|
protected $casts = []; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* The attributes that should be mutated to dates. |
|
48
|
|
|
* |
|
49
|
|
|
* @var array |
|
50
|
|
|
*/ |
|
51
|
|
|
protected $dates = ['deleted_at']; |
|
52
|
|
|
|
|
53
|
|
|
protected static function boot() |
|
54
|
|
|
{ |
|
55
|
|
|
parent::boot(); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function noteable() |
|
59
|
|
|
{ |
|
60
|
|
|
return $this->morphTo('noteable'); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function statuses() |
|
|
|
|
|
|
64
|
|
|
{ |
|
65
|
|
|
return $this->morphMany(\GitScrum\Models\Status::class, 'statusesable') |
|
66
|
|
|
->orderby('created_at', 'DESC'); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function closedUser() |
|
70
|
|
|
{ |
|
71
|
|
|
return $this->belongsTo(\GitScrum\Models\User::class, 'closed_user_id', 'id'); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function getConfigStatusIdAttribute() |
|
|
|
|
|
|
75
|
|
|
{ |
|
76
|
|
|
return ConfigStatus::where('type', '=', 'note') |
|
77
|
|
|
->where('default', '=', 1)->first()->id; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
public function setClosedUserIdAttribute($value) |
|
81
|
|
|
{ |
|
82
|
|
|
$this->attributes['closed_user_id'] = is_null($this->closed_at) ? $value : null; |
|
|
|
|
|
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
public function setClosedAtAttribute($value) |
|
86
|
|
|
{ |
|
87
|
|
|
$this->attributes['closed_at'] = is_null($this->closed_at) ? $value : null; |
|
|
|
|
|
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@returnannotation as described here.