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
|
|
|
* Set data main prefix (€, $, etc.). |
47
|
|
|
* |
48
|
|
|
* @param string $mainPrefix |
49
|
|
|
* |
50
|
|
|
* @return $this |
51
|
|
|
*/ |
52
|
1 |
|
public function setMainPrefix($mainPrefix) |
53
|
|
|
{ |
54
|
1 |
|
$this->mainPrefix = $mainPrefix; |
|
|
|
|
55
|
|
|
|
56
|
1 |
|
return $this; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Get data main prefix (€, $, etc.). |
61
|
|
|
* |
62
|
|
|
* @return string |
63
|
|
|
*/ |
64
|
7 |
|
public function getMainPrefix() |
65
|
|
|
{ |
66
|
7 |
|
return $this->mainPrefix; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Set main value. |
71
|
|
|
* |
72
|
|
|
* @param int $mainValue |
73
|
|
|
* |
74
|
|
|
* @return $this |
75
|
|
|
*/ |
76
|
3 |
|
public function setMainValue($mainValue) |
77
|
|
|
{ |
78
|
3 |
|
$this->mainValue = $mainValue; |
|
|
|
|
79
|
|
|
|
80
|
3 |
|
return $this; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Get main value. |
85
|
|
|
* |
86
|
|
|
* @return int |
87
|
|
|
*/ |
88
|
7 |
|
public function getMainValue() |
89
|
|
|
{ |
90
|
7 |
|
return $this->mainValue; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Set the primary text value. (Visible if widget is 2x2 |
95
|
|
|
* or 1x1 without a secondary value). |
96
|
|
|
* |
97
|
|
|
* @param string $mainText The text body |
98
|
|
|
* |
99
|
|
|
* @return NumberAndSecondaryStat |
100
|
|
|
*/ |
101
|
1 |
|
public function setMainText($mainText) |
102
|
|
|
{ |
103
|
1 |
|
$this->mainText = $mainText; |
104
|
|
|
|
105
|
1 |
|
return $this; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Return the main text body. |
110
|
|
|
* |
111
|
|
|
* @return string |
112
|
|
|
*/ |
113
|
1 |
|
public function getMainText() |
114
|
|
|
{ |
115
|
1 |
|
return $this->mainText; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Set secondary value. |
120
|
|
|
* |
121
|
|
|
* @param int $secondaryValue |
122
|
|
|
* |
123
|
|
|
* @return $this |
124
|
|
|
*/ |
125
|
2 |
|
public function setSecondaryValue($secondaryValue) |
126
|
|
|
{ |
127
|
2 |
|
$this->secondaryValue = $secondaryValue; |
|
|
|
|
128
|
|
|
|
129
|
2 |
|
return $this; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* Get secondary value. |
134
|
|
|
* |
135
|
|
|
* @return string |
136
|
|
|
*/ |
137
|
7 |
|
public function getSecondaryValue() |
138
|
|
|
{ |
139
|
7 |
|
return $this->secondaryValue; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* Set the secondary text value. (Visible if widget is 2x2). |
144
|
|
|
* |
145
|
|
|
* @param string $secondaryText The text body |
146
|
|
|
* |
147
|
|
|
* @return NumberAndSecondaryStat |
148
|
|
|
*/ |
149
|
1 |
|
public function setSecondaryText($secondaryText) |
150
|
|
|
{ |
151
|
1 |
|
$this->secondaryText = $secondaryText; |
152
|
|
|
|
153
|
1 |
|
return $this; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* Return the secondary text body. |
158
|
|
|
* |
159
|
|
|
* @return string |
160
|
|
|
*/ |
161
|
1 |
|
public function getSecondaryText() |
162
|
|
|
{ |
163
|
1 |
|
return $this->secondaryText; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* @param string|null $prefix |
168
|
|
|
* |
169
|
|
|
* @return $this |
170
|
|
|
*/ |
171
|
1 |
|
public function setType($prefix) |
172
|
|
|
{ |
173
|
1 |
|
$this->type = $prefix; |
|
|
|
|
174
|
|
|
|
175
|
1 |
|
return $this; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* @return string|null |
180
|
|
|
*/ |
181
|
7 |
|
public function getType() |
182
|
|
|
{ |
183
|
7 |
|
return $this->type; |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* Mark this widget as absolute. |
188
|
|
|
* |
189
|
|
|
* @param bool $absolute The absolute value |
190
|
|
|
* |
191
|
|
|
* @return NumberAndSecondaryStat |
192
|
|
|
*/ |
193
|
1 |
|
public function setAbsolute($absolute) |
194
|
|
|
{ |
195
|
1 |
|
$this->absolute = $absolute; |
196
|
|
|
|
197
|
1 |
|
return $this; |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* {@inheritdoc} |
202
|
|
|
*/ |
203
|
7 |
|
public function getData() |
204
|
|
|
{ |
205
|
|
|
$data = array( |
206
|
7 |
|
'text' => $this->mainText, |
207
|
7 |
|
'value' => (float) $this->getMainValue(), |
208
|
|
|
); |
209
|
|
|
|
210
|
7 |
|
$prefix = $this->getMainPrefix(); |
211
|
7 |
|
if (null !== $prefix) { |
212
|
1 |
|
$data['prefix'] = (string) $prefix; |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
$result = array( |
216
|
7 |
|
'item' => array($data), |
217
|
7 |
|
'type' => $this->getType(), |
218
|
|
|
); |
219
|
|
|
|
220
|
7 |
|
if ($this->absolute) { |
221
|
1 |
|
$result['absolute'] = $this->absolute; |
222
|
|
|
} |
223
|
|
|
|
224
|
7 |
|
$secondaryValue = $this->getSecondaryValue(); |
225
|
7 |
|
if (is_array($secondaryValue)) { |
226
|
|
|
$result['item'][] = $secondaryValue; |
227
|
7 |
|
} elseif (null !== $secondaryValue) { |
228
|
2 |
|
$result['item'][] = array( |
229
|
2 |
|
'text' => $this->secondaryText, |
230
|
2 |
|
'value' => (float) $secondaryValue, |
231
|
|
|
); |
232
|
|
|
} |
233
|
|
|
|
234
|
7 |
|
return $result; |
235
|
|
|
} |
236
|
|
|
} |
237
|
|
|
|
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..