You are here

public function Report::group in Forena Reports 7.5

Same name and namespace in other branches
  1. 8 src/Report.php \Drupal\forena\Report::group()

Iterate the data based on the provided path.

Parameters

$path xpath to iterate xml on:

$group grouping value:

$sort Sort criteria:

File

src/Report.php, line 766
Basic report provider. Controls the rendering of the report.

Class

Report

Namespace

Drupal\forena

Code

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) {
      Frx::Data()
        ->push($row, '_group');
      $gval = $this->teng
        ->replace($group, TRUE);
      foreach ($sums as $sum_col) {
        $sval = $this->teng
          ->replace($sum_col, FALSE);
        $skey = trim($sum_col, '{}');
        $totals[$gval][$skey] = isset($totals[$gval][$skey]) ? $totals[$gval][$skey] + $sval : (double) $sval;
      }
      Frx::Data()
        ->pop();
      $rows[$gval][] = $row;
    }
  }
  foreach ($totals as $gval => $col) {
    foreach ($col as $skey => $total) {
      $tkey = $skey . '_total';
      $rows[$gval][0]->{$tkey} = (string) $total;
    }
  }
  return $rows;
}