You are here

public function ReportEditor::loadReport in Forena Reports 7.5

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

Parameters

$report:

bool $edit:

Return value

Report

File

src/Editor/ReportEditor.php, line 91
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 = Frx::Menu()
    ->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 = Frx::File()
        ->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) {
    Frx::error('Invalid or malformed report document', '<pre>' . $e
      ->getMessage() . $e
      ->getTraceAsString() . '</pre>');
  }
  if (!$this->dom->documentElement) {
    Frx::error(t('Invalid or malformed report document'));
    return null;
  }
  $frxReport = new Report();
  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;
}