public function Report::setReport in Forena Reports 8
Same name and namespace in other branches
- 7.5 src/Report.php \Drupal\forena\Report::setReport()
Sets the report.
Parameters
DOMDocument $dom: Root Document element for the report
DOMXPath $xpq: Query object associated with the element
1 call to Report::setReport()
- Report::__construct in src/
Report.php
File
- src/
Report.php, line 168 - Basic report provider. Controls the rendering of the report.
Class
Namespace
Drupal\forenaCode
public function setReport(DOMDocument $dom, DOMXPath $xpq) {
$this->dom = $dom;
$dom->formatOutput = TRUE;
$this->xpathQuery = $xpq;
/** @var \SimpleXMLElement $rpt_xml */
$rpt_xml = $this->rpt_xml = simplexml_import_dom($this->dom->documentElement);
$this->missing_parms = FALSE;
// Load header data
$this->body = $rpt_xml->body;
if ($rpt_xml->head) {
$this->title = (string) $rpt_xml->head->title;
/** @var \SimpleXMLElement $nodes */
$nodes = $rpt_xml
->xpath('//frx:docgen/frx:doc');
$this->formats = array();
if ($nodes) {
/** @var \SimpleXMLElement $value */
foreach ($nodes as $value) {
$arr = $value
->attributes();
$this->formats[] = (string) $arr['type'];
}
}
$security = [];
/** @var \SimpleXMLElement $node */
foreach ($rpt_xml->head
->children(Report::FRX_NS) as $name => $node) {
switch ($name) {
case 'access':
$access = trim((string) $node);
if (strpos($access, '.')) {
list($repos, $right) = explode('.', $access, 2);
$security[$repos][] = $right;
}
break;
case 'fields':
$field_nodes = $node
->xpath('frx:field');
$fields = $this
->extractDefinitions($field_nodes, 'id', 'default');
foreach ($fields as $key => $field) {
$this->replacer
->defineField($key, $field);
}
break;
case 'category':
$this->category = (string) $node;
break;
case 'options':
foreach ($node
->attributes() as $key => $value) {
$this->options[$key] = (string) $value;
}
break;
case 'cache':
foreach ($node
->attributes() as $key => $value) {
$this->cache[$key] = (string) $value;
}
break;
case 'title':
$this->frx_title = (string) $node;
break;
case 'parameters':
/** @var \SimpleXMLElement $parm_node */
foreach ($node
->children(Report::FRX_NS) as $key => $parm_node) {
$parm = array();
foreach ($parm_node
->attributes() as $akey => $attr) {
$parm[$akey] = (string) $attr;
}
$id = $parm['id'];
$val = isset($parm['value']) ? $parm['value'] : '';
$parm['value'] = (string) $parm_node ? (string) $parm_node : $val;
// Convert pipes to an array.
if ($parm['value'] && strpos($parm['value'], '!' !== FALSE)) {
$parm['value'] = explode('|', $parm['value']);
}
$this->parameterDefinitions[$id] = $parm;
}
break;
case 'commands':
/** @var \SimpleXMLElement $ajax_node */
$events = $node
->attributes();
$event = $events['event'];
$event = strpos($event, 'pre') === 0 ? 'pre' : 'post';
foreach ($node
->children(Report::FRX_NS) as $key => $ajax_node) {
$command = array();
$command['text'] = $this
->innerXML($ajax_node, 'frx:ajax');
foreach ($ajax_node
->attributes() as $akey => $attr) {
$command[$akey] = (string) $attr;
}
$this->commands[$event][] = $command;
}
break;
case 'data':
$data = array();
foreach ($node
->attributes() as $key => $value) {
$data[$key] = (string) $value;
}
$data['data'] = $node;
$this->data[] = $data;
break;
case 'doctypes':
$this->doctypes = $node;
break;
case 'skin':
$def = [];
$skin_definition = (string) $node;
if ($skin_definition) {
try {
$def = Skin::parseJSON($skin_definition);
} catch (\Exception $e) {
$this
->error('Unable to parse JSON', $e
->getMessage());
}
Skin::instance($this->skin)
->merge($def);
}
break;
}
}
if (empty($security)) {
$security = $this
->getBlockAccess();
}
$this->access = $security;
if (!empty($this->options['skin'])) {
$this->skin = $this->options['skin'];
}
}
}