You are here

public function FrxFieldTable::generate in Forena Reports 7.4

Same name and namespace in other branches
  1. 6.2 templates/FrxFieldTable.inc \FrxFieldTable::generate()
  2. 7.2 templates/FrxFieldTable.inc \FrxFieldTable::generate()
  3. 7.3 templates/FrxFieldTable.inc \FrxFieldTable::generate()

Generate the template from the configuration.

Parameters

string $data_block:

SimpleXMLElement $xml:

array $config:

Overrides FrxRenderer::generate

File

renderers/FrxFieldTable.inc, line 35
FrxFieldTable Template that displays a table of column/value vertically.

Class

FrxFieldTable
@file FrxFieldTable Template that displays a table of column/value vertically.

Code

public function generate($xml, &$config) {
  $config['foreach'] = '*';
  $config['class'] = 'FrxFieldTable';
  $div = $this
    ->blockDiv($config);
  $columns = $this
    ->columns($xml);

  // PUt on the header
  $this
    ->removeChildren($div);
  $this
    ->addFragment($div, $config['header']);
  $table = $this
    ->setFirstNode($div, 4, 'table');
  $r = 0;
  if ($config['columns']) {
    foreach ($config['columns'] as $key => $col) {
      if ($col['include']) {
        $r++;
        $tbody = $this
          ->addNode($table, 6, 'tbody');
        $tr = $this
          ->addNode($tbody, 8, 'tr');
        $th_attrs = array();
        if ($r == 1) {
          $th_attrs = array(
            'style' => 'width: 25em;',
          );
        }
        $th = $this
          ->addNode($tr, 10, 'th', $col['label']);
        $td = $this
          ->addNode($tr, 10, 'td', $col['contents']);
      }
    }
  }

  // Decide to inlcude columns
  $found_columns = $this
    ->columns($xml);
  if (!$found_columns) {
    $found_columns = $this
      ->columns($xml, '/*');
    $attrs = array();
  }
  $include_column = 0;
  $weight = 0;
  if (!@$config['columns']) {
    $include_column = 1;
  }
  else {
    $weight = count($config['columns']);
  }
  foreach ($found_columns as $column => $label) {
    $token = '{' . $column . '}';
    if (!isset($config['columns'][$column])) {
      $weight++;
      $config['columns'][$column] = array(
        'contents' => $token,
        'include' => $include_column,
        'label' => $label,
        'weight' => $weight,
      );
    }
  }
}