Commit dcb7e7c4 authored by Carsten  Rose's avatar Carsten Rose
Browse files

Feature #2948 /altsql, shead, stail

Manual.rst: describe new option altsql, shead, stail
Report.php: implement altsql, shead, stail.
parent e8c09a41
......@@ -639,13 +639,17 @@ QFQ Keywords (Bodytext)
+-------------------+---------------------------------------------------------------------------------+
| <level>.fend | End token for every field (=column) |
+-------------------+---------------------------------------------------------------------------------+
| <level>.head | Start token for whole <level> |
| <level>.shead | Static start token for whole <level>, independent if records are selected |
+-------------------+---------------------------------------------------------------------------------+
| <level>.tail | End token for whole <level> |
| <level>.stail | Static end token for whole <level>, independent if records are selected. |
+-------------------+---------------------------------------------------------------------------------+
| <level>.head | Dynamic start token for whole <level>. Only if at least one record is select. |
+-------------------+---------------------------------------------------------------------------------+
| <level>.tail | Dynamic end token for whole <level>. Only if at least one record is select. |
+-------------------+---------------------------------------------------------------------------------+
| <level>.rbeg | Start token for row. |
+-------------------+---------------------------------------------------------------------------------+
| <level>.rbgd | Alternating (per row) token |
| <level>.rbgd | Alternating (per row) token. |
+-------------------+---------------------------------------------------------------------------------+
| <level>.rend | End token for row. Will be rendered **before** subsequent levels are processed |
+-------------------+---------------------------------------------------------------------------------+
......@@ -657,7 +661,9 @@ QFQ Keywords (Bodytext)
+-------------------+---------------------------------------------------------------------------------+
| <level>.sql | SQL Query |
+-------------------+---------------------------------------------------------------------------------+
| <level>.althead | If <level>.sql is empty, these token will be rendered |
| <level>.althead | If <level>.sql is empty, these token will be rendered. |
+-------------------+---------------------------------------------------------------------------------+
| <level>.altsql | If <level>.sql is empty, these query will be fired. No sub queries. |
+-------------------+---------------------------------------------------------------------------------+
| debugShowBodyText | If='1' and config.qfq.ini:*SHOW_DEBUG_INFO = yes*, shows a tooltip with bodytext|
+-------------------+---------------------------------------------------------------------------------+
......
......@@ -1089,7 +1089,10 @@ const SENDMAIL_TOKEN_SRC = 'S';
const TOKEN_SQL = 'sql';
const TOKEN_HEAD = 'head';
const TOKEN_ALT_HEAD = 'althead';
const TOKEN_ALT_SQL = 'altsql';
const TOKEN_TAIL = 'tail';
const TOKEN_SHEAD = 'shead';
const TOKEN_STAIL = 'stail';
const TOKEN_RBEG = 'rbeg';
const TOKEN_REND = 'rend';
const TOKEN_RENR = 'renr';
......@@ -1103,7 +1106,7 @@ const TOKEN_FORM = CLIENT_FORM;
const TOKEN_RECORD_ID = CLIENT_RECORD_ID;
const TOKEN_DEBUG_BODYTEXT = TYPO3_DEBUG_SHOW_BODY_TEXT;
const TOKEN_VALID_LIST = 'sql|head|althead|tail|rbeg|rend|renr|rsep|fbeg|fend|fsep|rbgd|debug|form|r|debugShowBodyText|sqlLog|sqlLogMode';
const TOKEN_VALID_LIST = 'sql|head|althead|altsql|tail|shead|stail|rbeg|rend|renr|rsep|fbeg|fend|fsep|rbgd|debug|form|r|debugShowBodyText|sqlLog|sqlLogMode';
const TOKEN_COLUMN_CTRL = '_';
......
......@@ -444,6 +444,7 @@ class Report {
$this->variables->resultArray[$full_level . ".line."]["count"] = is_array($result) ? 1 : 0;
$this->variables->resultArray[$full_level . ".line."]["insertId"] = isset($stat[DB_INSERT_ID]) ? $stat[DB_INSERT_ID] : 0;
$content .= $this->variables->doVariables($this->frArray[$full_level . "." . TOKEN_SHEAD]);
// HEAD: If there is at least one record, do 'head'.
if ($rowTotal > 0) {
$content .= $this->variables->doVariables($this->frArray[$full_level . "." . TOKEN_HEAD]);
......@@ -499,12 +500,23 @@ class Report {
}
}
//Print althead or tail
if ($rowTotal > 0) {
// tail
$content .= $this->variables->doVariables($this->frArray[$full_level . "." . TOKEN_TAIL]);
} else {
// althead
$content .= $this->variables->doVariables($this->frArray[$full_level . "." . TOKEN_ALT_HEAD]);
// altsql
$sql = $this->variables->doVariables($this->frArray[$full_level . "." . TOKEN_ALT_SQL]);
if (!empty($sql)) {
$result = $this->db->sql($sql, ROW_KEYS, array(), '', $keys, $stat);
foreach ($result as $row) {
$rowIndex = 0;
$content .= $this->collectRow($row, $keys, $full_level, $rowIndex);
}
}
}
$content .= $this->variables->doVariables($this->frArray[$full_level . "." . TOKEN_STAIL]);
++$counter;
if (isset($this->indexArray[$counter]) && is_array($this->indexArray[$counter])) {
......
......@@ -944,10 +944,43 @@ EOF;
}
}
/**
*
*/
public function testReportPageWrapper() {
$line = <<<EOF
10.sql = SELECT firstname FROM Person ORDER BY id LIMIT 2
10.head = <table>
10.tail = </table>
10.rbeg = <tr>
10.rend = <br>
10.renr = </tr>
10.fbeg = <td>
10.fend = </td>
10.rsep = --
10.fsep = ++
10.10.sql = SELECT 'nested' FROM (SELECT '') AS fake WHERE '{{10.line.count}}'='1'
10.10.shead = Static head
10.10.stail = Static tail
10.10.head = Dynamic head
10.10.tail = Dynamic tail
10.10.althead = No record found
10.10.altsql = SELECT 'alt sql fired'
EOF;
$result = $this->report->process($line);
$expect = "<table><tr><td>John</td><br>Static headDynamic headnestedDynamic tailStatic tail</tr>--<tr><td>Jane</td><br>Static headNo record foundalt sql firedStatic tail</tr></table>";
$this->assertEquals($expect, $result);
}
/**
*
*/
public function testReportReplace() {
public function testReportVariables() {
$result = $this->report->process("10.sql = SELECT 'normal ', 'hidden' AS _hidden, 'text ' FROM Person ORDER BY id LIMIT 1");
$this->assertEquals("normal text ", $result);
......@@ -999,7 +1032,7 @@ EOF;
/**
*
*/
public function testReportPageWrapperReplace() {
public function testReportPageVariables() {
$line = <<<EOF
10.sql = SELECT name, firstname FROM Person ORDER BY id LIMIT 2
......
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