You are here

public function FrxRenderer::columns in Forena Reports 7.4

Extract a list of columns from the data context.

Parameters

$xml SimpleXMLElement The xml data:

string $path:

Return value

multitype:|multitype:string mixed

5 calls to FrxRenderer::columns()
FrxCrosstab::generate in renderers/FrxCrosstab.inc
Generate the template from the configuration.
FrxFieldTable::generate in renderers/FrxFieldTable.inc
Generate the template from the configuration.
FrxRenderer::generate in renderers/FrxRenderer.inc
Generate the template from the configuration.
FrxSVGGraph::generate in renderers/FrxSVGGraph.inc
Generate the template from the configuration.
FrxTable::generate in renderers/FrxTable.inc
Generate the template from the configuration.

File

renderers/FrxRenderer.inc, line 675
FrxRenderer.inc Base class for Frx custom renderers @author davidmetzler

Class

FrxRenderer
@file FrxRenderer.inc Base class for Frx custom renderers @author davidmetzler

Code

public function columns($xml, $path = '/*/*') {

  //create an array of columns
  if (!is_object($xml)) {
    return array();
  }

  // Use xpath if possible otherwise iterate.
  if (method_exists($xml, 'xpath')) {
    $rows = $xml
      ->xpath($path);
  }
  else {
    $rows = $xml;
  }
  $column_array = array();
  $numeric_columns = array();
  foreach ($rows as $columns) {
    foreach ($columns as $name => $value) {
      $label = str_replace('_', ' ', $name);
      $column_array[$name] = $label;
      if (is_numeric((string) $value)) {
        $numeric_columns[$name] = $label;
      }
      else {
        if (isset($numeric_columns[$name])) {
          unset($numeric_columns[$name]);
        }
      }
    }
    if (is_object($xml) && method_exists($xml, 'attributes')) {
      foreach ($xml
        ->attributes() as $name => $value) {
        $column_array['@' . $name] = '@' . $name;
      }
    }
  }
  $this->columns = $column_array;
  $this->numeric_columns = $numeric_columns;
  return $column_array;
}