Completed
Push — master ( c8be31...6ec074 )
by Renato
02:42
created

Issue::attachments()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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
9
namespace GitScrum\Models;
10
11
use Illuminate\Database\Eloquent\Model;
12
use Illuminate\Database\Eloquent\SoftDeletes;
13
use Carbon\Carbon;
14
15
class Issue extends Model
16
{
17
    use SoftDeletes;
18
19
    /**
20
     * The database table used by the model.
21
     *
22
     * @var string
23
     */
24
    protected $table = 'issues';
25
26
    /**
27
     * Attributes that should be mass-assignable.
28
     *
29
     * @var array
30
     */
31
    protected $fillable = ['config_issue_effort_id', 'issue_type_id', 'github_id', 'user_id', 'product_backlog_id',
32
        'branch_id', 'sprint_id', 'user_story_id', 'number', 'effort', 'slug', 'code', 'title', 'description', 'state',
33
        'config_status_id', 'position', 'is_planning_poker', 'closed_user_id', 'closed_at', ];
34
35
    /**
36
     * The attributes excluded from the model's JSON form.
37
     *
38
     * @var array
39
     */
40
    protected $hidden = [];
41
42
    /**
43
     * The attributes that should be casted to native types.
44
     *
45
     * @var array
46
     */
47
    protected $casts = [];
48
49
    protected $dates = ['deleted_at'];
50
51
    protected static function boot()
52
    {
53
        parent::boot();
54
    }
55
56
    public function branch()
57
    {
58
        return $this->belongsTo(\GitScrum\Models\Branch::class, 'branch_id', 'id');
59
    }
60
61
    public function type()
62
    {
63
        return $this->belongsTo(\GitScrum\Models\IssueType::class, 'issue_type_id', 'id');
64
    }
65
66
    public function configEffort()
67
    {
68
        return $this->belongsTo(\GitScrum\Models\ConfigIssueEffort::class, 'config_issue_effort_id', 'id');
69
    }
70
71
    public function sprint()
72
    {
73
        return $this->belongsTo(\GitScrum\Models\Sprint::class, 'sprint_id', 'id');
74
    }
75
76
    public function productBacklog()
77
    {
78
        return $this->belongsTo(\GitScrum\Models\ProductBacklog::class, 'product_backlog_id', 'id');
79
    }
80
81
    public function userStory()
82
    {
83
        return $this->belongsTo(\GitScrum\Models\UserStory::class, 'user_story_id', 'id');
84
    }
85
86
    public function user()
87
    {
88
        return $this->belongsTo(\GitScrum\Models\User::class, 'user_id', 'id');
89
    }
90
91
    public function closedUser()
92
    {
93
        return $this->belongsTo(\GitScrum\Models\User::class, 'closed_user_id', 'id');
94
    }
95
96
    public function users()
97
    {
98
        return $this->belongsToMany(\GitScrum\Models\User::class, 'issues_has_users', 'issue_id', 'user_id')->withTimestamps();
99
    }
100
101
    public function commits()
102
    {
103
        return $this->hasMany(\GitScrum\Models\Commit::class, 'issue_id', 'id');
104
    }
105
106
    public function comments()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

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 @return annotation as described here.

Loading history...
107
    {
108
        return $this->morphMany(\GitScrum\Models\Comment::class, 'commentable')
109
            ->orderby('created_at', 'DESC');
110
    }
111
112
    public function attachments()
113
    {
114
        return $this->morphMany(\GitScrum\Models\Attachment::class, 'attachmentable');
115
    }
116
117
    public function notes()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

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 @return annotation as described here.

Loading history...
118
    {
119
        return $this->morphMany(\GitScrum\Models\Note::class, 'noteable')
120
            ->orderby('position', 'ASC');
121
    }
122
123
    public function favorite()
124
    {
125
        return $this->morphOne(\GitScrum\Models\Favorite::class, 'favoriteable');
126
    }
127
128
    public function labels()
129
    {
130
        return $this->morphToMany(\GitScrum\Models\Label::class, 'labelable');
131
    }
132
133
    public function status()
134
    {
135
        return $this->hasOne(\GitScrum\Models\ConfigStatus::class, 'id', 'config_status_id');
136
    }
137
138
    public function statuses()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

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 @return annotation as described here.

Loading history...
139
    {
140
        return $this->morphMany(\GitScrum\Models\Status::class, 'statusesable')
141
            ->orderby('created_at', 'DESC');
142
    }
143
144
    public function dateForHumans($dateField = 'created_at')
145
    {
146
        return Carbon::createFromFormat('Y-m-d H:i:s', $this->attributes[$dateField])->diffForHumans();
147
    }
148
149
    public function getNumberAttribute()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

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 @return annotation as described here.

Loading history...
150
    {
151
        return isset($this->attributes['number']) ? $this->attributes['number'] : null;
152
    }
153
}
154