1
|
|
|
<?php
|
2
|
|
|
/**
|
3
|
|
|
* TbButtonColumn class file.
|
4
|
|
|
* @author Christoffer Niska <[email protected]>
|
5
|
|
|
* @copyright Copyright © Christoffer Niska 2011-
|
6
|
|
|
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
|
7
|
|
|
* @package bootstrap.widgets
|
8
|
|
|
* @since 0.9.8
|
9
|
|
|
*/
|
10
|
|
|
|
11
|
1 |
|
Yii::import('zii.widgets.grid.CButtonColumn');
|
12
|
|
|
|
13
|
|
|
/**
|
14
|
|
|
* Bootstrap button column widget.
|
15
|
|
|
* Used to set buttons to use Glyphicons instead of the defaults images.
|
16
|
|
|
*/
|
17
|
|
|
class TbButtonColumn extends CButtonColumn
|
18
|
|
|
{
|
19
|
|
|
/**
|
20
|
|
|
* @var string the view button icon (defaults to 'eye-open').
|
21
|
|
|
*/
|
22
|
|
|
public $viewButtonIcon = 'eye-open';
|
23
|
|
|
/**
|
24
|
|
|
* @var string the update button icon (defaults to 'pencil').
|
25
|
|
|
*/
|
26
|
|
|
public $updateButtonIcon = 'pencil';
|
27
|
|
|
/**
|
28
|
|
|
* @var string the delete button icon (defaults to 'trash').
|
29
|
|
|
*/
|
30
|
|
|
public $deleteButtonIcon = 'trash';
|
31
|
|
|
|
32
|
|
|
/**
|
33
|
|
|
* Initializes the default buttons (view, update and delete).
|
34
|
|
|
*/
|
35
|
1 |
|
protected function initDefaultButtons()
|
36
|
|
|
{
|
37
|
1 |
|
parent::initDefaultButtons();
|
38
|
|
|
|
39
|
1 |
View Code Duplication |
if ($this->viewButtonIcon !== false && !isset($this->buttons['view']['icon']))
|
|
|
|
|
40
|
1 |
|
$this->buttons['view']['icon'] = $this->viewButtonIcon;
|
41
|
1 |
View Code Duplication |
if ($this->updateButtonIcon !== false && !isset($this->buttons['update']['icon']))
|
|
|
|
|
42
|
1 |
|
$this->buttons['update']['icon'] = $this->updateButtonIcon;
|
43
|
1 |
View Code Duplication |
if ($this->deleteButtonIcon !== false && !isset($this->buttons['delete']['icon']))
|
|
|
|
|
44
|
1 |
|
$this->buttons['delete']['icon'] = $this->deleteButtonIcon;
|
45
|
1 |
|
}
|
46
|
|
|
|
47
|
|
|
/**
|
48
|
|
|
* Renders a link button.
|
49
|
|
|
* @param string $id the ID of the button
|
50
|
|
|
* @param array $button the button configuration which may contain 'label', 'url', 'imageUrl' and 'options' elements.
|
51
|
|
|
* @param integer $row the row number (zero-based)
|
52
|
|
|
* @param mixed $data the data object associated with the row
|
53
|
|
|
*/
|
54
|
|
|
protected function renderButton($id, $button, $row, $data)
|
55
|
|
|
{
|
56
|
|
|
if (isset($button['visible']) && !$this->evaluateExpression($button['visible'], array('row'=>$row, 'data'=>$data)))
|
57
|
|
|
return;
|
58
|
|
|
|
59
|
|
|
$label = isset($button['label']) ? $button['label'] : $id;
|
60
|
|
|
$url = isset($button['url']) ? $this->evaluateExpression($button['url'], array('data'=>$data, 'row'=>$row)) : '#';
|
61
|
|
|
$options = isset($button['options']) ? $button['options'] : array();
|
62
|
|
|
|
63
|
|
|
if (!isset($options['title']))
|
64
|
|
|
$options['title'] = $label;
|
65
|
|
|
|
66
|
|
|
if (!isset($options['rel']))
|
67
|
|
|
$options['rel'] = 'tooltip';
|
68
|
|
|
|
69
|
|
|
if (isset($button['icon']))
|
70
|
|
|
{
|
71
|
|
|
if (strpos($button['icon'], 'icon') === false)
|
72
|
|
|
$button['icon'] = 'icon-'.implode(' icon-', explode(' ', $button['icon']));
|
73
|
|
|
|
74
|
|
|
echo CHtml::link('<i class="'.$button['icon'].'"></i>', $url, $options);
|
75
|
|
|
}
|
76
|
|
View Code Duplication |
else if (isset($button['imageUrl']) && is_string($button['imageUrl']))
|
|
|
|
|
77
|
|
|
echo CHtml::link(CHtml::image($button['imageUrl'], $label), $url, $options);
|
78
|
|
|
else
|
79
|
|
|
echo CHtml::link($label, $url, $options);
|
80
|
|
|
}
|
81
|
|
|
}
|
82
|
|
|
|
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.