1 <?php
2 3 4 5 6 7
8 namespace foundation\helpers;
9
10 use foundation\enum\Enum;
11
12 13 14 15 16 17
18 class Progress
19 {
20 21 22 23 24 25
26 public static function success($percent, $htmlOptions = array())
27 {
28 ArrayHelper::addValue('class', Enum::COLOR_SUCCESS, $htmlOptions);
29 return static::bar($percent, $htmlOptions);
30 }
31
32 public static function important($percent, $htmlOptions = array())
33 {
34 ArrayHelper::addValue('class', Enum::COLOR_ALERT, $htmlOptions);
35 return static::bar($percent, $htmlOptions);
36 }
37
38 public static function secondary($percent, $htmlOptions = array())
39 {
40 ArrayHelper::addValue('class', Enum::COLOR_SECONDARY, $htmlOptions);
41 return static::bar($percent, $htmlOptions);
42 }
43
44 public static function bar($percent, $htmlOptions = array())
45 {
46 $percent = substr(trim($percent), -1) !== '%'
47 ? $percent . '%'
48 : $percent;
49
50 ArrayHelper::addValue('class', Enum::PROGRESS, $htmlOptions);
51 ob_start();
52 echo \CHtml::openTag('div', $htmlOptions);
53 echo \CHtml::openTag('span', array('class' => Enum::PROGRESS_METER, 'style' => 'width:' . $percent));
54 echo \CHtml::closeTag('span');
55 echo \CHtml::closeTag('div');
56 return ob_get_clean();
57 }
58 }