|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace CarlosIO\Geckoboard\Widgets; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Class NumberAndSecondaryStat. |
|
7
|
|
|
*/ |
|
8
|
|
|
class NumberAndSecondaryStat extends Widget |
|
9
|
|
|
{ |
|
10
|
|
|
const TYPE_REGULAR = null; |
|
11
|
|
|
const TYPE_REVERSE = 'reverse'; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @var null Main value |
|
15
|
|
|
*/ |
|
16
|
|
|
private $mainValue = null; |
|
17
|
|
|
/** |
|
18
|
|
|
* @var null Secondary value |
|
19
|
|
|
*/ |
|
20
|
|
|
private $secondaryValue = null; |
|
21
|
|
|
/** |
|
22
|
|
|
* @var null Main value prefix |
|
23
|
|
|
*/ |
|
24
|
|
|
private $mainPrefix = null; |
|
25
|
|
|
/** |
|
26
|
|
|
* @var null Main value prefix |
|
27
|
|
|
*/ |
|
28
|
|
|
private $type = null; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var string |
|
32
|
|
|
*/ |
|
33
|
|
|
private $mainText = ''; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @var string |
|
37
|
|
|
*/ |
|
38
|
|
|
private $secondaryText = ''; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @var bool |
|
42
|
|
|
*/ |
|
43
|
|
|
private $absolute = false; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @var boolean |
|
47
|
|
|
*/ |
|
48
|
|
|
private $displayAsTimeDuration = false; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Set data main prefix (€, $, etc.). |
|
52
|
|
|
* |
|
53
|
|
|
* @param string $mainPrefix |
|
54
|
|
|
* |
|
55
|
|
|
* @return $this |
|
56
|
|
|
*/ |
|
57
|
1 |
|
public function setMainPrefix($mainPrefix) |
|
58
|
|
|
{ |
|
59
|
1 |
|
$this->mainPrefix = $mainPrefix; |
|
|
|
|
|
|
60
|
|
|
|
|
61
|
1 |
|
return $this; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Get data main prefix (€, $, etc.). |
|
66
|
|
|
* |
|
67
|
|
|
* @return string |
|
68
|
|
|
*/ |
|
69
|
8 |
|
public function getMainPrefix() |
|
70
|
|
|
{ |
|
71
|
8 |
|
return $this->mainPrefix; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Set main value. |
|
76
|
|
|
* |
|
77
|
|
|
* @param int $mainValue |
|
78
|
|
|
* |
|
79
|
|
|
* @return $this |
|
80
|
|
|
*/ |
|
81
|
3 |
|
public function setMainValue($mainValue) |
|
82
|
|
|
{ |
|
83
|
3 |
|
$this->mainValue = $mainValue; |
|
|
|
|
|
|
84
|
|
|
|
|
85
|
3 |
|
return $this; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Get main value. |
|
90
|
|
|
* |
|
91
|
|
|
* @return int |
|
92
|
|
|
*/ |
|
93
|
8 |
|
public function getMainValue() |
|
94
|
|
|
{ |
|
95
|
8 |
|
return $this->mainValue; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* Set the primary text value. (Visible if widget is 2x2 |
|
100
|
|
|
* or 1x1 without a secondary value). |
|
101
|
|
|
* |
|
102
|
|
|
* @param string $mainText The text body |
|
103
|
|
|
* |
|
104
|
|
|
* @return NumberAndSecondaryStat |
|
105
|
|
|
*/ |
|
106
|
1 |
|
public function setMainText($mainText) |
|
107
|
|
|
{ |
|
108
|
1 |
|
$this->mainText = $mainText; |
|
109
|
|
|
|
|
110
|
1 |
|
return $this; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* Return the main text body. |
|
115
|
|
|
* |
|
116
|
|
|
* @return string |
|
117
|
|
|
*/ |
|
118
|
1 |
|
public function getMainText() |
|
119
|
|
|
{ |
|
120
|
1 |
|
return $this->mainText; |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* Set secondary value. |
|
125
|
|
|
* |
|
126
|
|
|
* @param int $secondaryValue |
|
127
|
|
|
* |
|
128
|
|
|
* @return $this |
|
129
|
|
|
*/ |
|
130
|
2 |
|
public function setSecondaryValue($secondaryValue) |
|
131
|
|
|
{ |
|
132
|
2 |
|
$this->secondaryValue = $secondaryValue; |
|
|
|
|
|
|
133
|
|
|
|
|
134
|
2 |
|
return $this; |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* Get secondary value. |
|
139
|
|
|
* |
|
140
|
|
|
* @return string |
|
141
|
|
|
*/ |
|
142
|
8 |
|
public function getSecondaryValue() |
|
143
|
|
|
{ |
|
144
|
8 |
|
return $this->secondaryValue; |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
/** |
|
148
|
|
|
* Set the secondary text value. (Visible if widget is 2x2). |
|
149
|
|
|
* |
|
150
|
|
|
* @param string $secondaryText The text body |
|
151
|
|
|
* |
|
152
|
|
|
* @return NumberAndSecondaryStat |
|
153
|
|
|
*/ |
|
154
|
1 |
|
public function setSecondaryText($secondaryText) |
|
155
|
|
|
{ |
|
156
|
1 |
|
$this->secondaryText = $secondaryText; |
|
157
|
|
|
|
|
158
|
1 |
|
return $this; |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
/** |
|
162
|
|
|
* Return the secondary text body. |
|
163
|
|
|
* |
|
164
|
|
|
* @return string |
|
165
|
|
|
*/ |
|
166
|
1 |
|
public function getSecondaryText() |
|
167
|
|
|
{ |
|
168
|
1 |
|
return $this->secondaryText; |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
/** |
|
172
|
|
|
* @param string|null $prefix |
|
173
|
|
|
* |
|
174
|
|
|
* @return $this |
|
175
|
|
|
*/ |
|
176
|
1 |
|
public function setType($prefix) |
|
177
|
|
|
{ |
|
178
|
1 |
|
$this->type = $prefix; |
|
|
|
|
|
|
179
|
|
|
|
|
180
|
1 |
|
return $this; |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
|
/** |
|
184
|
|
|
* @return string|null |
|
185
|
|
|
*/ |
|
186
|
8 |
|
public function getType() |
|
187
|
|
|
{ |
|
188
|
8 |
|
return $this->type; |
|
189
|
|
|
} |
|
190
|
|
|
|
|
191
|
|
|
/** |
|
192
|
|
|
* Mark this widget as absolute. |
|
193
|
|
|
* |
|
194
|
|
|
* @param bool $absolute The absolute value |
|
195
|
|
|
* |
|
196
|
|
|
* @return NumberAndSecondaryStat |
|
197
|
|
|
*/ |
|
198
|
1 |
|
public function setAbsolute($absolute) |
|
199
|
|
|
{ |
|
200
|
1 |
|
$this->absolute = $absolute; |
|
201
|
|
|
|
|
202
|
1 |
|
return $this; |
|
203
|
|
|
} |
|
204
|
|
|
|
|
205
|
|
|
/** |
|
206
|
|
|
* Mark this widget for display main value as time duration (from milliseconds). |
|
207
|
|
|
* |
|
208
|
|
|
* @param boolean $displayAsTimeDuration |
|
209
|
|
|
* |
|
210
|
|
|
* @return NumberAndSecondaryStat |
|
211
|
|
|
*/ |
|
212
|
1 |
|
public function setDisplayAsTimeDuration($displayAsTimeDuration) |
|
213
|
|
|
{ |
|
214
|
1 |
|
$this->displayAsTimeDuration = $displayAsTimeDuration; |
|
215
|
|
|
|
|
216
|
1 |
|
return $this; |
|
217
|
|
|
} |
|
218
|
|
|
|
|
219
|
|
|
/** |
|
220
|
|
|
* {@inheritdoc} |
|
221
|
|
|
*/ |
|
222
|
8 |
|
public function getData() |
|
223
|
|
|
{ |
|
224
|
|
|
$data = array( |
|
225
|
8 |
|
'text' => $this->mainText, |
|
226
|
8 |
|
'value' => (float) $this->getMainValue(), |
|
227
|
8 |
|
); |
|
228
|
|
|
|
|
229
|
8 |
|
$prefix = $this->getMainPrefix(); |
|
230
|
8 |
|
if (null !== $prefix) { |
|
231
|
1 |
|
$data['prefix'] = (string) $prefix; |
|
232
|
1 |
|
} |
|
233
|
|
|
|
|
234
|
8 |
|
if ($this->displayAsTimeDuration) { |
|
235
|
1 |
|
$data['type'] = 'time_duration'; |
|
236
|
1 |
|
} |
|
237
|
|
|
|
|
238
|
|
|
$result = array( |
|
239
|
8 |
|
'item' => array($data), |
|
240
|
8 |
|
'type' => $this->getType(), |
|
241
|
8 |
|
); |
|
242
|
|
|
|
|
243
|
8 |
|
if ($this->absolute) { |
|
244
|
1 |
|
$result['absolute'] = $this->absolute; |
|
245
|
1 |
|
} |
|
246
|
|
|
|
|
247
|
8 |
|
$secondaryValue = $this->getSecondaryValue(); |
|
248
|
8 |
|
if (is_array($secondaryValue)) { |
|
249
|
|
|
$result['item'][] = $secondaryValue; |
|
250
|
8 |
|
} elseif (null !== $secondaryValue) { |
|
251
|
2 |
|
$result['item'][] = array( |
|
252
|
2 |
|
'text' => $this->secondaryText, |
|
253
|
2 |
|
'value' => (float) $secondaryValue, |
|
254
|
|
|
); |
|
255
|
2 |
|
} |
|
256
|
|
|
|
|
257
|
8 |
|
return $result; |
|
258
|
|
|
} |
|
259
|
|
|
} |
|
260
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..