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