|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace CarlosIO\Geckoboard\Widgets; |
|
4
|
|
|
|
|
5
|
|
|
use CarlosIO\Geckoboard\Data\Entry; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Class GeckoMeter. |
|
9
|
|
|
*/ |
|
10
|
|
|
class GeckoMeter extends Widget |
|
11
|
|
|
{ |
|
12
|
|
|
protected $dataset; |
|
13
|
|
|
protected $value; |
|
14
|
|
|
protected $reversed = false; |
|
15
|
|
|
|
|
16
|
5 |
|
public function __construct() |
|
17
|
|
|
{ |
|
18
|
5 |
|
$this->dataset = array(); |
|
19
|
5 |
|
} |
|
20
|
|
|
|
|
21
|
2 |
|
public function setReversed($reversed) |
|
22
|
|
|
{ |
|
23
|
2 |
|
$this->reversed = $reversed; |
|
24
|
|
|
|
|
25
|
2 |
|
return $this; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
2 |
|
public function getReversed() |
|
29
|
|
|
{ |
|
30
|
2 |
|
return $this->reversed; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @param $value |
|
35
|
|
|
* |
|
36
|
|
|
* @return $this |
|
37
|
|
|
*/ |
|
38
|
2 |
|
public function setValue($value) |
|
39
|
|
|
{ |
|
40
|
2 |
|
$this->value = $value; |
|
41
|
|
|
|
|
42
|
2 |
|
return $this; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
2 |
|
public function getValue() |
|
46
|
|
|
{ |
|
47
|
2 |
|
return $this->value; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
3 |
|
public function getMinData() |
|
51
|
|
|
{ |
|
52
|
3 |
|
return $this->getEntry('min'); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
2 |
|
public function setMinData(Entry $entry) |
|
56
|
|
|
{ |
|
57
|
2 |
|
$this->setEntry('min', $entry); |
|
58
|
|
|
|
|
59
|
2 |
|
return $this; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
2 |
|
public function getMaxData() |
|
63
|
|
|
{ |
|
64
|
2 |
|
return $this->getEntry('max'); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
2 |
|
public function setMaxData(Entry $entry) |
|
68
|
|
|
{ |
|
69
|
2 |
|
$this->setEntry('max', $entry); |
|
70
|
|
|
|
|
71
|
2 |
|
return $this; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
1 |
|
public function getData() |
|
75
|
|
|
{ |
|
76
|
|
|
$result = array( |
|
77
|
1 |
|
'item' => $this->getValue(), |
|
78
|
1 |
|
'max' => $this->getMaxData()->toArray(), |
|
79
|
1 |
|
'min' => $this->getMinData()->toArray(), |
|
80
|
1 |
|
); |
|
81
|
|
|
|
|
82
|
1 |
|
if ($this->getReversed()) { |
|
83
|
1 |
|
$result['type'] = 'reversed'; |
|
84
|
1 |
|
} |
|
85
|
|
|
|
|
86
|
1 |
|
return $result; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
2 |
|
protected function setEntry($level, $entry) |
|
90
|
|
|
{ |
|
91
|
2 |
|
$this->dataset[$level] = $entry; |
|
92
|
|
|
|
|
93
|
2 |
|
return $this; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
3 |
|
protected function getEntry($level) |
|
97
|
|
|
{ |
|
98
|
3 |
|
if (!isset($this->dataset[$level])) { |
|
99
|
1 |
|
throw new \Exception('Type entry does not exist'); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
2 |
|
return $this->dataset[$level]; |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
|