You are here

public function FrxEditor::setFrxHeader in Forena Reports 7.3

Same name and namespace in other branches
  1. 7.4 FrxEditor.inc \FrxEditor::setFrxHeader()

Genreal utility for setting data in the header of a reprot

Parameters

string $parent Name of parent element:

string $element Name of child element:

array $element_array Data containing the elements:

array $attributes array of attribute names to set:

string $element_field name of field containing node data:

unknown_type $id_field name of field containint node id:

4 calls to FrxEditor::setFrxHeader()
FrxEditor::addParameter in ./FrxEditor.inc
FrxEditor::setDocgen in ./FrxEditor.inc
Set document generation types that apply to this report. Enter description here ...
FrxEditor::setFields in ./FrxEditor.inc
Builds the fields from an array of elements. Enter description here ...
FrxEditor::setParameters in ./FrxEditor.inc
Set report parameters Enter description here ...

File

./FrxEditor.inc, line 179
FrxEditor.inc Wrapper XML class for working with DOM object. It provides helper Enter description here ... @author metzlerd

Class

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

Code

public function setFrxHeader($parent, $element, $element_array, $attributes, $element_field = '', $id_field = 'id') {
  $dom = $this->dom;
  $xpq = $this->xpq;
  $this
    ->verifyHeaderElements(array(
    $parent,
  ));
  $pnode = $dom
    ->getElementsByTagNameNS($this->xmlns, $parent)
    ->item(0);

  // Iterate through all child arrays in the header
  $tnode = $dom
    ->createTextNode("\n");
  $pnode
    ->appendChild($tnode);
  foreach ($element_array as $element_data) {
    $id = @$element_data[$id_field];
    $path = '//frx:' . $parent . '/frx:' . $element . '[@' . $id_field . '="' . $id . '"]';
    $nodes = $xpq
      ->query($path);
    $value = NULL;
    if ($element && isset($element_data[$element_field])) {
      $value = $element_data[$element_field];
    }
    $node = $dom
      ->createElementNS($this->xmlns, $element, trim($value, "|"));
    if ($nodes->length == 0) {
      $tnode = $dom
        ->createTextNode("  ");
      $pnode
        ->appendChild($tnode);
      $pnode
        ->appendChild($node);
      $tnode = $dom
        ->createTextNode("\n");
      $pnode
        ->appendChild($tnode);
    }
    else {
      $src_node = $nodes
        ->item(0);
      $pnode
        ->replaceChild($node, $src_node);
    }
    foreach ($attributes as $attribute) {
      if (!empty($element_data[$attribute])) {
        $node
          ->setAttribute($attribute, $element_data[$attribute]);
      }
      else {
        if ($node
          ->hasAttribute($attribute)) {
          $node
            ->removeAttribute($attribute);
        }
      }
    }
  }
}