You are here

public function ReportEditor::addBlock in Forena Reports 8

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

Add a data blcok

Parameters

string $block: Block to provide the data

string $class: Template class to use as configuration

string $id: ID of the section to insert.

Return value

ReportEditor

File

src/Editor/ReportEditor.php, line 928
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 addBlock($block_name, $template_class, &$config, $id = '') {
  if (!$template_class) {
    $template_class = 'FrxTable';
  }
  $block_name = str_replace('.', '/', $block_name);
  if ($id) {
    $path = "body//*[@id='{$id}']";
    $nodes = $this->simplexml
      ->xpath($path);
    if ($nodes) {
      $pnode = dom_import_simplexml($nodes[0]);
      $node = $this->dom
        ->createElement('div');
      $pnode
        ->appendChild($node);
    }
    else {
      drupal_set_message(t('Could not find %s in report', array(
        '%s' => $id,
      )), 'error');
      return NULL;
    }
  }
  else {
    $nodes = $this->dom
      ->getElementsByTagName('body');
    $pnode = $nodes
      ->item(0);
    $node = $this->dom
      ->createElement('div');
    $pnode
      ->appendChild($node);
  }
  $this->frxReport
    ->setReport($this->dom, $this->xpq);
  $config['block'] = $block_name;
  $b = FrxAPI::BlockEditor($block_name, $this->frxReport->block_edit_mode);
  $data = $b
    ->data($this->parms);
  $this
    ->addParameters($b
    ->tokens());
  $c = FrxAPI::Template($template_class);
  if ($c) {
    $c
      ->initReportNode($node, $this->frxReport);
    $c
      ->generate($data, $config);
  }
  else {
    drupal_set_message(t('Could not find template %s', array(
      '%s' => $template_class,
    )), 'error');
  }
  return $this;
}