You are here

protected function DataContext::simplexml_evaluate in Forena Reports 8

Same name and namespace in other branches
  1. 7.5 src/Context/DataContext.php \Drupal\forena\Context\DataContext::simplexml_evaluate()

Provides an api to the {=xpath} syntax that can be used to evaluate expressions such as sum and count in a report. We need to use the DOM object here, because this method isn't exposed with simplexml.

Parameters

\SimpleXMLElement $xml:

string $path:

Return value

\SimpleXMLElement

1 call to DataContext::simplexml_evaluate()
DataContext::getValue in src/Context/DataContext.php
Get the value from the data. This is used by token_replace method to extract the data based on the path provided.

File

src/Context/DataContext.php, line 76
Implements \Drupal\forena\Context\DataContext

Class

DataContext
The DataContext class holds all of the data contexts during the report rendering process. The general idea is that during the report render, data objects are pushed on the stack with the id's of the block or foreach objects that invoke them.

Namespace

Drupal\forena\Context

Code

protected function simplexml_evaluate($xml, $path) {
  if (!method_exists($xml, 'xpath')) {
    return '';
  }
  $dom_node = dom_import_simplexml($xml);
  $dom_doc = new DOMDocument('');
  $dom_node = $dom_doc
    ->importNode($dom_node, TRUE);
  $dom_doc
    ->appendChild($dom_node);

  // Do we also need to call AppendChild?
  $xpath = new DOMXpath($dom_doc);
  $ret = $xpath
    ->evaluate($path, $dom_node);
  return $ret;
}