Commit 81605a73 authored by Carsten  Rose's avatar Carsten Rose
Browse files

Feature 4766: Set STORE_RECORD in Report per row.

Manual.rst: some short docs.
Support.php: add stripFirstCharIf()
Report.php: merge STORE_RECORD
parent 26b088c2
......@@ -4492,7 +4492,33 @@ Be careful to:
Access column values
^^^^^^^^^^^^^^^^^^^^
Columns of the upper / outer level result can be accessed via variables, eg. {{10.pId}} will be replaced by the value in the pId column.
Columns of the upper / outer level result can be accessed via variables in two ways
* STORE_RECORD: `{{pId:R}}`
* Level Key: `{{10.pId}}`
The STORE_RECORD will always be merged with previous content. The Level Keys are unique.
Example STORE_RECORD: ::
10.sql= SELECT p.id AS _pId, p.name FROM Person AS p
10.5.sql = SELECT adr.city, 'dummy' AS _pId FROM Address AS adr WHERE adr.pId={{pId:R}}
10.5.20.sql = SELECT '{{pId:R}}'
10.10.sql = SELECT '{{pId:R}}'
The line '10.10' will output 'dummy' in cases where there is at least one corresponding address.
If there are no addresses (all persons) it reports the person id.
If there is at least one address, it reports 'dummy', cause that's the last stored content. This behaviour might change in the future.
Example 'Level Key': ::
10.sql= SELECT p.id AS _pId, p.name FROM Person AS p
10.5.sql = SELECT adr.city, 'dummy' AS _pId FROM Address AS adr WHERE adr.pId={{10.pId}}
10.5.20.sql = SELECT '{{10.pId}}'
10.10.sql = SELECT '{{10.pId}}'
Notes to the level level:
+-------------+------------------------------------------------------------------------------------------------------------------------+
| Levels |A report is divided into levels. The Example has levels *10*, *20*, *30*, *30.5*, *30.5.1*, *50* |
......
......@@ -993,5 +993,25 @@ class Support {
}
}
/**
* Strips the first char $c from $data if the first char is equal to $c.
* Example: with $c='_' the $data='_pId' becomes 'pId'
*
* @param $c
* @param $data
* @return string
*/
public static function stripFirstCharIf($c, $data) {
if (empty($data)) {
return $data;
}
if ($data[0] == $c) {
$data = substr($data, 1);
}
return $data;
}
}
\ No newline at end of file
......@@ -556,16 +556,24 @@ class Report {
*/
private function collectRow(array $row, array $keys, $full_level, $rowIndex) {
$content = "";
$assoc = array();
$fsep = '';
for ($ii = 0; $ii < count($keys); $ii++) {
// Debugging
$this->store->setVar(SYSTEM_REPORT_COLUMN_INDEX, $ii + 1, STORE_SYSTEM);
$this->store->setVar(SYSTEM_REPORT_COLUMN_NAME, $keys[$ii], STORE_SYSTEM);
$this->store->setVar(SYSTEM_REPORT_COLUMN_VALUE, $row[$ii], STORE_SYSTEM);
$flagOutput = false;
$renderedColumn = $this->renderColumn($ii, $keys[$ii], $row[$ii], $full_level, $rowIndex, $flagOutput);
$keyAssoc = Support::stripFirstCharIf('_', $keys[$ii]);
if ($keyAssoc != '') {
$assoc[$keyAssoc] = $row[$ii];
}
if ($flagOutput) {
//prints
$content .= $this->variables->doVariables($fsep);
......@@ -576,6 +584,8 @@ class Report {
}
}
$this->store->appendToStore(STORE_RECORD, $assoc);
return ($content);
}
......
......@@ -838,7 +838,7 @@ class Store {
}
/**
* Append an array or the first row of array of arrays to store $storeName.
* Append an array (in case of 'array of array': the first row of array) to store $storeName.
* Existing values will be overwritten.
*
* @param $storeName
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment