You are here

public function FrxCrosstab::scrapeConfig in Forena Reports 7.5

Extract table configuration from the HTML

Overrides RendererBase::scrapeConfig

See also

FrxRenderer::scrapeConfig()

File

src/Renderer/FrxCrosstab.php, line 323

Class

FrxCrosstab

Namespace

Drupal\forena\Renderer

Code

public function scrapeConfig() {
  $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;
}