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\Project; |
13
|
|
|
|
14
|
|
|
use Illuminate\Database\Eloquent\Model as BaseModel; |
15
|
|
|
use Tinyissue\Model; |
16
|
|
|
use Tinyissue\Model\Traits\CountAttributeTrait; |
17
|
|
|
use Tinyissue\Model\Traits\Project\Issue\CountTrait; |
18
|
|
|
use Tinyissue\Model\Traits\Project\Issue\CrudTagTrait; |
19
|
|
|
use Tinyissue\Model\Traits\Project\Issue\CrudTrait; |
20
|
|
|
use Tinyissue\Model\Traits\Project\Issue\QueryTrait; |
21
|
|
|
use Tinyissue\Model\Traits\Project\Issue\QueueTrait; |
22
|
|
|
use Tinyissue\Model\Traits\Project\Issue\RelationTrait; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Issue is model class for project issues. |
26
|
|
|
* |
27
|
|
|
* @author Mohamed Alsharaf <[email protected]> |
28
|
|
|
* |
29
|
|
|
* @property int $id |
30
|
|
|
* @property int $created_by |
31
|
|
|
* @property int $project_id |
32
|
|
|
* @property string $title |
33
|
|
|
* @property string $body |
34
|
|
|
* @property int $assigned_to |
35
|
|
|
* @property int $time_quote |
36
|
|
|
* @property bool $lock_quote |
37
|
|
|
* @property int $closed_by |
38
|
|
|
* @property int $closed_at |
39
|
|
|
* @property int status |
40
|
|
|
* @property int $updated_at |
41
|
|
|
* @property int $updated_by |
42
|
|
|
* @property Model\Project $project |
43
|
|
|
* @property Model\User $user |
44
|
|
|
* @property Model\User $updatedBy |
45
|
|
|
*/ |
46
|
|
|
class Issue extends BaseModel |
47
|
|
|
{ |
48
|
|
|
use CountAttributeTrait, |
49
|
|
|
CountTrait, |
50
|
|
|
CrudTrait, |
51
|
|
|
CrudTagTrait, |
52
|
|
|
RelationTrait, |
53
|
|
|
QueryTrait, |
54
|
|
|
QueueTrait; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Issue status: Open. |
58
|
|
|
* |
59
|
|
|
* @var int |
60
|
|
|
*/ |
61
|
|
|
const STATUS_OPEN = 1; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Issue status: Closed. |
65
|
|
|
* |
66
|
|
|
* @var int |
67
|
|
|
*/ |
68
|
|
|
const STATUS_CLOSED = 0; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Timestamp enabled. |
72
|
|
|
* |
73
|
|
|
* @var bool |
74
|
|
|
*/ |
75
|
|
|
public $timestamps = true; |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Name of database table. |
79
|
|
|
* |
80
|
|
|
* @var string |
81
|
|
|
*/ |
82
|
|
|
protected $table = 'projects_issues'; |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* List of allowed columns to be used in $this->fill(). |
86
|
|
|
* |
87
|
|
|
* @var array |
88
|
|
|
*/ |
89
|
|
|
protected $fillable = ['created_by', 'project_id', 'title', 'body', 'assigned_to', 'time_quote', 'lock_quote']; |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Set attributes default value. |
93
|
|
|
* |
94
|
|
|
* @var array |
95
|
|
|
*/ |
96
|
|
|
protected $attributes = [ |
97
|
|
|
'status' => self::STATUS_OPEN, |
98
|
|
|
]; |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Returns the aggregate value of number of comments in an issue. |
102
|
|
|
* |
103
|
|
|
* @return int |
104
|
|
|
*/ |
105
|
6 |
|
public function getCountCommentsAttribute() |
106
|
|
|
{ |
107
|
6 |
|
return $this->getCountAttribute('countComments'); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Generate a URL for the active project. |
112
|
|
|
* |
113
|
|
|
* @param string $url |
114
|
|
|
* |
115
|
|
|
* @return string |
116
|
|
|
*/ |
117
|
29 |
|
public function to($url = '') |
118
|
|
|
{ |
119
|
29 |
|
return \URL::to('project/' . $this->project_id . '/issue/' . $this->id . (($url) ? '/' . $url : '')); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* Convert time quote from an array into seconds. |
124
|
|
|
* |
125
|
|
|
* @param array $value |
126
|
|
|
*/ |
127
|
31 |
|
public function setTimeQuoteAttribute($value) |
128
|
|
|
{ |
129
|
31 |
|
$seconds = $value; |
130
|
31 |
|
if (is_array($value)) { |
131
|
30 |
|
$seconds = 0; |
132
|
30 |
|
$seconds += isset($value['m']) ? ($value['m'] * 60) : 0; |
133
|
30 |
|
$seconds += isset($value['h']) ? ($value['h'] * 60 * 60) : 0; |
134
|
|
|
} |
135
|
31 |
|
$this->attributes['time_quote'] = (int) $seconds; |
136
|
31 |
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* Returns the color of tag status. |
140
|
|
|
* |
141
|
|
|
* @return string |
142
|
|
|
*/ |
143
|
|
|
public function getTypeColorAttribute() |
144
|
|
|
{ |
145
|
|
|
$tag = $this->tags->filter(function (Model\Tag $tag) { |
|
|
|
|
146
|
|
|
return $tag->parent->name === 'type'; |
147
|
|
|
})->first(); |
148
|
|
|
|
149
|
|
|
if ($tag) { |
150
|
|
|
return $tag->bgcolor; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
return null; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* Whether or not the issue is new. |
158
|
|
|
* |
159
|
|
|
* @return bool |
160
|
|
|
*/ |
161
|
|
|
public function isNew() |
162
|
|
|
{ |
163
|
|
|
if ($this->status === 0) { |
164
|
|
|
return false; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
return $this->tags->count() === 0; |
|
|
|
|
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* Whether or not the issue is open or closed. |
172
|
|
|
* |
173
|
|
|
* @return bool |
174
|
|
|
*/ |
175
|
25 |
|
public function isOpen() |
176
|
|
|
{ |
177
|
25 |
|
return (boolean) $this->status; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* Check if the issue contains a tag with option to set the issue as readonly to current user. |
182
|
|
|
* |
183
|
|
|
* @param Model\User $user |
184
|
|
|
* |
185
|
|
|
* @return bool |
186
|
|
|
*/ |
187
|
2 |
|
public function hasReadOnlyTag(Model\User $user) |
188
|
|
|
{ |
189
|
2 |
|
$hasReadOnly = $this->tags->where('readonly', $user->role_id); |
|
|
|
|
190
|
|
|
|
191
|
2 |
|
return !$hasReadOnly->isEmpty(); |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* Whether or not the issue quote is locked by manager. |
196
|
|
|
* |
197
|
|
|
* @return bool |
198
|
|
|
*/ |
199
|
|
|
public function isQuoteLocked() |
200
|
|
|
{ |
201
|
|
|
return (boolean) $this->lock_quote; |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
/** |
205
|
|
|
* Check if a user is allowed to see the issue quote. |
206
|
|
|
* |
207
|
|
|
* @param Model\User $user |
208
|
|
|
* |
209
|
|
|
* @return bool |
210
|
|
|
*/ |
211
|
|
|
public function canUserViewQuote(Model\User $user) |
212
|
|
|
{ |
213
|
|
|
if ($this->time_quote > 0 && |
214
|
|
|
(!$this->isQuoteLocked() || $user->permission(Model\Permission::PERM_ISSUE_VIEW_QUOTE)) |
215
|
|
|
) { |
216
|
|
|
return true; |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
return false; |
220
|
|
|
} |
221
|
|
|
} |
222
|
|
|
|
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.