class ReportReplacer in Forena Reports 8
Same name and namespace in other branches
- 7.5 src/Token/ReportReplacer.php \Drupal\forena\Token\ReportReplacer
Hierarchy
- class \Drupal\forena\Token\TokenReplacerBase implements TokenReplacerInterface uses FrxAPI
- class \Drupal\forena\Token\ReportReplacer
Expanded class hierarchy of ReportReplacer
6 files declare their use of ReportReplacer
- AjaxCommandBase.php in src/
FrxPlugin/ AjaxCommand/ AjaxCommandBase.php - AReportTokenTest.php in tests/
src/ Unit/ AReportTokenTest.php - FieldFormatterTest.php in tests/
src/ Unit/ FieldFormatterTest.php - Formatter.php in src/
FrxPlugin/ FieldFormatter/ Formatter.php - contains various methods for extending report formating, layout, transformation and design.
- Report.php in src/
Report.php - Basic report provider. Controls the rendering of the report.
File
- src/
Token/ ReportReplacer.php, line 15
Namespace
Drupal\forena\TokenView source
class ReportReplacer extends TokenReplacerBase {
public $fields = [];
public $format_callbacks = [];
public $formats = [];
// Build the token replacer and set the base formatter.
public function __construct() {
parent::__construct('/\\{[^\\n^\\r^}]+}/', '{}');
$this
->setFormatter($this);
$formatters = AppService::instance()
->getFormatterPlugins();
foreach ($formatters as $class) {
/** @var FormatterInterface $formatter */
$formatter = new $class();
$formats = $formatter
->formats();
foreach ($formats as $method => $label) {
$this->format_callbacks[$method] = array(
$formatter,
$method,
);
$this->formats[$method] = $label;
}
}
}
/**
* Replaces nested array data.
* @param $data
* The array containing values to replace.
* @param $raw
* TRUE implies no formatting of data.
*/
public function replaceNested(&$data, $raw = TRUE) {
if (is_array($data)) {
$values = $data;
foreach ($values as $k => $value) {
// Replace key data
$key = $k;
if (strpos($k, '{') !== FALSE) {
$key = $this
->replace($key);
unset($data[$k]);
$data[$key] = $value;
}
// Replace value data.
if (is_array($value)) {
$this
->replaceNested($data[$key], $raw);
}
else {
$data[$key] = $this
->replace($value, $raw);
}
}
}
else {
$data = $this
->replace($data, $raw);
}
}
/**
* Get the value from the data.
* This is used by token_replace method to extract the data based on the path provided.
* @param $data
* @param $key
* @return string|array
*/
protected function get_value($key, $raw = FALSE) {
$context = '';
$raw_key = $key;
$dataSvc = $this
->dataService();
if ($key && strpos($key, '.')) {
@(list($context, $key) = explode('.', $key, 2));
$o = $this
->getDataContext($context);
}
else {
$o = $this
->currentDataContext();
}
$value = htmlentities($dataSvc
->getValue($key, $context));
if ($this->formatter) {
$value = $this->formatter
->format($value, $raw_key, $raw);
}
return $value;
}
/**
* Define the fields associated with the formatter.
* @param string $key
* Field replacement id
* @param $field
* Field definition.
*/
public function defineField($key, $field) {
$def = [];
//Make sure attribute names don't have -
foreach ($field as $attr => $value) {
$def[$attr] = $value;
}
$this->fields[$key] = $def;
}
/*
* Formatter used by the syntax engine to alter data that gets extracted.
* This invokes the field translation
*/
public function format($value, $key, $raw = FALSE) {
// Determine if there is a field overide entry
$default = '';
$link = '';
$format = '';
$format_string = '';
$calc = '';
$context = '';
$field = [];
if (isset($this->fields[$key])) {
$field = $this->fields[$key];
extract($field);
if (isset($field['format-string'])) {
$format_string = $field['format-string'];
}
}
// Evaluate any calculations first.
if ($calc) {
if ($context) {
$context .= ".";
}
$calc = $this
->replace($calc, TRUE);
if ($calc) {
$value = $this
->replace('{' . $context . '=' . $calc . '}', TRUE);
}
}
//@TODO: Figure out how to deal with formatters.
if ($format && !$raw) {
if (!empty($this->format_callbacks[$format])) {
$value = call_user_func($this->format_callbacks[$format], $value, $format_string, $this, $default);
}
$value = trim($value);
}
if (is_array($value) && !$raw) {
$value = implode(' ', $value);
}
// Default if specified
if (!$value && $default) {
$value = $default;
}
if ($link && !$raw) {
$link_fields = array_merge(array_fill_keys([
'link',
'target',
'rel',
'class',
'add_query',
], ''), $field);
$this
->replaceNested($link_fields, TRUE);
$value = AppService::instance()
->reportLink($value, $link_fields);
}
return $value;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FrxAPI:: |
public | function | Returns containing application service | |
FrxAPI:: |
public | function | Get the current data context. | |
FrxAPI:: |
public | function | ||
FrxAPI:: |
public | function | Returns the data manager service | |
FrxAPI:: |
public | function | Return Data Service | |
FrxAPI:: |
public | function | Returns the fornea document manager | |
FrxAPI:: |
public | function | Report an error | |
FrxAPI:: |
public | function | Get the context of a specific id. | |
FrxAPI:: |
public | function | Get the current document | |
FrxAPI:: |
public | function | Load the contents of a file in the report file system. | |
FrxAPI:: |
function | Enter description here... | 1 | |
FrxAPI:: |
public | function | Pop data off of the stack. | |
FrxAPI:: |
public | function | Push data onto the Stack | |
FrxAPI:: |
public | function | Run a report with a particular format. | 1 |
FrxAPI:: |
public | function | Get the current report file system. | |
FrxAPI:: |
public | function | Set Data context by id. | |
FrxAPI:: |
public | function | Change to a specific document type. | |
FrxAPI:: |
public | function | Get list of skins. | |
ReportReplacer:: |
public | property | ||
ReportReplacer:: |
public | property | ||
ReportReplacer:: |
public | property | ||
ReportReplacer:: |
public | function | Define the fields associated with the formatter. | |
ReportReplacer:: |
public | function | ||
ReportReplacer:: |
protected | function |
Get the value from the data.
This is used by token_replace method to extract the data based on the path provided. Overrides TokenReplacerBase:: |
|
ReportReplacer:: |
public | function | Replaces nested array data. | |
ReportReplacer:: |
public | function |
Overrides TokenReplacerBase:: |
|
TokenReplacerBase:: |
protected | property | ||
TokenReplacerBase:: |
private | property | ||
TokenReplacerBase:: |
protected | property | ||
TokenReplacerBase:: |
public | function | Convert an object into an array | |
TokenReplacerBase:: |
public | function |
Replace the text in a report. Overrides TokenReplacerInterface:: |
|
TokenReplacerBase:: |
public | function | ||
TokenReplacerBase:: |
public | function |
Test for TRUE/FALSE for conditions that are able to be represented using bind parameters
Note that & are used to separate the different conditions and these are to be OR'd together. Overrides TokenReplacerInterface:: |
|
TokenReplacerBase:: |
public | function |
List all of the tokens used in a piece of text, ignoring duplicates. Overrides TokenReplacerInterface:: |