You are here

public function Report::preloadData in Forena Reports 8

Same name and namespace in other branches
  1. 7.5 src/Report.php \Drupal\forena\Report::preloadData()
1 call to Report::preloadData()
Report::render in src/Report.php
Render the report

File

src/Report.php, line 349
Basic report provider. Controls the rendering of the report.

Class

Report

Namespace

Drupal\forena

Code

public function preloadData() {
  $blocks_loaded = $this->blocks_loaded;
  $jsonData = array();
  if ($this->data) {
    foreach ($this->data as $d) {
      if (!empty($d['block'])) {
        $id = @$d['id'];
        $block = $d['block'];
        $parms = @$d['parameters'];
        $raw = !empty($d['json']) || !empty($d['raw_mode']);

        /** @var \SimpleXMLElement $data */
        $data = $this
          ->getData($block, $parms, $raw);
        if (@$d['path'] && !$raw && $data) {
          $data = $data
            ->xpath((string) $d['path']);
          if ($data) {
            $data = $data[0];
          }
        }
        $this
          ->setDataContext($id, $data);
        if (!empty($d['json']) && $this->format == 'web') {
          $ret = array();
          if ($data) {
            foreach ($data as $row) {
              $ret[] = $row;
            }
          }
          $jsonData[$d['json']] = $ret;
        }
      }
      else {
        $id = @$d['id'];
        if ($id && isset($d['data'])) {
          $this
            ->setDataContext($id, $d['data']);
        }
      }
    }
  }
  if ($jsonData) {
    drupal_add_js(array(
      'forenaData' => $jsonData,
    ), 'setting');
  }
  $this->blocks_loaded = $blocks_loaded;
}