1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Tinyissue package. |
5
|
|
|
* |
6
|
|
|
* (c) Mohamed Alsharaf <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Tinyissue\Model\Traits\Project\Issue; |
13
|
|
|
|
14
|
|
|
use Illuminate\Database\Eloquent\Builder; |
15
|
|
|
use Illuminate\Database\Eloquent\Relations; |
16
|
|
|
use Tinyissue\Model; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* RelationTrait is trait class containing the relationship methods for the Project\Issue model. |
20
|
|
|
* |
21
|
|
|
* @author Mohamed Alsharaf <[email protected]> |
22
|
|
|
* |
23
|
|
|
* @method Relations\HasMany hasMany($related, $foreignKey = null, $localKey = null) |
24
|
|
|
* @method Relations\BelongsToMany belongsToMany($related, $table = null, $foreignKey = null, $otherKey = null, $relation = null) |
25
|
|
|
* @method Relations\BelongsTo belongsTo($related, $foreignKey = null, $otherKey = null, $relation = null) |
26
|
|
|
*/ |
27
|
|
|
trait RelationTrait |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* An issue has one user assigned to (inverse relationship of User::issues). |
31
|
|
|
* |
32
|
|
|
* @return Relations\BelongsTo |
33
|
|
|
*/ |
34
|
13 |
|
public function assigned() |
35
|
|
|
{ |
36
|
13 |
|
return $this->belongsTo('Tinyissue\Model\User', 'assigned_to'); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* An issue has one user updated by (inverse relationship of User::issuesUpdatedBy). |
41
|
|
|
* |
42
|
|
|
* @return Relations\BelongsTo |
43
|
|
|
*/ |
44
|
6 |
|
public function updatedBy() |
45
|
|
|
{ |
46
|
6 |
|
return $this->belongsTo('Tinyissue\Model\User', 'updated_by'); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* An issue has one user closed it (inverse relationship of User::issuesClosedBy). |
51
|
|
|
* |
52
|
|
|
* @return Relations\BelongsTo |
53
|
|
|
*/ |
54
|
|
|
public function closer() |
55
|
|
|
{ |
56
|
|
|
return $this->belongsTo('Tinyissue\Model\User', 'closed_by'); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* An issue has one user created it (inverse relationship of User::issuesCreatedBy). |
61
|
|
|
* |
62
|
|
|
* @return Relations\BelongsTo |
63
|
|
|
*/ |
64
|
21 |
|
public function user() |
65
|
|
|
{ |
66
|
21 |
|
return $this->belongsTo('Tinyissue\Model\User', 'created_by'); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Issue belong to a project. |
71
|
|
|
* |
72
|
|
|
* @return Relations\BelongsTo |
73
|
|
|
*/ |
74
|
2 |
|
public function project() |
75
|
|
|
{ |
76
|
2 |
|
return $this->belongsTo('Tinyissue\Model\Project'); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Issue can have many attachments. |
81
|
|
|
* |
82
|
|
|
* @return Relations\HasMany |
83
|
|
|
*/ |
84
|
18 |
|
public function attachments() |
85
|
|
|
{ |
86
|
|
|
return $this |
87
|
18 |
|
->hasMany('Tinyissue\Model\Project\Issue\Attachment', 'issue_id') |
88
|
18 |
|
->where(function (Builder $query) { |
89
|
18 |
|
$query->where('comment_id', '=', 0); |
90
|
18 |
|
$query->orWhere('comment_id', '=', null); |
91
|
18 |
|
}); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Issue have many users activities. |
96
|
|
|
* |
97
|
|
|
* @return Relations\HasMany |
98
|
|
|
*/ |
99
|
28 |
|
public function activities() |
100
|
|
|
{ |
101
|
|
|
return $this |
102
|
28 |
|
->hasMany('Tinyissue\Model\User\Activity', 'item_id') |
103
|
28 |
|
->orderBy('created_at', 'ASC'); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Issue have many users activities (all except comments). |
108
|
|
|
* |
109
|
|
|
* @return mixed |
110
|
|
|
*/ |
111
|
1 |
|
public function generalActivities() |
112
|
|
|
{ |
113
|
|
|
return $this |
114
|
1 |
|
->hasMany('Tinyissue\Model\User\Activity', 'item_id') |
115
|
1 |
|
->whereNotIn('type_id', [Model\Activity::TYPE_COMMENT]) |
116
|
1 |
|
->orderBy('created_at', 'ASC'); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Issue have many users activities (comments). |
121
|
|
|
* |
122
|
|
|
* @return mixed |
123
|
|
|
*/ |
124
|
8 |
|
public function commentActivities() |
125
|
|
|
{ |
126
|
|
|
return $this |
127
|
8 |
|
->hasMany('Tinyissue\Model\User\Activity', 'item_id') |
128
|
8 |
|
->whereIn('type_id', [Model\Activity::TYPE_COMMENT]) |
129
|
8 |
|
->orderBy('created_at', 'ASC'); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* Issue have many tags. |
134
|
|
|
* |
135
|
|
|
* @return Relations\BelongsToMany |
136
|
|
|
*/ |
137
|
28 |
|
public function tags() |
138
|
|
|
{ |
139
|
28 |
|
return $this->belongsToMany('Tinyissue\Model\Tag', 'projects_issues_tags', 'issue_id', 'tag_id'); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* Issue have many comments. |
144
|
|
|
* |
145
|
|
|
* @return Relations\HasMany |
146
|
|
|
*/ |
147
|
3 |
|
public function comments() |
148
|
|
|
{ |
149
|
|
|
return $this |
150
|
3 |
|
->hasMany('Tinyissue\Model\Project\Issue\Comment', 'issue_id') |
151
|
3 |
|
->orderBy('created_at', 'ASC'); |
152
|
|
|
} |
153
|
|
|
} |
154
|
|
|
|