You are here

public function FrxReportEditor::setBody in Forena Reports 7

Same name and namespace in other branches
  1. 6.2 FrxReportEditor.inc \FrxReportEditor::setBody()
  2. 6 FrxReportEditor.inc \FrxReportEditor::setBody()
  3. 7.2 FrxReportEditor.inc \FrxReportEditor::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

html $body:

File

./FrxReportEditor.inc, line 117

Class

FrxReportEditor
Wrapper XML class for working with DOM object. It provides helper Enter description here ... @author metzlerd

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) {
    forena_error('Malformed report body', '<pre>' . $e
      ->getMessage() . $e
      ->getTraceAsString() . '</pre>');
  }
}