public function FrxReport::render_section in Forena Reports 7
Same name and namespace in other branches
- 6.2 FrxReport.inc \FrxReport::render_section()
- 6 FrxReport.inc \FrxReport::render_section()
- 7.2 FrxReport.inc \FrxReport::render_section()
- 7.3 FrxReport.inc \FrxReport::render_section()
Recursive report renderer Walks the nodes rendering the report.
1 call to FrxReport::render_section()
- FrxReport::render in ./
FrxReport.inc - Render the report
File
- ./
FrxReport.inc, line 107 - Basic report provider. Controls the rendering of the report.
Class
Code
public function render_section(DOMNode $dom_node) {
$cur_data = $this->cur_data;
$continue = TRUE;
$is_data_block = FALSE;
$node_type = $dom_node->nodeType;
$o = '';
// Shortcut process a text node
if ($node_type == XML_TEXT_NODE || $node_type == XML_ENTITY_REF_NODE || $node_type == XML_ENTITY_NODE) {
$text = $dom_node->textContent;
$o .= $this->teng
->replace($text, $this->cur_data);
return $o;
}
//Ignore certain node types
if ($node_type == XML_COMMENT_NODE) {
return '';
}
// Continue processing non text nodes
$node = simplexml_import_dom($dom_node);
// Special catch to make sure we don't process bad nodes
if (!$node) {
return '';
}
$frx = $node
->attributes(FRX_NS);
$elements = $dom_node->childNodes->length;
// Test to see if we have any nodes that are contains data url
if ($node
->xpath('*//@frx:*') || $frx) {
$attrs = $node
->attributes();
$id = (string) $attrs['id'];
$frx = $node
->attributes(FRX_NS);
$tag = $node
->getName();
if ((string) $frx['block']) {
$is_data_block = TRUE;
$this
->get_data((string) $frx['block'], (string) $frx['clause'], $id);
if (!$this->cur_data) {
$continue = FALSE;
}
}
// Preserve non frx attributes
$attr_text = '';
$tmp_attrs = array();
if ($attrs) {
foreach ($attrs as $key => $value) {
$attr_text = ' ' . $key . '="' . (string) $value . '"';
$tmp_attr[$key] = (string) $value;
}
}
// if we have a foreach in this node, we need to iterate the children
if ((string) $frx['foreach']) {
// Save xml
$path = (string) $frx['foreach'];
$data = $this->cur_data;
if (is_object($data)) {
$nodes = $data
->xpath($path);
}
$i = 0;
//$tmp_attrs = (array)$attrs;
if ($nodes) {
foreach ($nodes as $x) {
$this->cur_data = $x;
$this->teng
->push_data($x, $id);
$i++;
$odd = $i & 1;
$row_class = $odd ? 'odd' : 'even';
$tmp_attrs['class'] = trim($attrs['class'] . ' ' . $row_class);
$r_attr_text = '';
foreach ($tmp_attrs as $key => $value) {
$r_attr_text .= ' ' . $key . '="' . (string) $value . '"';
}
$o .= $this->teng
->replace('<' . $tag . $r_attr_text . '>', $this->cur_data);
foreach ($dom_node->childNodes as $child) {
$o .= $this
->render_section($child);
}
$o .= '</' . $tag . '>';
}
}
$this->cur_data = $data;
$this->teng
->pop_data($id);
}
elseif ($continue) {
$renderer = (string) $frx['renderer'];
if (!$renderer) {
$o .= $this->teng
->replace('<' . $tag . $attr_text . '>');
}
// @TODO: Determine if there is a custom renderer
// None found, so render children
foreach ($dom_node->childNodes as $child) {
$o .= $this
->render_section($child);
}
if (!$renderer) {
$o .= '</' . $tag . '>';
}
}
}
else {
$tag = $node
->getName();
// We can render so lets do it.
$text = $node
->asXML();
$o .= $this->teng
->replace($text, $this->cur_data);
}
$this->cur_data = $cur_data;
//if ($is_data_block) $this->teng->pop_data($id);
return $o;
}