Commit 50c06e12 authored by Carsten  Rose's avatar Carsten Rose
Browse files

WIP Refs #11998 - first implementation - throws an exception

parent 5744133f
Pipeline #5046 passed with stages
in 3 minutes and 52 seconds
......@@ -2719,7 +2719,7 @@ Example::
Example::
10.sql = SELECT "p:home&r=0|t:Home|c:qfq-100 qfq-left" AS _pagev
10.sql = SELECT "p:home&r=0|t:Home|c:qfq-100 qfq-left" AS _pages
Tablesorter
-----------
......
......@@ -22,7 +22,7 @@ Quick Form Query Extension
en
:Copyright:
2017-2020
2017-2021
:Authors:
Carsten Rose, Benjamin Baer
......
......@@ -1529,6 +1529,7 @@ const SENDMAIL_TOKEN_ATTACHMENT_PAGE = 'p';
// Report, BodyText
const TOKEN_SQL = 'sql';
const TOKEN_FUNCTION = 'function';
const TOKEN_TWIG = 'twig';
const TOKEN_HEAD = 'head';
const TOKEN_ALT_HEAD = 'althead';
......@@ -1553,7 +1554,7 @@ const TOKEN_DB_INDEX = F_DB_INDEX;
const TOKEN_CONTENT = 'content';
const TOKEN_REPORT_FILE = 'file';
const TOKEN_VALID_LIST = 'sql|twig|head|althead|altsql|tail|shead|stail|rbeg|rend|renr|rsep|fbeg|fend|fsep|fskipwrap|rbgd|debug|form|r|debugShowBodyText|dbIndex|sqlLog|sqlLogMode|content|render';
const TOKEN_VALID_LIST = 'sql|function|twig|head|althead|altsql|tail|shead|stail|rbeg|rend|renr|rsep|fbeg|fend|fsep|fskipwrap|rbgd|debug|form|r|debugShowBodyText|dbIndex|sqlLog|sqlLogMode|content|render';
const TOKEN_COLUMN_CTRL = '_';
......
......@@ -1076,8 +1076,7 @@ class Database {
* @throws \DbException
* @throws \UserFormException
*/
public function selectFormByName(string $formName, array $columnsToSelect = null)
{
public function selectFormByName(string $formName, array $columnsToSelect = null) {
// make sure to select column 'name'
if (is_array($columnsToSelect) && !in_array(F_NAME, $columnsToSelect)) {
$columnsToSelect[] = F_NAME;
......@@ -1102,4 +1101,36 @@ class Database {
}
}
/**
*
* @param $uid
* @param array $urlParam
* @return string
* @throws \CodeException
* @throws \DbException
* @throws \DownloadException
* @throws \PhpOffice\PhpSpreadsheet\Exception
* @throws \PhpOffice\PhpSpreadsheet\Reader\Exception
* @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
* @throws \Twig\Error\LoaderError
* @throws \Twig\Error\RuntimeError
* @throws \Twig\Error\SyntaxError
* @throws \UserFormException
* @throws \UserReportException
*/
public function getBodyText($uid, array $urlParam = array()) {
// Copy $urlParam to STORE_SIP
foreach ($urlParam as $key => $paramValue) {
$this->store->setVar($key, $paramValue, STORE_SIP);
}
$column = (is_numeric($uid)) ? 'uid' : 'subheader';
$dbT3 = $this->store->getVar(SYSTEM_DB_NAME_T3, STORE_SYSTEM);
$sql = "SELECT `bodytext` FROM `$dbT3`.`tt_content` WHERE `$column` = ?";
$arr = $this->sql($sql, ROW_EXPECT_1, [$uid]);
return ($arr['bodytext']);
}
}
\ No newline at end of file
......@@ -216,16 +216,16 @@ class KeyValueStringParser {
*
* E.g.: "a,b,'c,d',e" with delimiter ',' will result in [ 'a', 'b', 'c,d', 'e' ]
*
* @param $delimeter
* @param $delimiter
* @param $str
* @param int $limit
*
* @return array|bool
* @throws \CodeException
*/
public static function explodeWrapped($delimeter, $str, $limit = PHP_INT_MAX) {
public static function explodeWrapped($delimiter, $str, $limit = PHP_INT_MAX) {
if ($delimeter == '') {
if ($delimiter == '') {
return false;
}
......@@ -242,7 +242,7 @@ class KeyValueStringParser {
$onHold = '';
$cnt = 0;
$arr = explode($delimeter, $str, PHP_INT_MAX);
$arr = explode($delimiter, $str, PHP_INT_MAX);
foreach ($arr as $value) {
$trimmed = trim($value);
if ($value == '' && $startToken == '') {
......@@ -269,19 +269,19 @@ class KeyValueStringParser {
}
if ($cnt >= $limit) {
$final[$cnt - 1] .= $delimeter . $value;
$final[$cnt - 1] .= $delimiter . $value;
} else {
$final[] = $value;
$cnt++;
}
continue;
} else {
$onHold .= $delimeter . $value;
$onHold .= $delimiter . $value;
$lastChar = substr($trimmed, -1);
if ($startToken == $lastChar) {
if ($cnt >= $limit) {
$final[$cnt - 1] .= $delimeter . $onHold;
$final[$cnt - 1] .= $delimiter . $onHold;
} else {
$final[] = $onHold;
$cnt++;
......
......@@ -130,7 +130,7 @@ class OnArray {
/**
* Converts a onedimensional array by using htmlentities on all elements
* Converts a one-dimensional array by using html entities on all elements.
*
* @param array $arr
*
......
......@@ -337,4 +337,40 @@ class OnString {
public static function strContains(string $haystack, string $needle): bool {
return strpos($haystack, $needle) !== false;
}
/**
* Split a cmd "getFeUser(pId, pName, ...) : accountId, feUserUid, ..." into:
* rcFunctionName = getFeUser
* rcFunctionParam = [ 'pId', 'pName', ... ]
* rcReturnParam = [ 'accountId', 'feUserUid', ... ]
*
* @param $cmd
* @param $rcFunctionName
* @param $rcFunctionParam
* @param $rcReturnParam
*/
public static function splitFunctionCmd($cmd, &$rcFunctionName, &$rcFunctionParam, &$rcReturnParam) {
$rcFunctionName = '';
$rcFunctionParam = array();
$rcReturnParam = array();
if ($cmd == '') {
return;
}
// $cmd = "getFeUser(pId, pName) : accountId, feUserUid"
$split = explode(':', $cmd, 2);
// $split[0] = getFeUser(pId, pName), $split[1]=accountId, feUserUid
$functionArr = explode('(', $split[0], 2);
// $functionArr[0]='getFeUser', $functionArr[1]='pId, pName) '
$args = explode(')', $functionArr[1] ?? '', 2);
// $args[0]='pId, pName', $args[1]=' '
$rcFunctionName = trim($functionArr[0]);
$rcFunctionParam = OnArray::trimArray(explode(',', $args[0] ?? ''));
$rcReturnParam = OnArray::trimArray(explode(',', $split[1] ?? ''));
}
}
......@@ -353,6 +353,29 @@ class Download {
}
}
/**
* @param $uid
* @param $urlParam
* @return string
* @throws \CodeException
* @throws \DbException
* @throws \DownloadException
* @throws \PhpOffice\PhpSpreadsheet\Exception
* @throws \PhpOffice\PhpSpreadsheet\Reader\Exception
* @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
* @throws \Twig\Error\LoaderError
* @throws \Twig\Error\RuntimeError
* @throws \Twig\Error\SyntaxError
* @throws \UserFormException
* @throws \UserReportException
*/
private function getEvaluatedBodytext($uid, $urlParam) {
$bodytext = $this->db->getBodytext($uid, $urlParam);
$qfq = new QuickFormQuery([T3DATA_BODYTEXT => $bodytext], false, false);
return $qfq->process();
}
/**
* Interprets $element and fetches corresponding content, either as a file or the content in a variable.
*
......@@ -445,36 +468,6 @@ class Download {
return $filename;
}
/**
* @param $uid
* @param array $urlParam
*
* @return string
* @throws \CodeException
* @throws \DbException
* @throws \DownloadException
* @throws \PhpOffice\PhpSpreadsheet\Exception
* @throws \PhpOffice\PhpSpreadsheet\Reader\Exception
* @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
* @throws \Twig\Error\LoaderError
* @throws \Twig\Error\RuntimeError
* @throws \Twig\Error\SyntaxError
* @throws \UserFormException
* @throws \UserReportException
*/
private function getEvaluatedBodyText($uid, array $urlParam) {
foreach ($urlParam as $key => $paramValue) {
$this->store->setVar($key, $paramValue, STORE_SIP);
}
$dbT3 = $this->store->getVar(SYSTEM_DB_NAME_T3, STORE_SYSTEM);
$sql = "SELECT `bodytext` FROM `$dbT3`.`tt_content` WHERE `uid` = ?";
$tt_content = $this->db->sql($sql, ROW_EXPECT_1, [$uid]);
$qfq = new QuickFormQuery([T3DATA_BODYTEXT => $tt_content[T3DATA_BODYTEXT]], false, false);
return $qfq->process();
}
/**
* Creates a ZIP Files of all given $files
*
......
......@@ -307,7 +307,7 @@ class Report {
$index = $level . "." . $frCmd;
// throw exception if this level was already defined
if(!empty($this->frArray[$index])) {
if (!empty($this->frArray[$index])) {
throw new \UserReportException ("Double definition: $index is defined more than once.", ERROR_DOUBLE_DEFINITION);
}
// store complete line reformatted in frArray
......@@ -417,6 +417,50 @@ class Report {
return $sortArg;
}
/**
* @param $cmd
* @throws \CodeException
* @throws \DbException
* @throws \DownloadException
* @throws \PhpOffice\PhpSpreadsheet\Exception
* @throws \PhpOffice\PhpSpreadsheet\Reader\Exception
* @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
* @throws \Twig\Error\LoaderError
* @throws \Twig\Error\RuntimeError
* @throws \Twig\Error\SyntaxError
* @throws \UserFormException
* @throws \UserReportException
*/
private function doFunction($cmd) {
// Explode cmd
OnString::splitFunctionCmd($cmd, $rcFunctionName, $rcFunctionParam, $rcReturnParam);
// Save STORE_RECORD
$storeRecord = $this->store->getStore(STORE_RECORD);
// Fill STORE_RECORD with parameter
$tmp = array();
foreach ($rcFunctionParam as $key) {
$tmp[$key] = $storeRecord[$key] ?? '';
}
$this->store->setStore($tmp, STORE_RECORD, true);
// Get tt_content record bodytext
$bodytext = $this->db->getBodyText($rcFunctionName);
// Fire bodytext
$output = $this->process($bodytext);
// Restore and fill STORE_RECORD
$tmp = $this->store->getStore(STORE_RECORD);
foreach ($rcReturnParam as $key) {
$storeRecord[$key] = $tmp[$key] ?? '';
}
$this->store->setStore($storeRecord, STORE_RECORD, true);
}
/**
* Executes the queries recursive. This Method is called for each sublevel.
*
......@@ -495,6 +539,11 @@ class Report {
unset($this->variables->resultArray[$fullLevel . ".line."][LINE_TOTAL]);
unset($this->variables->resultArray[$fullLevel . ".line."][LINE_COUNT]);
// If defined, fire QFQ function
if ($this->frArray[$fullLevel . "." . TOKEN_FUNCTION] != '') {
$this->doFunction($this->frArray[$fullLevel . "." . TOKEN_FUNCTION]);
}
$sql = $this->variables->doVariables($this->frArray[$fullLevel . "." . TOKEN_SQL]);
$this->store->setVar(SYSTEM_SQL_FINAL, $sql, STORE_SYSTEM);
......
......@@ -15,7 +15,7 @@ if (!defined('TYPO3_MODE')) {
}
if (is_array($GLOBALS['TCA']['tt_content']['palettes'])) {
$GLOBALS['TCA']['tt_content']['palettes']['introheader']['showitem'] = 'header, CType';
$GLOBALS['TCA']['tt_content']['palettes']['introheader']['showitem'] = 'header, subheader, CType';
$GLOBALS['TCA']['tt_content']['palettes']['startendtime']['showitem'] = 'starttime, endtime';
$GLOBALS['TCA']['tt_content']['palettes']['layoutpalette1']['showitem'] = 'colPos, header_position, sys_language_uid';
$GLOBALS['TCA']['tt_content']['palettes']['layoutpalette2']['showitem'] = 'layout, header_layout';
......
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