You are here

public function FrxReportEditor::setFrxHeader in Forena Reports 7

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

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

File

./FrxReportEditor.inc, line 178

Class

FrxReportEditor
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
  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, $value);
    if ($nodes->length == 0) {
      $pnode
        ->appendChild($node);
    }
    else {
      $src_node = $nodes
        ->item(0);
      $pnode
        ->replaceChild($node, $src_node);
    }
    foreach ($attributes as $attribute) {
      if (isset($element_data[$attribute])) {
        $node
          ->setAttribute($attribute, $element_data[$attribute]);
      }
      else {
        if ($node
          ->hasAttribute($attribute)) {
          $node
            ->removeAttribute($attribute);
        }
      }
    }
  }
}