You are here

public function FrxTable::generate in Forena Reports 7.4

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

Generate the template from the configuration.

Parameters

string $data_block:

SimpleXMLElement $xml:

array $config:

Overrides FrxRenderer::generate

File

renderers/FrxTable.inc, line 34
FrxTable Template that lays out a report in a particular table format.

Class

FrxTable
@file FrxTable Template that lays out a report in a particular table format.

Code

public function generate($xml, &$config) {
  $block = @$config['block'];
  $id = @$config['id'];
  if ($block) {
    $id = $this
      ->idFromBlock($block);
    $config['id'] = $id . '_block';
  }
  $config['class'] = @$config['class'] ? $config['class'] . ' FrxTable' : 'FrxTable';
  $div = $this
    ->blockDiv($config);

  // PUt on the header
  $this
    ->removeChildren($div);
  if (isset($config['header']['value'])) {
    $this
      ->addFragment($div, $config['header']['value']);
  }

  // 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,
      );
    }
  }
  $attrs = array(
    'foreach' => '*',
  );
  $table = $this
    ->setFirstNode($div, 4, 'table');
  if (@$config['caption']) {
    $this
      ->setFirstNode($table, 6, 'caption', $config['caption']);
  }
  $thead = $this
    ->setFirstNode($table, 6, 'thead');
  $throw = $this
    ->setFirstNode($thead, 8, 'tr');
  $tbody = $this
    ->setFirstNode($table, 6, 'tbody');
  $tdrow = $this
    ->setFirstNode($tbody, 8, 'tr', NULL, array(
    'id' => $id,
  ), $attrs);
  if (isset($config['columns'])) {
    foreach ($config['columns'] as $key => $col) {
      if ($col['include']) {
        $this
          ->addNode($throw, 10, 'th', $col['label']);
        $this
          ->addNode($tdrow, 10, 'td', $col['contents']);
      }
    }
  }
  if (isset($config['footer']['value'])) {
    $this
      ->addFragment($div, $config['footer']['value']);
  }
}