PageRenderTime 43ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/admincrud/extensions/bootstrap/widgets/TbJsonButtonColumn.php

https://github.com/max-rautkin/yii-admincrud
PHP | 71 lines | 38 code | 5 blank | 28 comment | 2 complexity | ed1ed0780dfaff9a0183393e16a89df6 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-3-Clause
  1. <?php
  2. /**
  3. * TbJsonButtonColumn class
  4. * Works in conjunction with TbJsonGridView. Renders HTML or returns JSON according to the request to the Grid.
  5. *
  6. * @author: antonio ramirez <antonio@clevertech.biz>
  7. * @copyright Copyright &copy; Clevertech 2012-
  8. * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
  9. * @package YiiBooster bootstrap.widgets
  10. */
  11. Yii::import('bootstrap.widgets.TbButtonColumn');
  12. /**
  13. * @property TbJsonGridView $grid
  14. */
  15. class TbJsonButtonColumn extends TbButtonColumn
  16. {
  17. /**
  18. * Renders|returns the header cell.
  19. */
  20. public function renderHeaderCell()
  21. {
  22. if ($this->grid->json) {
  23. ob_start();
  24. $this->renderHeaderCellContent();
  25. $content = ob_get_contents();
  26. ob_end_clean();
  27. return array('id' => $this->id, 'content' => $content);
  28. }
  29. parent::renderHeaderCell();
  30. }
  31. /**
  32. * Renders|returns the data cell
  33. *
  34. * @param int $row
  35. *
  36. * @return array|void
  37. */
  38. public function renderDataCell($row)
  39. {
  40. if ($this->grid->json) {
  41. $data = $this->grid->dataProvider->data[$row];
  42. $col = array();
  43. ob_start();
  44. $this->renderDataCellContent($row, $data);
  45. $col['content'] = ob_get_contents();
  46. ob_end_clean();
  47. $col['attrs'] = '';
  48. return $col;
  49. }
  50. parent::renderDataCell($row);
  51. }
  52. /**
  53. * Initializes the default buttons (view, update and delete).
  54. */
  55. protected function initDefaultButtons()
  56. {
  57. parent::initDefaultButtons();
  58. /**
  59. * add custom with msgbox instead
  60. */
  61. $this->buttons['delete']['click'] = strtr(
  62. $this->buttons['delete']['click'],
  63. array('yiiGridView' => 'yiiJsonGridView')
  64. );
  65. }
  66. }