You are here

public function FrxCrosstab::scrapeConfig in Forena Reports 8

Extract table configuration from the HTML

Overrides TemplateInterface::scrapeConfig

See also

FrxRenderer::scrapeConfig()

File

src/FrxPlugin/Template/FrxCrosstab.php, line 175

Class

FrxCrosstab
Crosstab Report Template

Namespace

Drupal\forena\Template

Code

public function scrapeConfig(\SimpleXMLElement $xml) {
  $this->weight = 0;
  $config = array();
  $nodes = $this->reportDocNode
    ->xpath('//table');
  if ($nodes) {
    $table = $nodes[0];
    $attrs = $this
      ->mergedAttributes($table);
  }
  $config['group'] = $group = $attrs['group'];
  $config['dim'] = $dim = $attrs['dim'];
  $this
    ->extractTemplateHTML($this->reportDocDomNode, $config, array(
    'table',
  ));
  $head_ths = $this
    ->extractXPathInnerHTML('*//thead/tr/th', $this->reportDocDomNode, FALSE);
  $head_tds = $this
    ->extractXPathInnerHTML('*//thead/tr/td', $this->reportDocDomNode, FALSE);
  $body_ths = $this
    ->extractXPathInnerHTML('*//tbody/tr/th', $this->reportDocDomNode, FALSE);
  $body_tds = $this
    ->extractXPathInnerHTML('*//tbody/tr/td', $this->reportDocDomNode, FALSE);
  $heading_cols = array_combine($head_ths, $body_ths);
  $data_cols = array_combine($head_tds, $body_tds);

  // Get the named headers
  foreach ($heading_cols as $label => $token) {
    $this
      ->addColumn('heading', $token, $label, $config);
  }

  // Get the data cells
  if ($dim) {
    $dims = (array) $dim;
    foreach ($dims as $dim) {
      $this
        ->addColumn('crosstab', $dim, trim($dim, '{}'), $config);
    }
  }
  foreach ($data_cols as $label => $token) {
    $this
      ->addColumn('value', $token, $label, $config);
  }
  return $config;
}