1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @copyright 2017 Vladimir Jimenez |
5
|
|
|
* @license https://github.com/allejo/PhpPulse/blob/master/LICENSE.md MIT |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace allejo\DaPulse\Objects; |
9
|
|
|
|
10
|
|
|
use allejo\DaPulse\Exceptions\ColumnNotFoundException; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class PulseColumnColorValue |
14
|
|
|
* |
15
|
|
|
* @package allejo\DaPulse\Objects |
16
|
|
|
* @since 0.1.0 |
17
|
|
|
*/ |
18
|
|
|
class PulseColumnStatusValue extends PulseColumnValue |
19
|
|
|
{ |
20
|
|
|
const DEFAULT_VALUE = self::Grey; // The default color for DaPulse columns |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* The index of the orange status |
24
|
|
|
*/ |
25
|
|
|
const Orange = 0; |
|
|
|
|
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* The index of the light green status |
29
|
|
|
*/ |
30
|
|
|
const L_Green = 1; |
|
|
|
|
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* The index of the red status |
34
|
|
|
*/ |
35
|
|
|
const Red = 2; |
|
|
|
|
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* The index of the blue status |
39
|
|
|
*/ |
40
|
|
|
const Blue = 3; |
|
|
|
|
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* The index of the purple status |
44
|
|
|
*/ |
45
|
|
|
const Purple = 4; |
|
|
|
|
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* The index of the grey status |
49
|
|
|
*/ |
50
|
|
|
const Grey = 5; |
|
|
|
|
51
|
|
|
const Gray = self::Grey; // just an alias |
|
|
|
|
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* The index of the green status |
55
|
|
|
*/ |
56
|
|
|
const Green = 6; |
|
|
|
|
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* The index of the light blue status |
60
|
|
|
*/ |
61
|
|
|
const L_Blue = 7; |
|
|
|
|
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* The index of the gold status |
65
|
|
|
*/ |
66
|
|
|
const Gold = 8; |
|
|
|
|
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* The index of the yellow status |
70
|
|
|
*/ |
71
|
|
|
const Yellow = 9; |
|
|
|
|
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* The index of the black status |
75
|
|
|
*/ |
76
|
|
|
const Black = 10; |
|
|
|
|
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* The lowest status value that exists |
80
|
|
|
*/ |
81
|
|
|
const MIN_VALUE = self::Orange; |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* The largest status value that exists |
85
|
|
|
*/ |
86
|
|
|
const MAX_VALUE = self::Black; |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Get the numerical representation of the color that a status column is set to. |
90
|
|
|
* |
91
|
|
|
* @api |
92
|
|
|
* |
93
|
|
|
* @since 0.4.0 ColumnNotFoundException is now thrown |
94
|
|
|
* @since 0.1.0 |
95
|
|
|
* |
96
|
|
|
* @throws ColumnNotFoundException The specified column ID does not exist for the parent Pulse |
97
|
|
|
* |
98
|
|
|
* @return int The color value of a column |
99
|
|
|
*/ |
100
|
2 |
|
public function getValue () |
101
|
|
|
{ |
102
|
2 |
|
return parent::getValue(); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Update the status of a status column |
107
|
|
|
* |
108
|
|
|
* It is highly recommended that you use the constants available in the **PulseColumnColorValue** class to match the |
109
|
|
|
* colors; keep in mind this value cannot be higher than 11. |
110
|
|
|
* |
111
|
|
|
* @api |
112
|
|
|
* |
113
|
|
|
* @param int $color The numerical value of the new color value |
114
|
|
|
* |
115
|
|
|
* @see PulseColumnStatusValue::Orange PulseColumnStatusValue::Orange |
116
|
|
|
* @see PulseColumnStatusValue::L_Green PulseColumnStatusValue::L_Green |
117
|
|
|
* @see PulseColumnStatusValue::Red PulseColumnStatusValue::Red |
118
|
|
|
* @see PulseColumnStatusValue::Blue PulseColumnStatusValue::Blue |
119
|
|
|
* @see PulseColumnStatusValue::Purple PulseColumnStatusValue::Purple |
120
|
|
|
* @see PulseColumnStatusValue::Grey PulseColumnStatusValue::Grey |
121
|
|
|
* @see PulseColumnStatusValue::Green PulseColumnStatusValue::Green |
122
|
|
|
* @see PulseColumnStatusValue::L_Blue PulseColumnStatusValue::L_Blue |
123
|
|
|
* @see PulseColumnStatusValue::Gold PulseColumnStatusValue::Gold |
124
|
|
|
* @see PulseColumnStatusValue::Yellow PulseColumnStatusValue::Yellow |
125
|
|
|
* @see PulseColumnStatusValue::Black PulseColumnStatusValue::Black |
126
|
|
|
* |
127
|
|
|
* @since 0.1.0 |
128
|
|
|
* |
129
|
|
|
* @throws \InvalidArgumentException if the $color is not an int or is not between 0-10 |
130
|
|
|
*/ |
131
|
5 |
|
public function updateValue ($color) |
132
|
|
|
{ |
133
|
5 |
|
if ($color < 0 || $color > 10 || !is_int($color)) |
134
|
|
|
{ |
135
|
4 |
|
throw new \InvalidArgumentException("DaPulse only has color indexes from 0-10"); |
136
|
|
|
} |
137
|
|
|
|
138
|
1 |
|
$url = sprintf("%s/%d/columns/%s/status.json", self::apiEndpoint(), $this->board_id, $this->column_id); |
139
|
|
|
$postParams = [ |
140
|
1 |
|
"pulse_id" => $this->pulse_id, |
141
|
1 |
|
"color_index" => $color |
142
|
|
|
]; |
143
|
|
|
|
144
|
1 |
|
$result = self::sendPut($url, $postParams); |
145
|
1 |
|
$this->jsonResponse = $result; |
|
|
|
|
146
|
1 |
|
$this->setValue($result); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* Get the hex value of the color used on DaPulse to represent the different statuses. |
151
|
|
|
* |
152
|
|
|
* @api |
153
|
|
|
* |
154
|
|
|
* @param int $numericalValue The numerical value of the column |
155
|
|
|
* |
156
|
|
|
* @since 0.1.0 |
157
|
|
|
* |
158
|
|
|
* @return string A hex value **without** the leading # |
159
|
|
|
*/ |
160
|
|
|
public static function getHexColor ($numericalValue) |
161
|
|
|
{ |
162
|
|
|
$colorArray = self::getHexColors(); |
163
|
|
|
|
164
|
|
|
return $colorArray[$numericalValue]; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* Get an array of hex values for each of the statuses |
169
|
|
|
* |
170
|
|
|
* @api |
171
|
|
|
* |
172
|
|
|
* @since 0.3.1 |
173
|
|
|
* |
174
|
|
|
* @return array |
|
|
|
|
175
|
|
|
*/ |
176
|
|
|
public static function getHexColors () |
177
|
|
|
{ |
178
|
2 |
|
return [ |
179
|
|
|
self::Orange => "fdab3d", |
180
|
2 |
|
self::L_Green => "00c875", |
181
|
|
|
self::Red => "e2445c", |
182
|
|
|
self::Blue => "0086c0", |
183
|
|
|
self::L_Blue => "579bfc", |
184
|
2 |
|
self::Purple => "a25ddc", |
185
|
2 |
|
self::Green => "037f4c", |
186
|
|
|
self::Gold => "CAB641", |
187
|
|
|
self::Yellow => "FFCB00", |
188
|
|
|
self::Black => "333333", |
189
|
|
|
self::Grey => "c4c4c4" |
190
|
|
|
]; |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
protected function setValue ($response) |
194
|
|
|
{ |
195
|
|
|
$value = $response['value']; |
196
|
|
|
|
197
|
|
|
// If the status column is set to 'Grey' or the default 'Just Assigned' value, DaPulse will evidently |
198
|
|
|
// return null... So let's set it to the Grey value to not confuse people |
199
|
|
|
$this->column_value = (is_array($value) && array_key_exists('index', $value)) ? $response["value"]["index"] : self::Grey; |
200
|
|
|
} |
201
|
|
|
} |
202
|
|
|
|