1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Helix\Asana\CustomField; |
4
|
|
|
|
5
|
|
|
use Helix\Asana\Base\AbstractEntity; |
6
|
|
|
use Helix\Asana\Base\AbstractEntity\CreateTrait; |
7
|
|
|
use Helix\Asana\Base\AbstractEntity\UpdateTrait; |
8
|
|
|
use Helix\Asana\CustomField; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* A custom field enum option. |
12
|
|
|
* |
13
|
|
|
* @see https://developers.asana.com/docs/enum-option |
14
|
|
|
* |
15
|
|
|
* @method string getColor () @depends after-create |
16
|
|
|
* @method bool isEnabled () |
17
|
|
|
* @method string getName () |
18
|
|
|
* |
19
|
|
|
* @method $this setColor (string $color) |
20
|
|
|
* @method $this setEnabled (bool $enabled) |
21
|
|
|
* @method $this setName (string $name) |
22
|
|
|
*/ |
23
|
|
|
class EnumOption extends AbstractEntity { |
24
|
|
|
|
25
|
|
|
use CreateTrait; |
26
|
|
|
use UpdateTrait; |
27
|
|
|
|
28
|
|
|
const DIR = 'enum_options'; |
29
|
|
|
const TYPE = 'enum_option'; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var CustomField |
33
|
|
|
*/ |
34
|
|
|
protected $parent; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @param CustomField $customField |
38
|
|
|
* @param array $data |
39
|
|
|
*/ |
40
|
|
|
public function __construct (CustomField $customField, array $data = []) { |
41
|
|
|
$this->parent = $customField; |
42
|
|
|
parent::__construct($customField, $data); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @return CustomField |
47
|
|
|
*/ |
48
|
|
|
public function getCustomField () { |
49
|
|
|
return $this->parent; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Move above another option. |
54
|
|
|
* |
55
|
|
|
* @see https://developers.asana.com/docs/reorder-a-custom-fields-enum |
56
|
|
|
* |
57
|
|
|
* @depends after-create |
58
|
|
|
* @param EnumOption $option |
59
|
|
|
* @return $this |
60
|
|
|
*/ |
61
|
|
|
public function moveAbove (EnumOption $option) { |
62
|
|
|
$this->api->post("{$this->parent}/enum_options/insert", [ |
63
|
|
|
'before_enum_option' => $option->getGid(), |
64
|
|
|
'enum_option' => $this->getGid() |
65
|
|
|
]); |
66
|
|
|
$this->parent->_reload('enum_options'); // safe. the options are pooled. |
67
|
|
|
return $this; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Move below another option. |
72
|
|
|
* |
73
|
|
|
* @see https://developers.asana.com/docs/reorder-a-custom-fields-enum |
74
|
|
|
* |
75
|
|
|
* @depends after-create |
76
|
|
|
* @param EnumOption $option |
77
|
|
|
* @return $this |
78
|
|
|
*/ |
79
|
|
|
public function moveBelow (EnumOption $option) { |
80
|
|
|
$this->api->post("{$this->parent}/enum_options//insert", [ |
81
|
|
|
'after_enum_option' => $option->getGid(), |
82
|
|
|
'enum_option' => $this->getGid() |
83
|
|
|
]); |
84
|
|
|
$this->parent->_reload('enum_options'); // safe. the options are pooled. |
85
|
|
|
return $this; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Make the option first. |
90
|
|
|
* |
91
|
|
|
* @depends after-create |
92
|
|
|
* @return $this |
93
|
|
|
*/ |
94
|
|
|
public function moveFirst () { |
95
|
|
|
$first = $this->parent->getEnumOptions()[0]; |
96
|
|
|
if ($first !== $this) { |
97
|
|
|
$this->moveAbove($first); |
98
|
|
|
} |
99
|
|
|
return $this; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Make the option last. |
104
|
|
|
* |
105
|
|
|
* @depends after-create |
106
|
|
|
* @return $this |
107
|
|
|
*/ |
108
|
|
|
public function moveLast () { |
109
|
|
|
$options = $this->parent->getEnumOptions(); |
110
|
|
|
$last = $options[count($options) - 1]; |
111
|
|
|
if ($last !== $this) { |
112
|
|
|
$this->moveBelow($last); |
113
|
|
|
} |
114
|
|
|
return $this; |
115
|
|
|
} |
116
|
|
|
} |