You are here

public function ReportEditor::loadReport in Forena Reports 8

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

Parameters

$report:

bool $edit:

Return value

Report

File

src/Editor/ReportEditor.php, line 97
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 loadReport($report, $edit = FALSE) {
  $desc = Menu::instance()
    ->parseURL($report);
  $r_text = '';
  $report_name = $desc['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');
  }
  $dom = new DOMDocument();
  libxml_use_internal_errors();
  try {
    @$dom
      ->loadXML($r_text);
  } 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 null;
  }

  // @TODO:  This should load the report and not worry about
  $frxReport = new Report($r_text);
  simplexml_import_dom($dom);
  $dom->formatOutput = TRUE;

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

  // Make sure document header is reparsed.
  // $frxReport->setReport($dom, $xpq, $edit);
  return $frxReport;
}