1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ajax\bootstrap\html; |
4
|
|
|
|
5
|
|
|
use Ajax\bootstrap\html\base\HtmlBsDoubleElement; |
6
|
|
|
use Ajax\JsUtils; |
7
|
|
|
|
8
|
|
|
use Ajax\bootstrap\html\base\CssRef; |
9
|
|
|
use Ajax\service\JArray; |
10
|
|
|
|
11
|
|
|
class HtmlProgressbar extends HtmlBsDoubleElement { |
12
|
|
|
protected $value; |
13
|
|
|
protected $max; |
14
|
|
|
protected $min; |
15
|
|
|
protected $striped=""; |
16
|
|
|
protected $active; |
17
|
|
|
protected $caption; |
18
|
|
|
protected $stacked=false; |
19
|
|
|
protected $style=""; |
20
|
|
|
protected $styleLimits=null; |
21
|
|
|
|
22
|
|
|
public function __construct($identifier, $style="info", $value=0, $max=100, $min=0) { |
23
|
|
|
parent::__construct($identifier); |
24
|
|
|
$this->_template=include 'templates/tplProgressbar.php'; |
25
|
|
|
$this->value=$value; |
26
|
|
|
$this->min=$min; |
27
|
|
|
$this->max=$max; |
28
|
|
|
$this->setStyle($style); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
View Code Duplication |
public function setActive($value) { |
|
|
|
|
32
|
|
|
if(\is_array($this->content)){ |
33
|
|
|
foreach ($this->content as $pb){ |
34
|
|
|
$pb->setActive($value); |
35
|
|
|
} |
36
|
|
|
}else{ |
37
|
|
|
if ($value===true) |
38
|
|
|
$this->active="active"; |
39
|
|
|
else |
40
|
|
|
$this->active=""; |
41
|
|
|
} |
42
|
|
|
return $this; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function setStriped($value) { |
46
|
|
|
if(\is_array($this->content)){ |
47
|
|
|
foreach ($this->content as $pb){ |
48
|
|
|
$pb->setStriped($value); |
49
|
|
|
} |
50
|
|
|
}else{ |
51
|
|
|
if ($value===true) |
52
|
|
|
$this->striped="progress-bar-striped"; |
53
|
|
|
else |
54
|
|
|
$this->striped=""; |
55
|
|
|
} |
56
|
|
|
return $this; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
View Code Duplication |
public function showCaption($value) { |
|
|
|
|
60
|
|
|
if(\is_array($this->content)){ |
61
|
|
|
foreach ($this->content as $pb){ |
62
|
|
|
$pb->showCaption($value); |
63
|
|
|
} |
64
|
|
|
}else{ |
65
|
|
|
if ($value===true) |
66
|
|
|
$this->caption="%value%%"; |
67
|
|
|
else |
68
|
|
|
$this->caption='<span class="sr-only">%value%% Complete (%style%)</span>'; |
69
|
|
|
} |
70
|
|
|
return $this; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function getValue() { |
74
|
|
|
return $this->value; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function stack(HtmlProgressbar $progressBar) { |
78
|
|
|
$this->_template='%content%'; |
79
|
|
|
$progressBar->setStacked(true); |
80
|
|
|
$progressBar->showCaption($this->caption=="%value%%"); |
81
|
|
|
$progressBar->setStriped($this->striped!=="" || $progressBar->isStriped()); |
82
|
|
|
$progressBar->setActive($this->active==="active" || $progressBar->isActive()); |
83
|
|
|
if (!is_array($this->content)) { |
84
|
|
|
$this->content=array (); |
85
|
|
|
} |
86
|
|
|
$this->content []=$progressBar; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function setValue($value) { |
90
|
|
|
$this->value=$value; |
91
|
|
|
return $this; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public function getMax() { |
95
|
|
|
return $this->max; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function setMax($max) { |
99
|
|
|
$this->max=$max; |
100
|
|
|
return $this; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
public function getMin() { |
104
|
|
|
return $this->min; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
public function setMin($min) { |
108
|
|
|
$this->min=$min; |
109
|
|
|
return $this; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
public function getStacked() { |
113
|
|
|
return $this->stacked; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
public function setStacked($stacked) { |
117
|
|
|
$this->stacked=$stacked; |
118
|
|
|
return $this; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* define the progressbar style |
123
|
|
|
* avaible values : "success","info","warning","danger" |
124
|
|
|
* @param string|int $cssStyle |
125
|
|
|
* @return \Ajax\bootstrap\html\HtmlProgressbar default : "" |
126
|
|
|
*/ |
127
|
|
|
public function setStyle($cssStyle) { |
128
|
|
|
return $this->setMemberCtrl($this->style,CssRef::getStyle($cssStyle, "progress-bar"), CssRef::Styles("progress-bar")); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/* |
132
|
|
|
* (non-PHPdoc) |
133
|
|
|
* @see \Ajax\bootstrap\html\base\BaseHtml::compile() |
134
|
|
|
*/ |
135
|
|
|
public function compile(JsUtils $js=NULL, &$view=NULL) { |
136
|
|
|
$actualStyle=$this->style; |
137
|
|
|
if(isset($this->styleLimits)&& JArray::isAssociative($this->styleLimits)){ |
138
|
|
|
foreach ($this->styleLimits as $k=>$v){ |
139
|
|
|
$actualStyle=$k; |
140
|
|
|
if($v>$this->value) |
141
|
|
|
break; |
142
|
|
|
} |
143
|
|
|
} |
144
|
|
|
$this->style=$actualStyle; |
145
|
|
|
$this->_template=str_replace("%caption%", $this->caption, $this->_template); |
146
|
|
|
if ($this->getStacked()===false) { |
147
|
|
|
$this->wrap('<div class="progress">', '</div>'); |
148
|
|
|
} |
149
|
|
|
return parent::compile($js, $view); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
public function isStriped() { |
153
|
|
|
return $this->striped; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
public function isActive() { |
157
|
|
|
return $this->active; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/* (non-PHPdoc) |
161
|
|
|
* @see \Ajax\bootstrap\html\base\BaseHtml::fromDatabaseObject() |
162
|
|
|
*/ |
163
|
|
|
public function fromDatabaseObject($object, $function) { |
164
|
|
|
$this->stack($function($object)); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
public function getStyleLimits() { |
168
|
|
|
return $this->styleLimits; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* Permet de modifier le style de la progressbar à partir de sa valeur actuelle |
173
|
|
|
* $styleLimits est de la forme ["success"=>50, "warning"=>100] pour obtenir un style success de 0 à 50 et warning de 50 à 100 |
174
|
|
|
* @param array $styleLimits tableau associatif des couples style=>valeur possibles |
175
|
|
|
* @return \Ajax\bootstrap\html\HtmlProgressbar |
176
|
|
|
*/ |
177
|
|
|
public function setStyleLimits($styleLimits) { |
178
|
|
|
$this->styleLimits=$styleLimits; |
179
|
|
|
return $this; |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
} |
183
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.