Advertisement
fernandezekiel

tbtotalsumcolumn

Jan 28th, 2013
371
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.23 KB | None | 0 0
  1. <?php
  2. /**
  3.  * TbTotalSumColumn widget class
  4.  *
  5.  * @author: antonio ramirez <antonio@clevertech.biz>
  6.  * @copyright Copyright &copy; Clevertech 2012-
  7.  * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
  8.  * @package YiiBooster bootstrap.widgets
  9.  */
  10. Yii::import('bootstrap.widgets.TbDataColumn');
  11.  
  12. class TbTotalSumColumn extends TbDataColumn
  13. {
  14.     public $totalExpression;
  15.  
  16.     public $totalValue;
  17.  
  18.     protected $total;
  19.  
  20.     public function init()
  21.     {
  22.         parent::init();
  23.  
  24.         if (!is_null($this->totalExpression))
  25.         {
  26.             $this->total = is_numeric($this->totalExpression) ? $this->totalExpression : $this->evaluateExpression($this->totalExpression);
  27.         }
  28.         $this->footer = true;
  29.     }
  30.  
  31.     protected function renderDataCellContent($row, $data)
  32.     {
  33.         ob_start();
  34.         parent::renderDataCellContent($row, $data);
  35.         $value = ob_get_clean();
  36.  
  37.         if(is_numeric($value))
  38.         {
  39.             $this->total += $value;
  40.         }
  41.         echo $value;
  42.     }
  43.  
  44.     protected function renderFooterCellContent()
  45.     {
  46.         if(is_null($this->total))
  47.             return parent::renderFooterCellContent();
  48.  
  49.         echo $this->totalValue? $this->evaluateExpression($this->totalValue, array('total'=>$this->total)) : $this->grid->getFormatter()->format($this->total, $this->type);
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement