public function Report::group in Forena Reports 8
Same name and namespace in other branches
- 7.5 src/Report.php \Drupal\forena\Report::group()
Iterate the data based on the provided path.
Parameters
string $path: Xpath
string $group: Grouping expression
string $sort: Sort criteria expression
Return value
array grouped array of reows.
File
- src/
Report.php, line 726 - Basic report provider. Controls the rendering of the report.
Class
Namespace
Drupal\forenaCode
public function group($data, $group = '', $sums = array()) {
$rows = array();
$totals = array();
if (is_array($group)) {
$group = implode(' ', $group);
}
$group = (string) $group;
if (is_array($data) || is_object($data)) {
foreach ($data as $row) {
$this
->pushData($row, '_group');
$gval = $this->replacer
->replace($group, TRUE);
foreach ($sums as $sum_col) {
$sval = $this->replacer
->replace($sum_col, FALSE);
$skey = trim($sum_col, '{}');
$totals[$gval][$skey] = isset($totals[$gval][$skey]) ? $totals[$gval][$skey] + (double) $sval : (double) $sval;
}
$this
->popData();
$rows[$gval][] = $row;
}
}
foreach ($totals as $gval => $col) {
foreach ($col as $skey => $total) {
$tkey = $skey . '_total';
$rows[$gval][0]->{$tkey} = (string) $total;
}
}
return $rows;
}