Overview

Packages

  • bootstrap
    • behaviors
    • components
    • form
    • gii
    • helpers
    • widgets

Classes

  • TbActiveForm
  • TbAffix
  • TbAlert
  • TbBreadcrumb
  • TbButtonColumn
  • TbCollapse
  • TbDataColumn
  • TbDetailView
  • TbGridView
  • TbHeroUnit
  • TbListView
  • TbModal
  • TbNav
  • TbNavbar
  • TbPager
  • TbScrollspy
  • TbTabs
  • TbThumbnails
  • TbTypeAhead
  • Overview
  • Package
  • Class
  • Tree
 1: <?php
 2: /**
 3:  * TbButtonColumn class file.
 4:  * @author Antonio Ramirez <ramirez.cobos@gmail.com>
 5:  * @author Christoffer Niska <ChristofferNiska@gmail.com>
 6:  * @copyright Copyright &copy; Christoffer Niska 2013-
 7:  * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
 8:  * @package bootstrap.widgets
 9:  */
10: 
11: Yii::import('bootstrap.helpers.TbHtml');
12: Yii::import('zii.widgets.grid.CButtonColumn');
13: 
14: /**
15:  * Bootstrap button column widget.
16:  */
17: class TbButtonColumn extends CButtonColumn
18: {
19:     /**
20:      * @var string the view button icon (defaults to TbHtml::ICON_EYE_OPEN).
21:      */
22:     public $viewButtonIcon = TbHtml::ICON_EYE_OPEN;
23:     /**
24:      * @var string the update button icon (defaults to TbHtml::ICON_PENCIL).
25:      */
26:     public $updateButtonIcon = TbHtml::ICON_PENCIL;
27:     /**
28:      * @var string the delete button icon (defaults to TbHtml::ICON_TRASH).
29:      */
30:     public $deleteButtonIcon = TbHtml::ICON_TRASH;
31: 
32:     /**
33:      * Initializes the default buttons (view, update and delete).
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:      * Renders a link button.
52:      * @param string $id the ID of the button
53:      * @param array $button the button configuration which may contain 'label', 'url', 'imageUrl' and 'options' elements.
54:      * @param integer $row the row number (zero-based)
55:      * @param mixed $data the data object associated with the row
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: 
Yiistrap API documentation generated by ApiGen 2.8.0