You are here

public function FrxDrupal::sqlData in Forena Reports 7.4

Same name and namespace in other branches
  1. 7.3 plugins/FrxDrupal.inc \FrxDrupal::sqlData()

Get data based on file data block in the repository.

Parameters

String $block_name:

Array $parm_data:

Query $subQuery:

Overrides FrxDataSource::sqlData

File

plugins/FrxDrupal.inc, line 106
Provides data blocks for native drupal connections using the default drupal connections.

Class

FrxDrupal
@file Provides data blocks for native drupal connections using the default drupal connections.

Code

public function sqlData($sql, $options = array()) {
  $rs = $this
    ->query($sql, $options);
  $entity_map = array();
  $select_fields = array();
  $rownum = 0;
  if (!$rs) {
    return;
  }
  if (@$options['return_type'] == 'raw') {
    return $rs;
  }
  $xml = new SimpleXMLElement('<table/>');
  if ($rs && $rs
    ->columnCount()) {
    foreach ($rs as $data) {
      $rownum++;
      $row_node = $xml
        ->addChild('row');
      $row_node['num'] = $rownum;
      foreach ($data as $key => $value) {
        $row_node
          ->addChild($key, htmlspecialchars($value));
      }

      /* If we are querying entities, we will store away IDs
       * for later querying and XML processing in the
       * loadEntitys method
       */
      if (@$options['entity_type'] && @$options['entity_id']) {
        $display = @$options['entity_display'];
        $id_key = $options['entity_id'];
        $type = $options['entity_type'];
        $id = $data->{$id_key};
        if ($id) {
          $entity_map[$id][] = $row_node;
          $select_fields[$id] = $data;
        }
      }
    }
  }
  if ($entity_map) {
    $this
      ->loadEntities($type, $entity_map, $select_fields, $display);
  }
  if ($this->debug) {
    $d = $xml ? htmlspecialchars($xml
      ->asXML()) : '';
    $this
      ->debug('SQL: ' . $sql, '<pre> SQL:' . $sql . "\n XML: " . $d . "\n</pre>");
  }
  return $xml;
}