You are here

public function FrxDrupalNode::data in Forena Reports 8

Same name and namespace in other branches
  1. 7.5 data/drupal/FrxDrupalNode.php \FrxDrupalNode::data()
  2. 7.4 repos/drupal/FrxDrupalNode.php \FrxDrupalNode::data()

File

data/drupal/FrxDrupalNode.php, line 10

Class

FrxDrupalNode
Implementation of a drupal node load function @author baileys

Code

public function data($parms = array()) {
  $nid = isset($parms['nid']) ? $parms['nid'] : 1;
  $vid = isset($parms['vid']) ? $parms['vid'] : NULL;

  // No node ID means don't try and laod a node.
  if (!$nid && !$vid) {
    return '';
  }
  $node = node_load($nid, $vid);
  $return = new SimpleXMLElement('<node/>');
  $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) {

          //$fields = field_get_items('node', $node, $key);
          $field = field_view_field('node', $node, $key, $display);
          $field['#theme'] = array(
            'forena_inline_field',
          );
          $value = drupal_render($field);
          $f = $return
            ->addChild($key, htmlspecialchars($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])) {
            $tmp = $val[$lang][0];
            if (isset($tmp['safe_value'])) {
              $return
                ->addChild($key, htmlspecialchars($tmp['safe_value']));
            }
            else {
              if (isset($tmp['value'])) {
                $return
                  ->addChild($key, htmlspecialchars($tmp['value']));
              }
            }
          }
          else {
            if (is_scalar($val)) {
              $return
                ->addChild($key, htmlspecialchars($val));
            }
          }
        }
      }
    }
  }
  return $return;
}