1 | <?php |
||
31 | class Project extends Model |
||
32 | { |
||
33 | use Traits\CountAttributeTrait, |
||
34 | Traits\Project\CountTrait, |
||
35 | Traits\Project\FilterTrait, |
||
36 | Traits\Project\SortTrait, |
||
37 | Traits\Project\RelationTrait, |
||
38 | Traits\Project\CrudTrait, |
||
39 | Traits\Project\QueryTrait; |
||
40 | |||
41 | /** |
||
42 | * Project private & user role can see their own issues only. |
||
43 | * |
||
44 | * @var int |
||
45 | */ |
||
46 | const INTERNAL_YES = 2; |
||
47 | |||
48 | /** |
||
49 | * Project not public to view and create issue. |
||
50 | * |
||
51 | * @var int |
||
52 | */ |
||
53 | const PRIVATE_YES = 1; |
||
54 | |||
55 | /** |
||
56 | * Project public to view and create issue. |
||
57 | * |
||
58 | * @var int |
||
59 | */ |
||
60 | const PRIVATE_NO = 0; |
||
61 | |||
62 | /** |
||
63 | * All projects. |
||
64 | * |
||
65 | * @var int |
||
66 | */ |
||
67 | const PRIVATE_ALL = -1; |
||
68 | |||
69 | /** |
||
70 | * Project status Open. |
||
71 | * |
||
72 | * @var int |
||
73 | */ |
||
74 | const STATUS_OPEN = 1; |
||
75 | |||
76 | /** |
||
77 | * Project status Archived. |
||
78 | * |
||
79 | * @var int |
||
80 | */ |
||
81 | const STATUS_ARCHIVED = 0; |
||
82 | |||
83 | /** |
||
84 | * Timestamp enabled. |
||
85 | * |
||
86 | * @var bool |
||
87 | */ |
||
88 | public $timestamps = true; |
||
89 | |||
90 | /** |
||
91 | * Name of database table. |
||
92 | * |
||
93 | * @var string |
||
94 | */ |
||
95 | protected $table = 'projects'; |
||
96 | |||
97 | /** |
||
98 | * List of allowed columns to be used in $this->fill(). |
||
99 | * |
||
100 | * @var array |
||
101 | */ |
||
102 | protected $fillable = ['name', 'default_assignee', 'status', 'private']; |
||
103 | |||
104 | /** |
||
105 | * List of HTML classes for each status. |
||
106 | * |
||
107 | * @var array |
||
108 | */ |
||
109 | protected $attrClassNames = [ |
||
110 | self::PRIVATE_NO => 'note', |
||
111 | self::PRIVATE_YES => 'info', |
||
112 | self::INTERNAL_YES => 'primary', |
||
113 | ]; |
||
114 | |||
115 | /** |
||
116 | * List of statuses names. |
||
117 | * |
||
118 | * @var array |
||
119 | */ |
||
120 | protected $statusesNames = [ |
||
121 | self::PRIVATE_NO => 'public', |
||
122 | self::PRIVATE_YES => 'private', |
||
123 | self::INTERNAL_YES => 'internal', |
||
124 | ]; |
||
125 | |||
126 | /** |
||
127 | * Generate a URL for the active project. |
||
128 | * |
||
129 | * @param string $url |
||
130 | * |
||
131 | * @return string |
||
132 | */ |
||
133 | 38 | public function to($url = '') |
|
137 | |||
138 | /** |
||
139 | * Returns the aggregate value of number of open issues in the project. |
||
140 | * |
||
141 | * @return int |
||
142 | */ |
||
143 | 4 | public function getOpenIssuesCountAttribute() |
|
147 | |||
148 | /** |
||
149 | * Returns the aggregate value of number of closed issues in the project. |
||
150 | * |
||
151 | * @return int |
||
152 | */ |
||
153 | 1 | public function getClosedIssuesCountAttribute() |
|
157 | |||
158 | /** |
||
159 | * Set default assignee attribute. |
||
160 | * |
||
161 | * @param int $value |
||
162 | * |
||
163 | * @return $this |
||
164 | */ |
||
165 | 50 | public function setDefaultAssigneeAttribute($value) |
|
173 | |||
174 | /** |
||
175 | * Returns the aggregate value of number of issues in the project. |
||
176 | * |
||
177 | * @return int |
||
178 | */ |
||
179 | public function getIssuesCountAttribute() |
||
183 | |||
184 | /** |
||
185 | * Get total issues total quote time. |
||
186 | * |
||
187 | * @return int |
||
188 | */ |
||
189 | 3 | public function getTotalQuote() |
|
198 | |||
199 | /** |
||
200 | * Calculate the progress (open & closed issues). |
||
201 | * |
||
202 | * @return float|int |
||
203 | */ |
||
204 | 1 | public function getProgress() |
|
205 | { |
||
206 | 1 | $total = $this->openIssuesCount + $this->closedIssuesCount; |
|
207 | 1 | $progress = 100; |
|
208 | 1 | if ($total > 0) { |
|
209 | 1 | $progress = (float) ($this->closedIssuesCount / $total) * 100; |
|
210 | } |
||
211 | 1 | $progressInt = (int) $progress; |
|
212 | 1 | if ($progressInt > 0) { |
|
213 | 1 | $progress = number_format($progress, 2); |
|
214 | 1 | $fraction = $progress - $progressInt; |
|
215 | 1 | if ($fraction === 0.0) { |
|
216 | 1 | $progress = $progressInt; |
|
217 | } |
||
218 | } |
||
219 | |||
220 | 1 | return $progress; |
|
221 | } |
||
222 | |||
223 | /** |
||
224 | * Whether or not a user is member of the project. |
||
225 | * |
||
226 | * @param int $userId |
||
227 | * |
||
228 | * @return bool |
||
229 | */ |
||
230 | 8 | public function isMember($userId) |
|
234 | |||
235 | /** |
||
236 | * Whether or not the project is private. |
||
237 | * |
||
238 | * @return bool |
||
239 | */ |
||
240 | 2 | public function isPrivate() |
|
244 | |||
245 | /** |
||
246 | * Whether or not the project is public. |
||
247 | * |
||
248 | * @return bool |
||
249 | */ |
||
250 | 3 | public function isPublic() |
|
254 | |||
255 | /** |
||
256 | * Whether or not the project is private internal. |
||
257 | * |
||
258 | * @return bool |
||
259 | */ |
||
260 | 24 | public function isPrivateInternal() |
|
264 | |||
265 | /** |
||
266 | * Returns project status as string name. |
||
267 | * |
||
268 | * @return string |
||
269 | */ |
||
270 | 1 | public function getStatusAsName() |
|
278 | |||
279 | /** |
||
280 | * Returns the class name to be used for project status. |
||
281 | * |
||
282 | * @return string |
||
283 | */ |
||
284 | 1 | public function getStatusClass() |
|
292 | |||
293 | /** |
||
294 | * Whether or not a user can access the project. |
||
295 | * |
||
296 | * @param User $user |
||
297 | * |
||
298 | * @return bool |
||
299 | */ |
||
300 | 3 | public function canView(User $user) |
|
312 | } |
||
313 |