Skip to content
Snippets Groups Projects
Commit 2bc51505 authored by Carsten  Rose's avatar Carsten Rose
Browse files

Merge branch 'F15098_AS_function_in_variable' into 'develop'

F15098 as function in variable

See merge request !621
parents f59c758c a2c6acb5
No related branches found
No related tags found
4 merge requests!638Merge Develop to B16343,!637develop into F17086-Multiple-Forms-on-a-page,!626New version v23.10.1,!621F15098 as function in variable
Pipeline #10790 passed
......@@ -44,7 +44,7 @@ provided. Access to:
* :ref:`store-variables`
* :ref:`sql-variables`
* :ref:`row-column-variables`
* :ref:`link-column-variables`
* :ref:`link-function-column-variables`
Some examples, including nesting::
......@@ -72,6 +72,12 @@ Some examples, including nesting::
# Link Columns
{{p:form=Person&r=1|t:Edit Person|E|s AS link}}
# Function Columns: output in {{fullname:R}}
{{getFullname(pId) => fullname AS function}}
# Function Columns: output direct tt_content
{{getFullname(pId) AS function}}
Leading and trailing spaces inside curly braces are removed.
* ``{{ SELECT "Hello World" }}`` becomes ``{{SELECT "Hello World"}}``
......@@ -421,21 +427,42 @@ General note: using this type of variables is only the second choice. First choi
:ref:`access-column-values`) - using the STORE_RECORD is more portable cause no renumbering is needed if the level keys change.
.. _`link-column-variables`:
.. _`link-function-column-variables`:
Link column variables
---------------------
Link/Function column variables
------------------------------
Link column
^^^^^^^^^^^
These variables return a link, completely rendered in HTML. The syntax and all features of :ref:`column-link` are available.
The following code will render a *new person* button::
{{p:form&form=Person|s|N|t:new person AS link}}
For better reading, the format string might be wrapped in single or double quotes (this is optional): ::
Optional: For better reading, the format string might be wrapped in single or double quotes: ::
{{"p:form&form=Person|s|N|t:new person" AS link}}
These variables are especially helpful in:
Function column
^^^^^^^^^^^^^^^
Function column variables are helpful in:
* `report`, to create create links or buttons outside of an SQL statement. E.g. in `head`, `rbeg`, ...
* `form`, to create links and buttons in labels or notes.
Definition of a qfqFunction: Report with qfqFunction. Subheader: getFullname::
render = api
10.sql = SELECT CONCAT(lastName, ', ', firstName) FROM Person WHERE id = {{pId:R0}}
a) Somewhere in a different report or form::
{{getFullname(pId) AS function}}
b) Somewhere in a different report, output is returned in STORE_RECORD variable `fullname`::
{{getFullname(pId) => fullname AS function}}
......@@ -823,7 +823,6 @@ const SIP_EXCLUDE_XDEBUG_SESSION_START = 'XDEBUG_SESSION_START';
// FURTHER: all extracted params from 'urlparam
const ACTION_KEYWORD_SLAVE_ID = 'slaveId';
const VAR_RANDOM = 'random';
const VAR_FILE_DESTINATION = 'fileDestination';
const VAR_SLAVE_ID = ACTION_KEYWORD_SLAVE_ID;
......@@ -1783,7 +1782,7 @@ const LINE_ALT_INSERT_ID = 'altInsertId';
const COLUMN_LINK = 'link';
const COLUMN_EXEC = 'exec';
const COLUMN_THUMBNAIL = 'thumbnail';
const COLUMN_FUNCTION = 'function';
const COLUMN_PPAGE = 'Page';
const COLUMN_PPAGEC = 'Pagec';
const COLUMN_PPAGED = 'Paged';
......
......@@ -15,11 +15,11 @@ use IMATHUZH\Qfq\Core\Helper\OnString;
use IMATHUZH\Qfq\Core\Helper\Path;
use IMATHUZH\Qfq\Core\Helper\Support;
use IMATHUZH\Qfq\Core\Report\Link;
use IMATHUZH\Qfq\Core\Report\Report;
use IMATHUZH\Qfq\Core\Report\Tablesorter;
use IMATHUZH\Qfq\Core\Store\Sip;
use IMATHUZH\Qfq\Core\Store\Store;
const EVALUATE_DB_INDEX_DEFAULT = 0;
/**
* Class Evaluate
......@@ -52,9 +52,8 @@ class Evaluate {
private $endDelimiter = '';
private $endDelimiterLength = 0;
private $sqlKeywords = array('SELECT ', 'INSERT ', 'DELETE ', 'UPDATE ', 'SHOW ', 'REPLACE ', 'TRUNCATE ', 'DESCRIBE ', 'EXPLAIN ', 'SET ');
private $escapeTypeDefault = '';
private $report = null;
// private $debugStack = array();
......@@ -297,6 +296,34 @@ class Evaluate {
return DND_DATA_DND_API . '="' . Path::urlApi(API_DRAG_AND_DROP_PHP) . '?s=' . $s . '"';
}
/** Execute qfqFunction and output value. Content is accessible in record store
*
* @param $arrToken
* @param $foundInStore
* @return string
* @throws \CodeException
* @throws \UserFormException
* @throws \UserReportException
* @throws \DbException
*/
private function inlineFunction($arrToken, &$foundInStore): string {
$output = '';
$token = OnString::trimQuote(trim(implode(' ', $arrToken)));
if ($this->report === null) {
$this->report = new Report(array(), $this);
}
$this->report->doQfqFunction($token);
$foundInStore = TOKEN_FOUND_AS_COLUMN;
// Check for => in qfqFunction. If not given then output content.
if (!strpos($token, '=>')) {
$output = $this->store::getVar(COLUMN_FUNCTION_OUTPUT, STORE_RECORD);
}
return $output;
}
/**
* Tries to substitute $token.
* Token might be:
......@@ -395,6 +422,10 @@ class Evaluate {
$baseUrlAttribute = DATA_TABLESORTER_BASE_URL . "='" . $this->store->getVar(SYSTEM_BASE_URL, STORE_SYSTEM) . "'";
return ($this->tablesorter->inlineTablesorterView($arrToken[VAR_INDEX_VALUE], $foundInStore, $frCmd)) . $baseUrlAttribute;
break;
case COLUMN_FUNCTION:
return ($this->inlineFunction($arrToken, $foundInStore));
break;
default:
break;
}
......
......@@ -45,6 +45,7 @@ const DEFAULT_BOOTSTRAP_BUTTON = 'bootstrapButton';
/**
* Class Report
* @package qfq
*
*/
class Report {
......@@ -424,7 +425,7 @@ class Report {
* Return 'return values' in STORE_RECORD and QFQ function output in {{_output:R}}.
* BTW: the QFQ function is cached and read only once. The evaluation is not cached.
*
* @param $cmd # 'getFirstName(pId) => firstName, myLink'
* @param string $cmd # 'getFirstName(pId) => firstName, myLink'
* @throws \CodeException
* @throws \DbException
* @throws \DownloadException
......@@ -437,7 +438,7 @@ class Report {
* @throws \UserFormException
* @throws \UserReportException
*/
private function doQfqFunction($cmd) {
public function doQfqFunction(string $cmd): void {
// QFQ function cache
static $functionCache = array();
......
......@@ -20,6 +20,5 @@ $EM_CONF['qfq'] = array(
'conflicts' => [],
'suggests' => [],
],
);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment