public function FrxDrupal::sqlData in Forena Reports 7.3
Same name and namespace in other branches
- 7.4 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 36 - 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()) {
if ($this->database != 'default') {
db_set_active($this->database);
}
// Load the types array based on data
$this->types = isset($options['type']) ? $options['type'] : array();
// Load the block from the file
$xml = '';
$sql = $this->te
->replace($sql);
$rs = db_query($sql);
$entity_map = array();
$select_fields = array();
$rownum = 0;
$xml = new SimpleXMLElement('<table/>');
if ($rs && $rs
->columnCount()) {
foreach ($rs as $data) {
$rownum++;
$row_node = $xml
->addChild('row');
$row_node['num'] = $rownum;
/* 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']) {
$id_key = $options['entity_id'];
$type = $options['entity_type'];
$id = $data->{$id_key};
if ($id) {
$entity_map[$id] = $row_node;
$select_fields[$id] = $data;
}
}
else {
foreach ($data as $key => $value) {
$row_node
->addChild($key, htmlspecialchars($value));
//$row_node->$key = $value;
}
}
}
}
if ($this->database != 'default') {
db_set_active();
}
if ($entity_map) {
$this
->loadEntities($type, $entity_map, $select_fields);
}
if ($this->debug) {
$d = $xml ? htmlspecialchars($xml
->asXML()) : '';
$this
->debug('SQL: ' . $sql, '<pre> SQL:' . $sql . "\n XML: " . $d . "\n</pre>");
}
return $xml;
}