1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Spinen\ClickUp; |
4
|
|
|
|
5
|
|
|
use Spinen\ClickUp\Exceptions\InvalidRelationshipException; |
6
|
|
|
use Spinen\ClickUp\Exceptions\ModelNotFoundException; |
7
|
|
|
use Spinen\ClickUp\Exceptions\NoClientException; |
8
|
|
|
use Carbon\Carbon; |
9
|
|
|
use Spinen\ClickUp\Support\Collection; |
10
|
|
|
use Spinen\ClickUp\Support\Model; |
11
|
|
|
use Spinen\ClickUp\Support\Relations\BelongsTo; |
12
|
|
|
use Spinen\ClickUp\Support\Relations\ChildOf; |
13
|
|
|
use Spinen\ClickUp\Support\Relations\HasMany; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class Task |
17
|
|
|
* |
18
|
|
|
* @package Spinen\ClickUp |
19
|
|
|
* |
20
|
|
|
* @property boolean $archived |
21
|
|
|
* @property array $attachments |
22
|
|
|
* @property array $dependencies |
23
|
|
|
* @property Carbon $date_closed |
24
|
|
|
* @property Carbon $date_created |
25
|
|
|
* @property Carbon $date_updated |
26
|
|
|
* @property Carbon $due_date |
27
|
|
|
* @property Carbon $start_date |
28
|
|
|
* @property Collection $assignees |
29
|
|
|
* @property Collection $checklists |
30
|
|
|
* @property Collection $comments |
31
|
|
|
* @property Collection $custom_fields |
32
|
|
|
* @property Collection $members |
33
|
|
|
* @property Collection $tags |
34
|
|
|
* @property Collection $times |
35
|
|
|
* @property float $orderindex |
36
|
|
|
* @property Folder $folder |
37
|
|
|
* @property integer $team_id |
38
|
|
|
* @property integer $time_estimate |
39
|
|
|
* @property integer $time_spent |
40
|
|
|
* @property Member $creator |
41
|
|
|
* @property Priority $priority |
42
|
|
|
* @property Project $project |
43
|
|
|
* @property Space $space |
44
|
|
|
* @property Status $status |
45
|
|
|
* @property string $id |
46
|
|
|
* @property string $name |
47
|
|
|
* @property string $url |
48
|
|
|
* @property Task $parent |
49
|
|
|
* @property TaskList $list |
50
|
|
|
* @property Team $team |
51
|
|
|
* @property View $view |
52
|
|
|
*/ |
53
|
|
|
class Task extends Model |
54
|
|
|
{ |
55
|
|
|
/** |
56
|
|
|
* The attributes that should be cast to native types. |
57
|
|
|
* |
58
|
|
|
* @var array |
59
|
|
|
*/ |
60
|
|
|
protected $casts = [ |
61
|
|
|
'archived' => 'boolean', |
62
|
|
|
'date_closed' => 'datetime:Uv', |
63
|
|
|
'date_created' => 'datetime:Uv', |
64
|
|
|
'date_updated' => 'datetime:Uv', |
65
|
|
|
'due_date' => 'datetime:Uv', |
66
|
|
|
'id' => 'string', |
67
|
|
|
'orderindex' => 'float', |
68
|
|
|
'start_date' => 'datetime:Uv', |
69
|
|
|
'team_id' => 'integer', |
70
|
|
|
'time_estimate' => 'integer', |
71
|
|
|
'time_spent' => 'integer', |
72
|
|
|
]; |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Path to API endpoint. |
76
|
|
|
* |
77
|
|
|
* @var string |
78
|
|
|
*/ |
79
|
|
|
protected $path = '/task'; |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @return HasMany |
83
|
|
|
|
84
|
|
|
* @throws InvalidRelationshipException |
85
|
|
|
* @throws ModelNotFoundException |
86
|
|
|
* @throws NoClientException |
87
|
|
|
*/ |
88
|
1 |
|
public function comments(): HasMany |
89
|
|
|
{ |
90
|
1 |
|
return $this->hasMany(Comment::class); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Accessor for Assignees. |
95
|
|
|
* |
96
|
|
|
* @param array $assignees |
97
|
|
|
* |
98
|
|
|
* @return Collection |
99
|
|
|
* @throws NoClientException |
100
|
|
|
*/ |
101
|
1 |
|
public function getAssigneesAttribute(array $assignees): Collection |
102
|
|
|
{ |
103
|
1 |
|
return $this->givenMany(Member::class, $assignees); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Accessor for Checklists. |
108
|
|
|
* |
109
|
|
|
* @param array $checklists |
110
|
|
|
* |
111
|
|
|
* @return Collection |
112
|
|
|
* @throws NoClientException |
113
|
|
|
*/ |
114
|
1 |
|
public function getChecklistsAttribute(array $checklists): Collection |
115
|
|
|
{ |
116
|
1 |
|
return $this->givenMany(Checklist::class, $checklists); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Accessor for Creator. |
121
|
|
|
* |
122
|
|
|
* @param array $creator |
123
|
|
|
* |
124
|
|
|
* @return Member |
125
|
|
|
* @throws NoClientException |
126
|
|
|
*/ |
127
|
1 |
|
public function getCreatorAttribute($creator): Member |
128
|
|
|
{ |
129
|
1 |
|
return $this->givenOne(Member::class, $creator); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* Accessor for CustomFields. |
134
|
|
|
* |
135
|
|
|
* @param array $custom_fields |
136
|
|
|
* |
137
|
|
|
* @return Collection |
138
|
|
|
* @throws NoClientException |
139
|
|
|
*/ |
140
|
1 |
|
public function getCustomFieldsAttribute(array $custom_fields): Collection |
141
|
|
|
{ |
142
|
1 |
|
return $this->givenMany(Field::class, $custom_fields); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* Accessor for Folder. |
147
|
|
|
* |
148
|
|
|
* @param array $folder |
149
|
|
|
* |
150
|
|
|
* @return Folder |
151
|
|
|
* @throws NoClientException |
152
|
|
|
*/ |
153
|
1 |
|
public function getFolderAttribute($folder): Folder |
154
|
|
|
{ |
155
|
1 |
|
return $this->givenOne(Folder::class, $folder); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* Accessor for Parent. |
160
|
|
|
* |
161
|
|
|
* @param string $parent |
162
|
|
|
* |
163
|
|
|
* @return Task |
164
|
|
|
*/ |
165
|
|
|
// TODO: Figure out how to make this relationship work |
166
|
|
|
/*public function getParentAttribute($parent): Task |
167
|
|
|
{ |
168
|
|
|
return $this->parentModel; |
169
|
|
|
}*/ |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* Accessor for Priority. |
173
|
|
|
* |
174
|
|
|
* @param array $priority |
175
|
|
|
* |
176
|
|
|
* @return Priority |
177
|
|
|
* @throws NoClientException |
178
|
|
|
*/ |
179
|
1 |
|
public function getPriorityAttribute($priority): Priority |
180
|
|
|
{ |
181
|
1 |
|
return $this->givenOne(Priority::class, $priority); |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* Accessor for Project. |
186
|
|
|
* |
187
|
|
|
* @param array $project |
188
|
|
|
* |
189
|
|
|
* @return Project |
190
|
|
|
* @throws NoClientException |
191
|
|
|
*/ |
192
|
1 |
|
public function getProjectAttribute($project): Project |
193
|
|
|
{ |
194
|
|
|
// TODO: This is not documented. I think it is a hold over from v1? |
195
|
1 |
|
return $this->givenOne(Project::class, $project); |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* Accessor for Space. |
200
|
|
|
* |
201
|
|
|
* @param array $space |
202
|
|
|
* |
203
|
|
|
* @return Space |
204
|
|
|
* @throws NoClientException |
205
|
|
|
*/ |
206
|
1 |
|
public function getSpaceAttribute($space): Space |
207
|
|
|
{ |
208
|
|
|
// TODO: Look into making this a relationship |
209
|
1 |
|
return $this->givenOne(Space::class, $space); |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
/** |
213
|
|
|
* Accessor for Status. |
214
|
|
|
* |
215
|
|
|
* @param array $status |
216
|
|
|
* |
217
|
|
|
* @return Status |
218
|
|
|
* @throws NoClientException |
219
|
|
|
*/ |
220
|
1 |
|
public function getStatusAttribute($status): Status |
221
|
|
|
{ |
222
|
1 |
|
return $this->givenOne(Status::class, $status); |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
/** |
226
|
|
|
* Accessor for Tags. |
227
|
|
|
* |
228
|
|
|
* @param array $tags |
229
|
|
|
* |
230
|
|
|
* @return Collection |
231
|
|
|
* @throws NoClientException |
232
|
|
|
*/ |
233
|
1 |
|
public function getTagsAttribute(array $tags): Collection |
234
|
|
|
{ |
235
|
1 |
|
return $this->givenMany(Tag::class, $tags); |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* @return ChildOf |
240
|
|
|
* @throws InvalidRelationshipException |
241
|
|
|
* @throws ModelNotFoundException |
242
|
|
|
* @throws NoClientException |
243
|
|
|
*/ |
244
|
2 |
|
public function list(): ?ChildOf |
245
|
|
|
{ |
246
|
2 |
|
return is_a($this->parentModel, TaskList::class) ? $this->childOf(TaskList::class) : null; |
247
|
|
|
} |
248
|
|
|
|
249
|
|
|
/** |
250
|
|
|
* @return HasMany |
251
|
|
|
|
252
|
|
|
* @throws InvalidRelationshipException |
253
|
|
|
* @throws ModelNotFoundException |
254
|
|
|
* @throws NoClientException |
255
|
|
|
*/ |
256
|
1 |
|
public function members(): HasMany |
257
|
|
|
{ |
258
|
1 |
|
return $this->hasMany(Member::class); |
259
|
|
|
} |
260
|
|
|
|
261
|
|
|
/** |
262
|
|
|
* @return ChildOf |
263
|
|
|
* @throws InvalidRelationshipException |
264
|
|
|
* @throws ModelNotFoundException |
265
|
|
|
* @throws NoClientException |
266
|
|
|
*/ |
267
|
2 |
|
public function team(): ?ChildOf |
268
|
|
|
{ |
269
|
2 |
|
return is_a($this->parentModel, Team::class) ? $this->childOf(Team::class) : null; |
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
/** |
273
|
|
|
* @return HasMany |
274
|
|
|
|
275
|
|
|
* @throws InvalidRelationshipException |
276
|
|
|
* @throws ModelNotFoundException |
277
|
|
|
* @throws NoClientException |
278
|
|
|
*/ |
279
|
1 |
|
public function times(): HasMany |
280
|
|
|
{ |
281
|
1 |
|
return $this->hasMany(Time::class); |
282
|
|
|
} |
283
|
|
|
|
284
|
|
|
/** |
285
|
|
|
* @return BelongsTo |
286
|
|
|
* @throws InvalidRelationshipException |
287
|
|
|
* @throws ModelNotFoundException |
288
|
|
|
* @throws NoClientException |
289
|
|
|
*/ |
290
|
1 |
|
public function view(): BelongsTo |
291
|
|
|
{ |
292
|
1 |
|
return $this->belongsTo(View::class); |
293
|
|
|
} |
294
|
|
|
} |
295
|
|
|
|