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; |
13
|
|
|
|
14
|
|
|
use Illuminate\Database\Eloquent\Model; |
15
|
|
|
use URL; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Project is model class for projects. |
19
|
|
|
* |
20
|
|
|
* @author Mohamed Alsharaf <[email protected]> |
21
|
|
|
* |
22
|
|
|
* @property int $id |
23
|
|
|
* @property string $name |
24
|
|
|
* @property int $status |
25
|
|
|
* @property int $default_assignee |
26
|
|
|
* @property Project\Issue[] $issues |
27
|
|
|
* @property int $openIssuesCount |
28
|
|
|
* @property int $closedIssuesCount |
29
|
|
|
*/ |
30
|
|
|
class Project extends Model |
31
|
|
|
{ |
32
|
|
|
use Traits\CountAttributeTrait, |
33
|
|
|
Traits\Project\CountTrait, |
34
|
|
|
Traits\Project\FilterTrait, |
35
|
|
|
Traits\Project\SortTrait, |
36
|
|
|
Traits\Project\RelationTrait, |
37
|
|
|
Traits\Project\CrudTrait, |
38
|
|
|
Traits\Project\QueryTrait; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Project not public to view and create issue. |
42
|
|
|
* |
43
|
|
|
* @var int |
44
|
|
|
*/ |
45
|
|
|
const PRIVATE_YES = 1; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Project public to view and create issue. |
49
|
|
|
* |
50
|
|
|
* @var int |
51
|
|
|
*/ |
52
|
|
|
const PRIVATE_NO = 0; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* All projects. |
56
|
|
|
* |
57
|
|
|
* @var int |
58
|
|
|
*/ |
59
|
|
|
const PRIVATE_ALL = -1; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Project status Open. |
63
|
|
|
* |
64
|
|
|
* @var int |
65
|
|
|
*/ |
66
|
|
|
const STATUS_OPEN = 1; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Project status Archived. |
70
|
|
|
* |
71
|
|
|
* @var int |
72
|
|
|
*/ |
73
|
|
|
const STATUS_ARCHIVED = 0; |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Timestamp enabled. |
77
|
|
|
* |
78
|
|
|
* @var bool |
79
|
|
|
*/ |
80
|
|
|
public $timestamps = true; |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Name of database table. |
84
|
|
|
* |
85
|
|
|
* @var string |
86
|
|
|
*/ |
87
|
|
|
protected $table = 'projects'; |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* List of allowed columns to be used in $this->fill(). |
91
|
|
|
* |
92
|
|
|
* @var array |
93
|
|
|
*/ |
94
|
|
|
protected $fillable = ['name', 'default_assignee', 'status', 'private']; |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Generate a URL for the active project. |
98
|
|
|
* |
99
|
|
|
* @param string $url |
100
|
|
|
* |
101
|
|
|
* @return string |
102
|
|
|
*/ |
103
|
42 |
|
public function to($url = '') |
104
|
|
|
{ |
105
|
42 |
|
return URL::to('project/' . $this->id . (($url) ? '/' . $url : '')); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Returns the aggregate value of number of open issues in the project. |
110
|
|
|
* |
111
|
|
|
* @return int |
112
|
|
|
*/ |
113
|
5 |
|
public function getOpenIssuesCountAttribute() |
114
|
|
|
{ |
115
|
5 |
|
return $this->getCountAttribute('openIssuesCount'); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Returns the aggregate value of number of closed issues in the project. |
120
|
|
|
* |
121
|
|
|
* @return int |
122
|
|
|
*/ |
123
|
1 |
|
public function getClosedIssuesCountAttribute() |
124
|
|
|
{ |
125
|
1 |
|
return $this->getCountAttribute('closedIssuesCount'); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* Set default assignee attribute. |
130
|
|
|
* |
131
|
|
|
* @param int $value |
132
|
|
|
* |
133
|
|
|
* @return $this |
134
|
|
|
*/ |
135
|
46 |
|
public function setDefaultAssigneeAttribute($value) |
136
|
|
|
{ |
137
|
46 |
|
if (!empty($value)) { |
138
|
28 |
|
$this->attributes['default_assignee'] = (int) $value; |
139
|
|
|
} |
140
|
|
|
|
141
|
46 |
|
return $this; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* Returns the aggregate value of number of issues in the project. |
146
|
|
|
* |
147
|
|
|
* @return int |
148
|
|
|
*/ |
149
|
|
|
public function getIssuesCountAttribute() |
150
|
|
|
{ |
151
|
|
|
return $this->getCountAttribute('issuesCount'); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* Get total issues total quote time. |
156
|
|
|
* |
157
|
|
|
* @return int |
158
|
|
|
*/ |
159
|
3 |
|
public function getTotalQuote() |
160
|
|
|
{ |
161
|
3 |
|
$total = 0; |
162
|
3 |
|
foreach ($this->issues as $issue) { |
163
|
3 |
|
$total += $issue->time_quote; |
164
|
|
|
} |
165
|
|
|
|
166
|
3 |
|
return $total; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* Calculate the progress (open & closed issues). |
171
|
|
|
* |
172
|
|
|
* @return float|int |
173
|
|
|
*/ |
174
|
1 |
|
public function getProgress() |
175
|
|
|
{ |
176
|
1 |
|
$total = $this->openIssuesCount + $this->closedIssuesCount; |
177
|
1 |
|
$progress = 100; |
178
|
1 |
|
if ($total > 0) { |
179
|
1 |
|
$progress = (float) ($this->closedIssuesCount / $total) * 100; |
180
|
|
|
} |
181
|
1 |
|
$progressInt = (int) $progress; |
182
|
1 |
|
if ($progressInt > 0) { |
183
|
1 |
|
$progress = number_format($progress, 2); |
184
|
1 |
|
$fraction = $progress - $progressInt; |
185
|
1 |
|
if ($fraction === 0.0) { |
186
|
1 |
|
$progress = $progressInt; |
187
|
|
|
} |
188
|
|
|
} |
189
|
|
|
|
190
|
1 |
|
return $progress; |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* Whether or not a user is member of the project. |
195
|
|
|
* |
196
|
|
|
* @param int $userId |
197
|
|
|
* |
198
|
|
|
* @return bool |
199
|
|
|
*/ |
200
|
8 |
|
public function isMember($userId) |
201
|
|
|
{ |
202
|
8 |
|
return $this->user($userId)->count() > 0; |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
/** |
206
|
|
|
* Whether or not the project is private or public. |
207
|
|
|
* |
208
|
|
|
* @return bool |
209
|
|
|
*/ |
210
|
1 |
|
public function isPrivate() |
211
|
|
|
{ |
212
|
1 |
|
return $this->private === true; |
|
|
|
|
213
|
|
|
} |
214
|
|
|
} |
215
|
|
|
|
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.