|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Spinen\ClickUp; |
|
4
|
|
|
|
|
5
|
|
|
use Carbon\Carbon; |
|
6
|
|
|
use Spinen\ClickUp\Exceptions\NoClientException; |
|
7
|
|
|
use Spinen\ClickUp\Support\Collection; |
|
8
|
|
|
use Spinen\ClickUp\Support\Model; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Class Item |
|
12
|
|
|
* |
|
13
|
|
|
* @package Spinen\ClickUp |
|
14
|
|
|
* |
|
15
|
|
|
* @property boolean $resolved |
|
16
|
|
|
* @property boolean $unresolved |
|
17
|
|
|
* @property Carbon $date_created |
|
18
|
|
|
* @property Collection $children |
|
19
|
|
|
* @property float $orderindex |
|
20
|
|
|
* @property Member $assignee |
|
21
|
|
|
* @property string $id |
|
22
|
|
|
* @property string $name |
|
23
|
|
|
* @property string $parent // TODO: Swap to Item when relationship addessed |
|
24
|
|
|
*/ |
|
25
|
|
|
class Item extends Model |
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
28
|
|
|
* The attributes that should be cast to native types. |
|
29
|
|
|
* |
|
30
|
|
|
* @var array |
|
31
|
|
|
*/ |
|
32
|
|
|
protected $casts = [ |
|
33
|
|
|
'date_created' => 'datetime:Uv', |
|
34
|
|
|
'id' => 'string', |
|
35
|
|
|
'orderindex' => 'float', |
|
36
|
|
|
'resolved' => 'boolean', |
|
37
|
|
|
'unresolved' => 'boolean', |
|
38
|
|
|
]; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Is resource nested behind parentModel |
|
42
|
|
|
* |
|
43
|
|
|
* Several of the endpoints are nested behind another model for relationship, but then to |
|
44
|
|
|
* interact with the specific model, then are not nested. This property will know when to |
|
45
|
|
|
* keep the specific model nested. |
|
46
|
|
|
* |
|
47
|
|
|
* @var bool |
|
48
|
|
|
*/ |
|
49
|
|
|
protected $nested = true; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Path to API endpoint. |
|
53
|
|
|
* |
|
54
|
|
|
* @var string |
|
55
|
|
|
*/ |
|
56
|
|
|
protected $path = '/checklist_item'; |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Accessor for Assignee. |
|
60
|
|
|
* |
|
61
|
|
|
* @param array $assignee |
|
62
|
|
|
* |
|
63
|
|
|
* @return Member |
|
64
|
|
|
* @throws NoClientException |
|
65
|
|
|
*/ |
|
66
|
1 |
|
public function getAssigneeAttribute($assignee): Member |
|
67
|
|
|
{ |
|
68
|
1 |
|
return $this->givenOne(Member::class, $assignee); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Accessor for Children. |
|
73
|
|
|
* |
|
74
|
|
|
* @param array $children |
|
75
|
|
|
* |
|
76
|
|
|
* @return Collection |
|
77
|
|
|
* @throws NoClientException |
|
78
|
|
|
*/ |
|
79
|
1 |
|
public function getChildrenAttribute(array $children): Collection |
|
80
|
|
|
{ |
|
81
|
1 |
|
return $this->givenMany(Item::class, $children); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* Accessor for Parent. |
|
86
|
|
|
* |
|
87
|
|
|
* @param string $parent |
|
88
|
|
|
* |
|
89
|
|
|
* @return Item |
|
90
|
|
|
*/ |
|
91
|
|
|
// TODO: Figure out how to make this relationship work |
|
92
|
|
|
/*public function getParentAttribute($parent): Item |
|
93
|
|
|
{ |
|
94
|
|
|
return $this->parentModel; |
|
95
|
|
|
}*/ |
|
96
|
|
|
} |
|
97
|
|
|
|