You are here

public function ReportEditor::load in Forena Reports 8

Same name and namespace in other branches
  1. 7.5 src/Editor/ReportEditor.php \Drupal\forena\Editor\ReportEditor::load()

Load report from file system

Parameters

string $report_name:

bool $edit: Indicates whether we are preferentially loading from session.

Return value

string

1 call to ReportEditor::load()
ReportEditor::__construct in src/Editor/ReportEditor.php
Construct the editor

File

src/Editor/ReportEditor.php, line 154
ReportEditor.inc Wrapper XML class for working with DOM object. It provides helper Enter description here ... @author metzlerd

Class

ReportEditor

Namespace

Drupal\forena\Editor

Code

public function load($report_name, $edit = TRUE) {
  $this->desc = Menu::instance()
    ->parseURL($report_name);
  $r_text = '';
  $dom = $this->dom;
  $this->report_name = $report_name = $this->desc['name'];
  $this->report_link = 'reports/' . str_replace('/', '.', $this->desc['base_name']);

  // Load the latest copy of the report editor
  if ($report_name) {
    if (isset($_SESSION['forena_report_editor'][$report_name]) && $edit) {
      $r_text = $_SESSION['forena_report_editor'][$report_name];
      drupal_set_message(t('All changes are stored temporarily.  Click Save to make your changes permanent.  Click Cancel to discard your changes.'), 'warning', FALSE);
    }
    else {
      $filename = $report_name . '.frx';
      $r_text = $this
        ->reportFileSystem()
        ->contents($filename);
    }
  }
  if (!$r_text) {
    $m_path = drupal_get_path('module', 'forena');
    $r_text = file_get_contents($m_path . '/default.frx');
  }
  libxml_use_internal_errors();
  try {
    @$dom
      ->loadXML($r_text);
    $this->xpq = new DOMXPath($dom);
  } catch (\Exception $e) {
    $this
      ->error('Invalid or malformed report document', '<pre>' . $e
      ->getMessage() . $e
      ->getTraceAsString() . '</pre>');
  }
  if (!$this->dom->documentElement) {
    $this
      ->error(t('Invalid or malformed report document'));
    return '';
  }
  $this
    ->verifyHeaderElements();
  $tnodes = $dom
    ->getElementsByTagName('title');
  if ($tnodes->length) {
    $this->title = $tnodes
      ->item(0)->textContent;
  }
  $this->document_root = $dom->documentElement;
  $this->simplexml = simplexml_import_dom($dom);
  $dom->formatOutput = TRUE;

  // Try to make sure garbage collection happens.
  unset($this->xpq);
  $this->xpq = new DOMXPath($dom);
  $this->xpq
    ->registerNamespace('frx', $this->xmlns);

  // Make sure document header is reparsed.
  // @TODO: Figure out whether we need to reparse?
  // $this->frxReport->setReport($this->dom, $this->xpq, $this->edit);
  $cache = forena_load_cache($this->frxReport->rpt_xml);
  if (isset($cache['access'])) {
    $this->access = forena_check_all_access($cache['access']);
  }
  if (!$edit) {
    $this->cache = $this
      ->reportFileSystem()
      ->getMetaData($report_name . '.frx');
  }
  return $r_text;
}