|
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\CrudTrait; |
|
19
|
|
|
use Tinyissue\Model\Traits\Project\Issue\CrudTagTrait; |
|
20
|
|
|
use Tinyissue\Model\Traits\Project\Issue\RelationTrait; |
|
21
|
|
|
use Tinyissue\Model\Traits\Project\Issue\QueryTrait; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Issue is model class for project issues. |
|
25
|
|
|
* |
|
26
|
|
|
* @author Mohamed Alsharaf <[email protected]> |
|
27
|
|
|
* |
|
28
|
|
|
* @property int $id |
|
29
|
|
|
* @property int $created_by |
|
30
|
|
|
* @property int $project_id |
|
31
|
|
|
* @property string $title |
|
32
|
|
|
* @property string $body |
|
33
|
|
|
* @property int $assigned_to |
|
34
|
|
|
* @property int $time_quote |
|
35
|
|
|
* @property int $closed_by |
|
36
|
|
|
* @property int $closed_at |
|
37
|
|
|
* @property int status |
|
38
|
|
|
* @property int $updated_at |
|
39
|
|
|
* @property int $updated_by |
|
40
|
|
|
* @property Model\Project $project |
|
41
|
|
|
* @property Model\User $user |
|
42
|
|
|
* @property Model\User $updatedBy |
|
43
|
|
|
*/ |
|
44
|
|
|
class Issue extends BaseModel |
|
45
|
|
|
{ |
|
46
|
|
|
use CountAttributeTrait, |
|
47
|
|
|
CountTrait, |
|
48
|
|
|
CrudTrait, |
|
49
|
|
|
CrudTagTrait, |
|
50
|
|
|
RelationTrait, |
|
51
|
|
|
QueryTrait; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Issue status: Open. |
|
55
|
|
|
* |
|
56
|
|
|
* @var int |
|
57
|
|
|
*/ |
|
58
|
|
|
const STATUS_OPEN = 1; |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Issue status: Closed. |
|
62
|
|
|
* |
|
63
|
|
|
* @var int |
|
64
|
|
|
*/ |
|
65
|
|
|
const STATUS_CLOSED = 0; |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Timestamp enabled. |
|
69
|
|
|
* |
|
70
|
|
|
* @var bool |
|
71
|
|
|
*/ |
|
72
|
|
|
public $timestamps = true; |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Name of database table. |
|
76
|
|
|
* |
|
77
|
|
|
* @var string |
|
78
|
|
|
*/ |
|
79
|
|
|
protected $table = 'projects_issues'; |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* List of allowed columns to be used in $this->fill(). |
|
83
|
|
|
* |
|
84
|
|
|
* @var array |
|
85
|
|
|
*/ |
|
86
|
|
|
protected $fillable = ['created_by', 'project_id', 'title', 'body', 'assigned_to', 'time_quote']; |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Returns the aggregate value of number of comments in an issue. |
|
90
|
|
|
* |
|
91
|
|
|
* @return int |
|
92
|
|
|
*/ |
|
93
|
6 |
|
public function getCountCommentsAttribute() |
|
94
|
|
|
{ |
|
95
|
6 |
|
return $this->getCountAttribute('countComments'); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* Generate a URL for the active project. |
|
100
|
|
|
* |
|
101
|
|
|
* @param string $url |
|
102
|
|
|
* |
|
103
|
|
|
* @return string |
|
104
|
|
|
*/ |
|
105
|
25 |
|
public function to($url = '') |
|
106
|
|
|
{ |
|
107
|
25 |
|
return \URL::to('project/' . $this->project_id . '/issue/' . $this->id . (($url) ? '/' . $url : '')); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* Convert time quote from an array into seconds. |
|
112
|
|
|
* |
|
113
|
|
|
* @param array $value |
|
114
|
|
|
*/ |
|
115
|
27 |
|
public function setTimeQuoteAttribute($value) |
|
116
|
|
|
{ |
|
117
|
27 |
|
$seconds = $value; |
|
118
|
27 |
|
if (is_array($value)) { |
|
119
|
26 |
|
$seconds = 0; |
|
120
|
26 |
|
$seconds += isset($value['m']) ? ($value['m'] * 60) : 0; |
|
121
|
26 |
|
$seconds += isset($value['h']) ? ($value['h'] * 60 * 60) : 0; |
|
122
|
|
|
} |
|
123
|
27 |
|
$this->attributes['time_quote'] = (int) $seconds; |
|
124
|
27 |
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* Returns the color of tag status. |
|
128
|
|
|
* |
|
129
|
|
|
* @return string |
|
130
|
|
|
*/ |
|
131
|
|
|
public function getTypeColorAttribute() |
|
132
|
|
|
{ |
|
133
|
|
|
$tag = $this->tags->filter(function (Model\Tag $tag) { |
|
|
|
|
|
|
134
|
|
|
return $tag->parent->name === 'type'; |
|
135
|
|
|
})->first(); |
|
136
|
|
|
|
|
137
|
|
|
if ($tag) { |
|
138
|
|
|
return $tag->bgcolor; |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
return null; |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
/** |
|
145
|
|
|
* Whether or not the issue is open or closed |
|
146
|
|
|
* |
|
147
|
|
|
* @return bool |
|
148
|
|
|
*/ |
|
149
|
16 |
|
public function isOpen() |
|
150
|
|
|
{ |
|
151
|
16 |
|
return (bool)$this->status; |
|
152
|
|
|
} |
|
153
|
|
|
} |
|
154
|
|
|
|
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@propertyannotation 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.