Commit 2a7caa8b authored by metzlerd's avatar metzlerd
Browse files

Added the ability to load entities for each query retrieved in a data

block. 
Data blocks can now have options using the comment syntax. 
parent b08b5ef1
......@@ -17,6 +17,7 @@ class FrxDataSource{
public $types;
public $block_name;
protected $te;
public $debug = FALSE;
public function __construct($conf, $repos_path, $name) {
$this->conf = $conf;
$this->comment_prefix = '--';
......@@ -306,6 +307,7 @@ class FrxDataSource{
$file = '';
$skip = FALSE;
$tokens = array();
$options = array();
while ($i<$cnt) {
$l = trim($lines[$i], "\r");
@list($d, $c) = explode($comment, $l, 2);
......@@ -335,6 +337,8 @@ class FrxDataSource{
$tokens = array_merge($tokens, $inc_block['tokens']);
}
break;
default:
$options[$a] = $o;
}
}
......@@ -355,16 +359,17 @@ class FrxDataSource{
}
$tokens = array_merge($tokens, $this->tokens($contents));
$block = array( 'source' => $data, 'file' => trim($file, " \n"),
'tokens' => $tokens);
'tokens' => $tokens, 'options' => $options);
if ($access) $block['access'] = $access;
return $block;
}
/**
* Dummy method for returning sql data
* @param unknown_type $parameters
* @param $parameters array Block parameters
* @param $block array extra block options for data provider.
*/
public function sqlData($parameters) {
public function sqlData($parameters, $options= array()) {
return '';
}
......
......@@ -243,7 +243,7 @@ class FrxRepoMan {
if ($block && $o->access($right)) {
switch ($block['type']) {
case 'sql':
$xml = $o->sqlData($block['source']);
$xml = $o->sqlData($block['source'], @$block['options']);
break;
case 'xml':
$xml = $o->xmlData($block['source']);
......
......@@ -33,7 +33,7 @@ class FrxDrupal extends FrxDataSource {
* @param Array $parm_data
* @param Query $subQuery
*/
public function sqlData($sql) {
public function sqlData($sql, $options = array()) {
if ($this->database != 'default') {
db_set_active($this->database);
}
......@@ -42,15 +42,52 @@ class FrxDrupal extends FrxDataSource {
$sql = $this->te->replace($sql);
$rs = db_query($sql);
$xml = new SimpleXMLElement('<table/>');
foreach ($rs as $data) {
$row_node = $xml->addChild('row');
/* If we have asked for one, lets load the entities based on
the entity type and entity id that is specified in the block
comments. */
if (@$options['ENTITY_TYPE'] && @$options['ENTITY_ID'] ) {
$id_key = $options['ENTITY_ID'];
$id = $data->$id_key;
if ($id) {
$type = $options['ENTITY_TYPE'];
$e = entity_load($type, (array) $id);
$lang = isset($e->language) ? $e->language : 'und';
if ($e) foreach ($e[$id] as $key => $val) if ($val) {
if (strpos($key, 'field_') === 0) {
//$fields = field_get_items('node', $node, $key);
$field = field_view_field($type, $e, $key);
$field['#theme'] = array('forena_inline_field');
$value = drupal_render($field);
$f = $row_node->addChild($key, $value);
if (isset($field['#field_type'])) $f['type'] = $field['#field_type'];
if (isset($field['#field_name'])) $f['name'] = $field['#field_name'];
} else if (is_array($val) && isset($val[$lang])) {
dpm('in here');
$tmp = $val[$lang][0];
if (isset($tmp['safe_value'])) {
$row_node->addChild($key, $tmp['safe_value']);
} else if (isset($tmp['value'])) {
$row_node->addChild($key, $tmp['value']);
}
} else if (is_scalar($val)) {
$row_node->addChild($key, $val);
}
}
foreach ($data as $key => $value) {
$row_node->addChild($key, htmlspecialchars($value));
//$row_node->$key = $value;
}
} else {
foreach ($data as $key => $value) {
$row_node->addChild($key, htmlspecialchars($value));
//$row_node->$key = $value;
}
}
}
if ($this->database != 'default') {
db_set_active();
}
......
......@@ -61,7 +61,7 @@ class FrxMSSQL extends FrxDataSource {
* @param Array $parm_data
* @param Query $subQuery
*/
public function sqlData($sql, $params=array(), $tag='table') {
public function sqlData($sql, $options = array()) {
// Load the block from the file
$db = $this->db;
$xml ='';
......
......@@ -62,7 +62,7 @@ class FrxOracle extends FrxDataSource {
* @param Array $parm_data
* @param Query $subQuery
*/
public function sqlData($sql) {
public function sqlData($sql, $options = array()) {
// Load the block from the file
$db = $this->db;
$xml ='';
......
......@@ -74,7 +74,7 @@ class FrxPDO extends FrxDataSource {
* @param Array $parm_data
* @param Query $subQuery
*/
public function sqlData($sql) {
public function sqlData($sql, $options = array()) {
// Load the block from the file
$db = $this->db;
$xml ='';
......
......@@ -54,7 +54,7 @@ class FrxPostgres extends FrxDataSource {
* @param Array $parm_data
* @param Query $subQuery
*/
public function sqlData($sql) {
public function sqlData($sql, $options = array()) {
// Load the block from the file
$db = $this->db;
$xml ='';
......
......@@ -15,7 +15,7 @@ class FrxDrupalNode {
if (!$nid && !$vid) return '';
$node = node_load($nid, $vid);
$return = new SimpleXMLElement('<node/>');
$lang = isset($node->language) ? $node->language : 'unk';
$lang = isset($node->language) ? $node->language : 'und';
$display = isset($parms['display']) ? $parms['display'] : 'default';
if ($node) foreach ($node as $key => $val) if ($val) {
if (strpos($key, 'field_') === 0) {
......
--ACCESS=access content
--ENTITY_TYPE=node
--ENTITY_ID=nid
SELECT nid, type, title, uid, sticky, promote from node WHERE type=:content_type
and status=1
ORDER BY title
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment