HCE Project DC service web UI  0.2
Hierarchical Cluster Engine DC service web UI
 All Classes Namespaces Files Functions Variables Pages
TbProgress.php
Go to the documentation of this file.
1 <?php
9 Yii::import('booster.widgets.TbWidget');
18 class TbProgress extends TbWidget {
19 
23  public $striped = false;
24 
28  public $animated = false;
29 
33  public $percent = 0;
34 
38  public $htmlOptions = array();
39 
43  public $content;
44 
55  public $stacked;
56 
57  protected $progressClasses = array('progress');
58  protected $progressBarClasses = array('progress-bar');
59 
65  public function init() {
66 
67  if ($this->isValidContext())
68  $this->progressBarClasses[] = 'progress-bar-' . $this->getContextClass();
69 
70  if ($this->striped)
71  $this->progressClasses[] = 'progress-striped';
72 
73  if ($this->animated)
74  $this->progressClasses[] = 'active';
75 
76  if ($this->percent < 0)
77  $this->percent = 0;
78  else if ($this->percent > 100)
79  $this->percent = 100;
80 
81  if (!empty($this->progressClasses)) {
82  $this->progressClasses = implode(' ', $this->progressClasses);
83  if (isset($this->htmlOptions['class'])) {
84  $this->htmlOptions['class'] .= ' ' . $this->progressClasses;
85  } else {
86  $this->htmlOptions['class'] = $this->progressClasses;
87  }
88  }
89  }
90 
98  public function run() {
99 
100  echo CHtml::openTag('div', $this->htmlOptions);
101  if (empty($this->stacked)) {
102  echo '<div class="'.implode(' ', $this->progressBarClasses).'" style="width: ' . $this->percent . '%;">' . $this->content . '</div>';
103  } elseif (is_array($this->stacked)) {
104  foreach ($this->stacked as $bar) {
105  $options = isset($bar['htmlOptions']) ? $bar['htmlOptions'] : array();
106  if (empty($options['style'])) {
107  $options['style'] = '';
108  } else {
109  $options['style'] .= ' ';
110  }
111  $options['style'] .= 'width: ' . $bar['percent'] . '%';
112 
113  if (empty($options['class'])) {
114  $options['class'] = '';
115  } else {
116  $options['style'] .= ' ';
117  }
118  $options['class'] .= 'progress-bar progress-bar-' . $bar['context'];
119 
120  echo '<div ' . CHtml::renderAttributes($options) . '>' . @$bar['content'] . '</div>';
121  }
122  }
123  echo CHtml::closeTag('div');
124  }
125 
126  protected function isValidContext($context = false) {
127  return in_array($this->context, [
128  self::CTX_SUCCESS,
129  self::CTX_INFO,
130  self::CTX_WARNING,
131  self::CTX_DANGER
132  ]);
133  }
134 }