HCE Project DC service web UI  0.2
Hierarchical Cluster Engine DC service web UI
 All Classes Namespaces Files Functions Variables Pages
TbButtonGroupColumn.php
Go to the documentation of this file.
1 <?php
10 Yii::import('booster.widgets.TbButtonColumn');
11 
20 
24  public $buttonSize = 'mini';
25 
29  public $viewButtonContext = 'info';
30 
34  public $updateButtonContext = 'warning';
35 
39  public $deleteButtonContext = 'danger';
40 
46  protected function initDefaultButtons() {
47 
49 
50  if ($this->viewButtonContext !== false && !isset($this->buttons['view']['context'])) {
51  $this->buttons['view']['context'] = $this->viewButtonContext;
52  }
53  if ($this->updateButtonContext !== false && !isset($this->buttons['update']['context'])) {
54  $this->buttons['update']['context'] = $this->updateButtonContext;
55  }
56  if ($this->deleteButtonContext !== false && !isset($this->buttons['delete']['context'])) {
57  $this->buttons['delete']['context'] = $this->deleteButtonContext;
58  }
59  }
60 
61 
72  protected function renderButton($id, $button, $row, $data) {
73 
74  if (isset($button['visible']) && !$this->evaluateExpression(
75  $button['visible'],
76  array('row' => $row, 'data' => $data)
77  )
78  ) {
79  return;
80  }
81 
82  $label = isset($button['label']) ? $button['label'] : $id;
83  $url = isset($button['url']) ? $this->evaluateExpression($button['url'], array('data' => $data, 'row' => $row))
84  : '#';
85  $options = isset($button['options']) ? $button['options'] : array();
86 
87  if (!isset($options['title'])) {
88  $options['title'] = $label;
89  }
90 
91  if (!isset($options['data-toggle'])) {
92  $options['data-toggle'] = 'tooltip';
93  }
94 
95  if (!isset($options['class'])) {
96  $options['class'] = '';
97  }
98  $options['class'] .= ' btn btn-' . $this->buttonSize;
99  if (isset($button['context'])) {
100  $options['class'] .= ' btn-' . $button['context'];
101  }
102 
103  if (isset($button['icon'])) {
104  if (strpos($button['icon'], 'icon') === false && strpos($button['icon'], 'fa') === false) {
105  $button['icon'] = 'icon-' . implode(' icon-', explode(' ', $button['icon']));
106  }
107 
108  echo CHtml::link('<i class="' . $button['icon'] . '"></i>', $url, $options);
109  } else if (isset($button['imageUrl']) && is_string($button['imageUrl'])) {
110  echo CHtml::link(CHtml::image($button['imageUrl'], $label), $url, $options);
111  } else {
112  echo CHtml::link($label, $url, $options);
113  }
114  }
115 
125  protected function renderDataCellContent($row, $data)
126  {
127  $tr = array();
128  ob_start();
129  foreach ($this->buttons as $id => $button) {
130  $this->renderButton($id, $button, $row, $data);
131  $tr['{' . $id . '}'] = ob_get_contents();
132  ob_clean();
133  }
134  ob_end_clean();
135  echo "<div class='btn-group'>" . strtr($this->template, $tr) . "</div>";
136  }
137 }