From e2c81b5ea369ec332cb5db3d9c2b55a6ddac8b4e Mon Sep 17 00:00:00 2001
From: Carsten  Rose <carsten.rose@math.uzh.ch>
Date: Fri, 8 Apr 2016 14:00:04 +0200
Subject: [PATCH] Documentation/UsersManual/index.rst: example for page
 'search'. Rewrote to match Typo 6.x and 7.x Store.php, Constants.php:
 STORE_EMPTY implemented. Similar to STORE_ZERO, but returns allways an empty
 string instead of 0.

---
 extension/Documentation/UsersManual/Index.rst | 15 +++++++++------
 extension/qfq/qfq/Constants.php               |  1 +
 extension/qfq/qfq/store/Store.php             |  2 ++
 3 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/extension/Documentation/UsersManual/Index.rst b/extension/Documentation/UsersManual/Index.rst
index 5f0e79112..51d675f7b 100644
--- a/extension/Documentation/UsersManual/Index.rst
+++ b/extension/Documentation/UsersManual/Index.rst
@@ -213,8 +213,11 @@ Only variables that are known in a specified store can be substituted.
  +-----+----------------------------------------------------------------------------------------+----------------------------------------------------------------------------+
  | V   | Vars - Generic variables                                                               |                                                                            |
  +-----+----------------------------------------------------------------------------------------+----------------------------------------------------------------------------+
- | 0   | Value: 0, might be helpful if variable is empty but used in an SQL statement, which    | All possible keys                                                          |
- |     | might produce a SQL error otherwise if substituted with an empty string                |                                                                            |
+ | 0   | Zero - allways value: 0, might be helpful if a variable is empty or undefined and will | All possible keys                                                          |
+ |     | be used in an SQL statement.                                                           |                                                                            |
+ +-----+----------------------------------------------------------------------------------------+----------------------------------------------------------------------------+
+ | E   | Empty - allways value: 0, might be helpful if a variable is empty or undefined and will| All possible keys                                                          |
+ |     | be used in an SQL statement                                                            |                                                                            |
  +-----+----------------------------------------------------------------------------------------+----------------------------------------------------------------------------+
  | Y   | System: a) Database credentials, b) helper vars for logging/debugging:                 |                                                                            |
  |     | SYSTEM_SQL_RAW ... SYSTEM_FORM_ELEMENT_COLUMN                                          |                                                                            |
@@ -2165,13 +2168,14 @@ QFQ content record::
   # Creates a small form that redirects back to this page
   10 {
     sql = SELECT '_'
-    head = <form action='{{pageId:T}}'>Search for person by name: <input type='text' name='search' vaue='{{search:C0:all}}'><input type='submit'  value='Search'></form>
+    head = <form action='#' method='get'><input type='hidden' name='id' value='{{pageId:T}}'>Search for person by name: <input type='text' name='search' value='{{search:CE:all}}'><input type='submit'  value='Search'></form>
   }
 
   # SQL statement will find and list all the relevant persons
   20 {
-    sql = SELECT CONCAT('persondetail&form=person&r=', p.id) AS Pagee, CONCAT(p.lastName, ', ', p.firstName)
-              FROM person AS p WHERE CONCAT(p.lastName, ', ', p.firstName, ' ' ,    p.lastName) LIKE  '%{{search:C0:all}}%'
+    sql = SELECT CONCAT('?detail&form=form&r=', f.id) AS Pagee, f.name
+              FROM Form AS f
+              WHERE f.name LIKE  '%{{search:CE:all}}%'
     head = <table>
     tail = </table>
     rbeg = <tr>
@@ -2180,4 +2184,3 @@ QFQ content record::
     fend = </td>
   }
 
-
diff --git a/extension/qfq/qfq/Constants.php b/extension/qfq/qfq/Constants.php
index 35fbcaa14..7abfcf1e2 100644
--- a/extension/qfq/qfq/Constants.php
+++ b/extension/qfq/qfq/Constants.php
@@ -173,6 +173,7 @@ const STORE_CLIENT = "C"; // Client: POST variable, if not found: GET variable
 const STORE_TYPO3 = "T"; // Typo3 > Page content record > bodytext
 const STORE_VAR = "V"; // Generic Vars
 const STORE_ZERO = "0"; // value: 0, might helpfull if variable is empty but used in an SQL statement, which might produce a SQL error otherwise if substituted with an empty string
+const STORE_EMPTY = "E"; // value: '', might helpfull if variable is not defined and should result in an empty string instead of {{...}} (cause not replaced)
 const STORE_SYSTEM = "Y"; // various system values like db connection credentials
 
 const STORE_USE_DEFAULT = "FSRD";
diff --git a/extension/qfq/qfq/store/Store.php b/extension/qfq/qfq/store/Store.php
index 057bc2efa..5abd6b944 100644
--- a/extension/qfq/qfq/store/Store.php
+++ b/extension/qfq/qfq/store/Store.php
@@ -317,6 +317,8 @@ class Store {
                 switch ($store) {
                     case STORE_ZERO:
                         return 0;
+                    case STORE_EMPTY:
+                        return '';
                     case STORE_VAR:
                         if ($key === VAR_RANDOM) {
                             return self::randomAlphaNum(RANDOM_LENGTH);
-- 
GitLab