public function ReportEditor::setFrxHeader in Forena Reports 8
Same name and namespace in other branches
- 7.5 src/Editor/ReportEditor.php \Drupal\forena\Editor\ReportEditor::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:
string $id_field name of field containint node id:
4 calls to ReportEditor::setFrxHeader()
- ReportEditor::addParameters in src/
Editor/ ReportEditor.php - ReportEditor::setDocgen in src/
Editor/ ReportEditor.php - Set document generation types that apply to this report. Enter description here ...
- ReportEditor::setFields in src/
Editor/ ReportEditor.php - Builds the fields from an array of elements. Enter description here ...
- ReportEditor::setParameters in src/
Editor/ ReportEditor.php - Set report parameters Enter description here ...
File
- src/
Editor/ ReportEditor.php, line 359 - ReportEditor.inc Wrapper XML class for working with DOM object. It provides helper Enter description here ... @author metzlerd
Class
Namespace
Drupal\forena\EditorCode
public function setFrxHeader($parent, $element, $element_array, $attributes, $element_field = '', $id_field = 'id') {
$dom = $this->dom;
/** @var \DOMXPath $xpq */
$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);
}
}
}
}
}