PageRenderTime 48ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/admincrud/extensions/bootstrap/widgets/TbGroupButtonColumn.php

https://github.com/max-rautkin/yii-admincrud
PHP | 85 lines | 49 code | 9 blank | 27 comment | 9 complexity | 1ddfef2c466b78b76ef9cb6075cdbac4 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-3-Clause
  1. <?php
  2. /**
  3. * TbGroupButtonColumn class file.
  4. * @author Lushnikov Alexander <alexander.aka.alegz@gmail.com>
  5. * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
  6. * @package bootstrap.widgets
  7. * @since 0.9.8
  8. */
  9. Yii::import('zii.widgets.grid.CButtonColumn');
  10. /**
  11. * Bootstrap button column widget.
  12. * Used to set buttons group.
  13. */
  14. class TbGroupButtonColumn extends CButtonColumn
  15. {
  16. /**
  17. * Renders a link button.
  18. *
  19. * @param string $id the ID of the button
  20. * @param array $button the button configuration which may contain 'label', 'url', 'imageUrl' and 'options' elements.
  21. * @param integer $row the row number (zero-based)
  22. * @param mixed $data the data object associated with the row
  23. */
  24. protected function renderButton($id, $button, $row, $data)
  25. {
  26. if (isset($button['visible']) && !$this->evaluateExpression(
  27. $button['visible'],
  28. array('row' => $row, 'data' => $data)
  29. )
  30. ) {
  31. return;
  32. }
  33. $label = isset($button['label']) ? $button['label'] : $id;
  34. $url = isset($button['url']) ? $this->evaluateExpression($button['url'], array('data' => $data, 'row' => $row))
  35. : '#';
  36. $options = isset($button['options']) ? $button['options'] : array();
  37. if (!isset($options['title'])) {
  38. $options['title'] = $label;
  39. }
  40. //Forsing btn class
  41. if (!isset($options['class'])) {
  42. $options['class'] = 'btn';
  43. } else if (!preg_match('/[^A-z\-]btn[^A-z\-]/', $options['class'])) {
  44. $options['class'] = 'btn ' . $options['class'];
  45. }
  46. if (isset($button['icon'])) {
  47. if (strpos($button['icon'], 'icon') === false) {
  48. $button['icon'] = 'icon-' . implode(' icon-', explode(' ', $button['icon']));
  49. }
  50. echo CHtml::link('<i class="' . $button['icon'] . '"></i>', $url, $options);
  51. } else {
  52. echo CHtml::link($label, $url, $options);
  53. }
  54. }
  55. /**
  56. * Renders the data cell content.
  57. * This method renders the view, update and delete buttons in the data cell.
  58. *
  59. * @param integer $row the row number (zero-based)
  60. * @param mixed $data the data associated with the row
  61. */
  62. protected function renderDataCellContent($row, $data)
  63. {
  64. $tr = array();
  65. ob_start();
  66. foreach ($this->buttons as $id => $button) {
  67. $this->renderButton($id, $button, $row, $data);
  68. $tr['{' . $id . '}'] = ob_get_contents();
  69. ob_clean();
  70. }
  71. ob_end_clean();
  72. echo '<div class="btn-group">';
  73. echo strtr($this->template, $tr);
  74. echo '</div>';
  75. }
  76. }