public function FrxData::getValue in Forena Reports 7.3
Same name and namespace in other branches
- 7.4 FrxData.inc \FrxData::getValue()
Get the value from the data. This is used by token_replace method to extract the data based on the path provided.
Parameters
$data:
$key:
Return value
unknown_type
Overrides FrxContext::getValue
File
- ./
FrxData.inc, line 87
Class
Code
public function getValue($key, $context = '') {
$retvar = '';
// Default to theo current context
$data = $this
->currentContext();
if ($context && $this
->contextExists($context)) {
$data = $this
->getContext($context);
}
if (is_array($data)) {
$retvar = @$data[$key];
}
elseif (is_object($data)) {
if (strpos($key, '=') === 0) {
$retvar = $this
->simplexml_evaluate($data, ltrim($key, '='));
}
else {
$rows = @$data
->xpath($key);
if ($rows === FALSE) {
drupal_set_message(t('Invalid field: "%s"', array(
'%s' => $key,
)), 'error', FALSE);
}
$x = '';
if ($rows) {
$x = $rows[0];
}
if ($x) {
$retvar = $x
->asXML();
}
// Check to see if there are child nodes
// If so use asXML otherwise string cast.
if ($retvar && strpos($retvar, '<') !== FALSE) {
// Find the end of the first tag.
$p = strpos($retvar, '>');
$retvar = substr_replace($retvar, '', 0, $p + 1);
$p = strrpos($retvar, '<', -1);
$retvar = substr_replace($retvar, '', $p, strlen($retvar) - $p);
}
else {
$retvar = (string) $x;
}
}
}
if (!is_array($retvar)) {
$retvar = trim((string) $retvar);
}
return $retvar;
}