You are here

public function ReportEditor::setBody in Forena Reports 8

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

Set the value of the body of the report Will parse and set the value of the body of the report using XML

Parameters

string $body: String represnetation of html body

File

src/Editor/ReportEditor.php, line 282
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 setBody($body) {
  $dom = $this->dom;
  $nodes = $dom
    ->getElementsByTagName('body');
  $cur_body = $nodes
    ->item(0);

  // Make sure that we have a body tag.
  if (strpos($body, '<body') === FALSE) {
    $body = '<body>' . $body . '</body>';
  }

  // Attempt to parse the xml
  $body_doc = new DOMDocument('1.0', 'UTF-8');
  $body_xml = $this->doc_prefix . '<html xmlns:frx="' . $this->xmlns . '">' . $body . '</html>';
  try {
    $body_doc
      ->loadXML($body_xml);
    $new_body = $dom
      ->importNode($body_doc
      ->getElementsByTagName('body')
      ->item(0), TRUE);
    $parent = $cur_body->parentNode;
    $parent
      ->replaceChild($new_body, $cur_body);
  } catch (\Exception $e) {
    $this
      ->error('Malformed report body', '<pre>' . $e
      ->getMessage() . $e
      ->getTraceAsString() . '</pre>');
  }

  // If there are no frx attributes in the body then replace them with the old values.
  $frx_nodes = $this->frxReport->rpt_xml
    ->xpath('body//*[@frx:*]');
  if (!$frx_nodes) {

    //@TODO: Figure out how to save all the report attbitues by id.

    //$this->frxReport->save_attributes_by_id();
  }
}