You are here

public function RendererBase::xmlToValues in Forena Reports 8

Convert XML to key value pairs. This is used in support of graping to get specific key/value pairs in an array format suitable for passing off to php libraries.

Parameters

string $path: xpath expression to use to convert

string $data_path: path to configuration data.

string $label_path: xpath to label values

bool $pairs:

Return value

array data values from xml.

File

src/FrxPlugin/Renderer/RendererBase.php, line 877
FrxRenderer.php Base class for FrxAPI custom Renderer @author davidmetzler

Class

RendererBase
Crosstab Renderer

Namespace

Drupal\forena\FrxPlugin\Renderer

Code

public function xmlToValues($path, $data_path, $label_path = '', $pairs = FALSE) {
  $do = $this->dmSvc->dataSvc;
  $data = $do
    ->currentContext();
  $values = array();
  if (is_object($data)) {
    $nodes = $data
      ->xpath($path);
    if ($nodes) {
      foreach ($nodes as $i => $node) {
        $do
          ->push($node, $this->id);
        $val = $this->report
          ->replace($data_path, TRUE);
        if ($label_path) {
          $key = strip_tags($this->report
            ->replace($label_path, FALSE));
        }
        else {
          $key = $i;
        }
        if ($pairs && $label_path) {
          $values[] = array(
            floatval($key),
            floatval($val),
          );
        }
        else {
          $values[$key] = $val;
        }
        $do
          ->pop();
      }
    }
  }
  return $values;
}