1 | <?php |
||
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 | 37 | public function to($url = '') |
|
104 | { |
||
105 | 37 | 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 | 4 | public function getOpenIssuesCountAttribute() |
|
114 | { |
||
115 | 4 | 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 | public function getClosedIssuesCountAttribute() |
||
124 | { |
||
125 | 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 | 1 | public function getTotalQuote() |
|
160 | { |
||
161 | 1 | $total = 0; |
|
162 | 1 | foreach ($this->issues as $issue) { |
|
163 | 1 | $total += $issue->time_quote; |
|
164 | } |
||
165 | |||
166 | 1 | return $total; |
|
167 | } |
||
168 | |||
169 | /** |
||
170 | * Calculate the progress (open & closed issues). |
||
171 | * |
||
172 | * @return float|int |
||
173 | */ |
||
174 | public function getProgress() |
||
175 | { |
||
176 | $total = $this->openIssuesCount + $this->closedIssuesCount; |
||
177 | $progress = 100; |
||
178 | if ($total > 0) { |
||
179 | $progress = (float) ($this->closedIssuesCount / $total) * 100; |
||
180 | } |
||
181 | $progressInt = (int) $progress; |
||
182 | if ($progressInt > 0) { |
||
183 | $progress = number_format($progress, 2); |
||
184 | $fraction = $progress - $progressInt; |
||
185 | if ($fraction === 0.0) { |
||
186 | $progress = $progressInt; |
||
187 | } |
||
188 | } |
||
189 | |||
190 | 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) |
|
204 | |||
205 | /** |
||
206 | * Whether or not the project is private or public. |
||
207 | * |
||
208 | * @return bool |
||
209 | */ |
||
210 | 1 | public function isPrivate() |
|
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.