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\ChildOf; |
12
|
|
|
use Spinen\ClickUp\Support\Relations\HasMany; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class TaskList |
16
|
|
|
* |
17
|
|
|
* @package Spinen\ClickUp |
18
|
|
|
* |
19
|
|
|
* @property boolean $archived |
20
|
|
|
* @property boolean $due_date_time |
21
|
|
|
* @property boolean $override_statuses |
22
|
|
|
* @property boolean $start_date_time |
23
|
|
|
* @property Carbon $due_date |
24
|
|
|
* @property Carbon $start_date |
25
|
|
|
* @property Collection $statuses |
26
|
|
|
* @property float $orderindex |
27
|
|
|
* @property integer $id |
28
|
|
|
* @property integer $task_count |
29
|
|
|
* @property Member $assignee |
30
|
|
|
* @property Priority $priority |
31
|
|
|
* @property Status $status |
32
|
|
|
* @property string $content |
33
|
|
|
* @property string $name |
34
|
|
|
*/ |
35
|
|
|
class TaskList extends Model |
36
|
|
|
{ |
37
|
|
|
/** |
38
|
|
|
* The attributes that should be cast to native types. |
39
|
|
|
* |
40
|
|
|
* @var array |
41
|
|
|
*/ |
42
|
|
|
protected $casts = [ |
43
|
|
|
'archived' => 'boolean', |
44
|
|
|
'due_date' => 'datetime:Uv', |
45
|
|
|
'due_date_time' => 'boolean', |
46
|
|
|
'id' => 'integer', |
47
|
|
|
'orderindex' => 'float', |
48
|
|
|
'override_statuses' => 'boolean', |
49
|
|
|
'start_date' => 'datetime:Uv', |
50
|
|
|
'start_date_time' => 'boolean', |
51
|
|
|
'task_count' => 'integer', |
52
|
|
|
]; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Path to API endpoint. |
56
|
|
|
* |
57
|
|
|
* @var string |
58
|
|
|
*/ |
59
|
|
|
protected $path = '/list'; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Some of the responses have the collections under a property |
63
|
|
|
* |
64
|
|
|
* @var string|null |
65
|
|
|
*/ |
66
|
|
|
protected $responseCollectionKey = 'lists'; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Some of the responses have the data under a property |
70
|
|
|
* |
71
|
|
|
* @var string|null |
72
|
|
|
*/ |
73
|
|
|
protected $responseKey = 'list'; |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @return HasMany |
77
|
|
|
|
78
|
|
|
* @throws InvalidRelationshipException |
79
|
|
|
* @throws ModelNotFoundException |
80
|
|
|
* @throws NoClientException |
81
|
|
|
*/ |
82
|
1 |
|
public function comments(): HasMany |
83
|
|
|
{ |
84
|
1 |
|
return $this->hasMany(Comment::class); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @return HasMany |
89
|
|
|
|
90
|
|
|
* @throws InvalidRelationshipException |
91
|
|
|
* @throws ModelNotFoundException |
92
|
|
|
* @throws NoClientException |
93
|
|
|
*/ |
94
|
1 |
|
public function fields(): HasMany |
95
|
|
|
{ |
96
|
1 |
|
return $this->hasMany(Field::class); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @return ChildOf |
101
|
|
|
* @throws InvalidRelationshipException |
102
|
|
|
* @throws ModelNotFoundException |
103
|
|
|
* @throws NoClientException |
104
|
|
|
*/ |
105
|
2 |
|
public function folder(): ?ChildOf |
106
|
|
|
{ |
107
|
2 |
|
return is_a($this->parentModel, Folder::class) ? $this->childOf(Folder::class) : null; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Accessor for Assignee. |
112
|
|
|
* |
113
|
|
|
* @param array $assignee |
114
|
|
|
* |
115
|
|
|
* @return Member |
116
|
|
|
* @throws NoClientException |
117
|
|
|
*/ |
118
|
1 |
|
public function getAssigneeAttribute($assignee): Member |
119
|
|
|
{ |
120
|
1 |
|
return $this->givenOne(Member::class, $assignee); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Accessor for Priority. |
125
|
|
|
* |
126
|
|
|
* @param array $priority |
127
|
|
|
* |
128
|
|
|
* @return Priority |
129
|
|
|
* @throws NoClientException |
130
|
|
|
*/ |
131
|
1 |
|
public function getPriorityAttribute($priority): Priority |
132
|
|
|
{ |
133
|
1 |
|
return $this->givenOne(Priority::class, $priority); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* Accessor for Status. |
138
|
|
|
* |
139
|
|
|
* @param array $status |
140
|
|
|
* |
141
|
|
|
* @return Status |
142
|
|
|
* @throws NoClientException |
143
|
|
|
*/ |
144
|
1 |
|
public function getStatusAttribute($status): Status |
145
|
|
|
{ |
146
|
1 |
|
return $this->givenOne(Status::class, $status); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* Accessor for Statuses. |
151
|
|
|
* |
152
|
|
|
* @param array $statuses |
153
|
|
|
* |
154
|
|
|
* @return Collection |
155
|
|
|
* @throws NoClientException |
156
|
|
|
*/ |
157
|
1 |
|
public function getStatusesAttribute(array $statuses): Collection |
158
|
|
|
{ |
159
|
1 |
|
return $this->givenMany(Status::class, $statuses); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* @return HasMany |
164
|
|
|
|
165
|
|
|
* @throws InvalidRelationshipException |
166
|
|
|
* @throws ModelNotFoundException |
167
|
|
|
* @throws NoClientException |
168
|
|
|
*/ |
169
|
1 |
|
public function members(): HasMany |
170
|
|
|
{ |
171
|
1 |
|
return $this->hasMany(Member::class); |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* @return ChildOf |
176
|
|
|
* @throws InvalidRelationshipException |
177
|
|
|
* @throws ModelNotFoundException |
178
|
|
|
* @throws NoClientException |
179
|
|
|
*/ |
180
|
2 |
|
public function space(): ?ChildOf |
181
|
|
|
{ |
182
|
2 |
|
return is_a($this->parentModel, Space::class) ? $this->childOf(Space::class) : null; |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* @return HasMany |
187
|
|
|
|
188
|
|
|
* @throws InvalidRelationshipException |
189
|
|
|
* @throws ModelNotFoundException |
190
|
|
|
* @throws NoClientException |
191
|
|
|
*/ |
192
|
1 |
|
public function tasks(): HasMany |
193
|
|
|
{ |
194
|
1 |
|
return $this->hasMany(Task::class); |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* @return HasMany |
199
|
|
|
|
200
|
|
|
* @throws InvalidRelationshipException |
201
|
|
|
* @throws ModelNotFoundException |
202
|
|
|
* @throws NoClientException |
203
|
|
|
*/ |
204
|
1 |
|
public function taskTemplates(): HasMany |
205
|
|
|
{ |
206
|
1 |
|
return $this->hasMany(TaskTemplate::class); |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
/** |
210
|
|
|
* @return HasMany |
211
|
|
|
|
212
|
|
|
* @throws InvalidRelationshipException |
213
|
|
|
* @throws ModelNotFoundException |
214
|
|
|
* @throws NoClientException |
215
|
|
|
*/ |
216
|
1 |
|
public function views(): HasMany |
217
|
|
|
{ |
218
|
1 |
|
return $this->hasMany(View::class); |
219
|
|
|
} |
220
|
|
|
} |
221
|
|
|
|