1: <?php
2: 3: 4: 5: 6: 7: 8: 9:
10:
11: Yii::import('bootstrap.helpers.TbHtml');
12: Yii::import('zii.widgets.grid.CButtonColumn');
13:
14: 15: 16:
17: class TbButtonColumn extends CButtonColumn
18: {
19: 20: 21:
22: public $viewButtonIcon = TbHtml::ICON_EYE_OPEN;
23: 24: 25:
26: public $updateButtonIcon = TbHtml::ICON_PENCIL;
27: 28: 29:
30: public $deleteButtonIcon = TbHtml::ICON_TRASH;
31:
32: 33: 34:
35: protected function initDefaultButtons()
36: {
37: parent::initDefaultButtons();
38:
39: if ($this->viewButtonIcon !== false && !isset($this->buttons['view']['icon'])) {
40: $this->buttons['view']['icon'] = $this->viewButtonIcon;
41: }
42: if ($this->updateButtonIcon !== false && !isset($this->buttons['update']['icon'])) {
43: $this->buttons['update']['icon'] = $this->updateButtonIcon;
44: }
45: if ($this->deleteButtonIcon !== false && !isset($this->buttons['delete']['icon'])) {
46: $this->buttons['delete']['icon'] = $this->deleteButtonIcon;
47: }
48: }
49:
50: 51: 52: 53: 54: 55: 56:
57: protected function renderButton($id, $button, $row, $data)
58: {
59: if (isset($button['visible']) && !$this->evaluateExpression(
60: $button['visible'],
61: array('row' => $row, 'data' => $data)
62: )
63: ) {
64: return;
65: }
66:
67: $url = TbArray::popValue('url', $button, '#');
68: if ($url !== '#') {
69: $url = $this->evaluateExpression($url, array('data' => $data, 'row' => $row));
70: }
71:
72: $imageUrl = TbArray::popValue('imageUrl', $button, false);
73: $label = TbArray::popValue('label', $button, $id);
74: $options = TbArray::popValue('options', $button, array());
75:
76: TbArray::defaultValue('title', $label, $options);
77: TbArray::defaultValue('rel', 'tooltip', $options);
78:
79: if ($icon = TbArray::popValue('icon', $button, false)) {
80: echo CHtml::link(TbHtml::icon($icon), $url, $options);
81: } else {
82: if ($imageUrl && is_string($imageUrl)) {
83: echo CHtml::link(CHtml::image($imageUrl, $label), $url, $options);
84: } else {
85: echo CHtml::link($label, $url, $options);
86: }
87: }
88: }
89: }
90: