Index: branches/5.1.x/core/kernel/db/db_tag_processor.php =================================================================== diff -u -N -r13883 -r13884 --- branches/5.1.x/core/kernel/db/db_tag_processor.php (.../db_tag_processor.php) (revision 13883) +++ branches/5.1.x/core/kernel/db/db_tag_processor.php (.../db_tag_processor.php) (revision 13884) @@ -1,6 +1,6 @@ GetList($params); + $field = $this->SelectParam($params, 'field,name'); + $total_function = array_key_exists('function', $params) ? $params['function'] : $list->getTotalFunction($field); - return $list->GetFormattedTotal($this->SelectParam($params, 'field,name'), $params['function']); + if (array_key_exists('function_only', $params) && $params['function_only']) { + return $total_function; + } + + return $list->GetFormattedTotal($field, $total_function); } /** Index: branches/5.1.x/core/kernel/db/dblist.php =================================================================== diff -u -N -r13882 -r13884 --- branches/5.1.x/core/kernel/db/dblist.php (.../dblist.php) (revision 13882) +++ branches/5.1.x/core/kernel/db/dblist.php (.../dblist.php) (revision 13884) @@ -1,6 +1,6 @@ PerPage = -1; } + function setGridName($grid_name) + { + $this->gridName = $grid_name; + } + /** * Returns information about all possible filter types * @@ -410,19 +422,32 @@ function CalculateTotals() { + $fields = Array(); $this->Totals = Array(); - $fields = Array(); - foreach($this->Fields as $field_name => $field_options) - { - $totals = getArrayValue($field_options, 'totals'); - if(!$totals) continue; + if ($this->gridName) { + $grids = $this->Application->getUnitOption($this->Prefix, 'Grids'); + $grid_fields = $grids[$this->gridName]['Fields']; + } + else { + $grid_fields = $this->Fields; + } - $calculated_field = isset($this->CalculatedFields[$field_name]) && isset($this->VirtualFields[$field_name]); - $db_field = !isset($this->VirtualFields[$field_name]); + foreach ($grid_fields as $field_name => $field_options) { + if ($this->gridName && array_key_exists('totals', $field_options) && $field_options['totals']) { + $totals = $field_options['totals']; + } + elseif (array_key_exists('totals', $this->Fields[$field_name]) && $this->Fields[$field_name]['totals']) { + $totals = $this->Fields[$field_name]['totals']; + } + else { + continue; + } - if($calculated_field || $db_field) - { + $calculated_field = array_key_exists($field_name, $this->CalculatedFields) && array_key_exists($field_name, $this->VirtualFields); + $db_field = !array_key_exists($field_name, $this->VirtualFields); + + if ($calculated_field || $db_field) { $field_expression = $calculated_field ? $this->CalculatedFields[$field_name] : '`'.$this->TableName.'`.`'.$field_name.'`'; $fields[$field_name] = $totals.'('.$field_expression.') AS '.$field_name.'_'.$totals; } @@ -457,10 +482,33 @@ function getTotal($field, $total_function) { - if (!$this->TotalsCalculated) $this->CalculateTotals(); - return $this->Totals[$field.'_'.$total_function]; + if (!$this->TotalsCalculated) { + $this->CalculateTotals(); + } + + return $this->Totals[$field . '_' . $total_function]; } + function getTotalFunction($field) + { + if ($this->gridName) { + $grids = $this->Application->getUnitOption($this->Prefix, 'Grids'); + $field_options = $grids[$this->gridName]['Fields'][$field]; + } + else { + $field_options = $this->Fields[$field]; + } + + if ($this->gridName && array_key_exists('totals', $field_options) && $field_options['totals']) { + return $field_options['totals']; + } + elseif (array_key_exists('totals', $this->Fields[$field]) && $this->Fields[$field]['totals']) { + return $this->Fields[$field]['totals']; + } + + return false; + } + function GetFormattedTotal($field, $total_function) { $val = $this->getTotal($field, $total_function); Index: branches/5.1.x/core/kernel/db/db_event_handler.php =================================================================== diff -u -N -r13782 -r13884 --- branches/5.1.x/core/kernel/db/db_event_handler.php (.../db_event_handler.php) (revision 13782) +++ branches/5.1.x/core/kernel/db/db_event_handler.php (.../db_event_handler.php) (revision 13884) @@ -1,6 +1,6 @@ mainList = true; } + $object->setGridName( $event->getEventParam('grid') ); + $sql = $this->ListPrepareQuery($event); $sql = $this->Application->ReplaceLanguageTags($sql); $object->setSelectSQL($sql); Index: branches/5.1.x/core/admin_templates/incs/grid_blocks.tpl =================================================================== diff -u -N -r13883 -r13884 --- branches/5.1.x/core/admin_templates/incs/grid_blocks.tpl (.../grid_blocks.tpl) (revision 13883) +++ branches/5.1.x/core/admin_templates/incs/grid_blocks.tpl (.../grid_blocks.tpl) (revision 13884) @@ -188,9 +188,8 @@ - - - + +