Newer
Older

Carsten Rose
committed
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
* Class: **native**
* Type: **text**
* Name: city
* Label: City
* Value: `{{SELECT city FROM Address WHERE personId={{r}} ORDER BY id LIMIT 1}}`
* *FormElement*: insert/update address record
* Class: **action**
* Type: **afterSave**
* Label: Manage Address
* Parameter:
* `slaveId={{SELECT id FROM Address WHERE personId={{r}} ORDER BY id LIMIT 1}}`
* `sqlInsert={{INSERT INTO Address (personId, city) VALUES ({{r}}, '{{city:F:allbut:s}}') }}`
* `sqlUpdate={{UPDATE Address SET city='{{city:F:allbut:s}}' WHERE id={{slaveId:V}} }}`
* `sqlDelete={{DELETE FROM Address WHERE id={{slaveId:V}} AND ''='{{city:F:allbut:s}}' LIMIT 1}}`
Form: Person Wizard - firstname, single note
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Requirement: A form that displays the column 'firstname' from table 'Person' and 'note' from table 'Note'.
If the records don't exist, the form should create it.
Column Person.noteId points to Note.id
Form primary table: Person
Form slave table: Address
Relation: `Person.id = Address.personId`
* Form: wizard
* Name: wizard
* Title: Person Wizard
* Table: Person
* Render: bootstrap
* *FormElement*: firstname
* Class: **native**
* Type: **text**
* Name: firstname
* Label: Firstname
* *FormElement*: email, text, 20
* Class: **native**
* Type: **text**
* Name: note
* Label: Note
* Value: `{{SELECT Note FROM Note AS n, Person AS p WHERE p.id={{r}} AND p.noteId=n.id ORDER BY id }}`
* *FormElement*: insert/update address record
* Class: **action**
* Type: **afterSave**
* Name: noteId
* Label: Manage Note
* Parameter:
* `sqlInsert={{INSERT INTO Note (note) VALUES ('{{note:F:allbut:s}}') }}`
* `sqlUpdate={{UPDATE Note SET note='{{note:F:allbut:s}}' WHERE id={{slaveId:V}} }}`
.. _example_class_template_group:

Carsten Rose
committed
Icons Template Group
^^^^^^^^^^^^^^^^^^^^
This example will display graphics instead of text 'add' and 'remove'. Also there is a distance between the templateGroups.

Carsten Rose
committed
* FormElement.parameter::

Carsten Rose
committed
tgClass = qfq-child-margin-top
tgAddClass = btn alert-success
tgAddText = <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
tgRemoveClass = btn btn-danger alert-danger
tgRemoveText = <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>

Carsten Rose
committed
Chart
^^^^^
* QFQ delivers a chart JavaScript lib: https://github.com/nnnick/Chart.js.git. Docs: http://www.chartjs.org/docs/
* The library is not sourced in the HTML page automatically. To do it, either include the lib
`typo3conf/ext/qfq/Resources/Public/JavaScript/Chart.min.js`:
* in the specific tt_content record (shown below in the example) or
* system wide via Typo3 Template record.
* By splitting HTML and JavaScript code over several lines, take care not accidentally to create a 'nesting'-end token.

Carsten Rose
committed
Check the line after `10.tail =`. It's '}' alone on one line. This is a valid 'nesting'-end token!. There are two options
to circumvent this:
* Don't nest the HTML & JavaScript code - bad workaround, this is not human readable.
* Select different nesting token, e.g. '<' (check the first line on the following example). ::

Carsten Rose
committed
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
# <
10.sql = SELECT '_'
10.head =
<div style="height: 1024px; width: 640px;">
<h3>Distribution of FormElement types over all forms</h3>
<canvas id="barchart" width="1240" height="640"></canvas>
</div>
<script src="typo3conf/ext/qfq/Resources/Public/JavaScript/Chart.min.js"></script>
<script>
$(function () {
var ctx = document.getElementById("barchart");
var barChart = new Chart(ctx, {
type: 'bar',
data: {
10.tail =
}
});
});
</script>
# Labels
10.10 <
sql = SELECT "'", fe.type, "'" FROM FormElement AS fe GROUP BY fe.type ORDER BY fe.type
head = labels: [
tail = ],
rsep = ,
>
# Data
10.20 <
sql = SELECT COUNT(fe.id) FROM FormElement AS fe GROUP BY fe.type ORDER BY fe.type
head = datasets: [ { data: [
tail = ], backgroundColor: "steelblue", label: "FormElements" } ]
rsep = ,
>
Upload Form Simple
^^^^^^^^^^^^^^^^^^
Table Person
+---------------------+--------------+
| Name | Type |
+=====================+==============+
| id | int |
+---------------------+--------------+
| name | varchar(255) |
+---------------------+--------------+
| pathFileNamePicture | varchar(255) |
+---------------------+--------------+
| pathFileNameAvatar | varchar(255) |
+---------------------+--------------+
* Form:
* Name: UploadSimple
* Table: Person
* FormElements:
* Name: name
* Type: text
* Label: Name
* Name: pathFileNamePicture
* Type: upload
* Label: Picture
* Parameter::
fileDestination=fileadmin/user/{{id:R0}}-picture-{{filename}}
* Name: pathFileNameAvatar
* Type: upload
* Label: Avatar
* Parameter::
fileDestination=fileadmin/user/{{id:R0}}-avatar-{{filename}}
Upload Form Advanced 1
^^^^^^^^^^^^^^^^^^^^^^
Table: Person
+---------------------+--------------+
| Name | Type |
+=====================+==============+
| id | int |
+---------------------+--------------+
| name | varchar(255) |
+---------------------+--------------+
Table: Note
+---------------------+--------------+
| Name | Type |
+=====================+==============+
| id | int |
+---------------------+--------------+
| pId | int |
+---------------------+--------------+
| type | varchar(255) |
+---------------------+--------------+
| pathFileName | varchar(255) |
+---------------------+--------------+
* Form:
* Name: UploadAdvanced1
* Table: Person
* FormElements
* Name: name
* Type: text
* Label: Name
* Name: mypathFileNamePicture
* Type: upload
* Label: Picture
* Value: {{SELECT pathFileName FROM Note WHERE id={{slaveId}} }}
* Parameter::
fileDestination=fileadmin/user/{{id:R0}}-picture-{{filename}}
slaveId={{SELECT id FROM Note WHERE pId={{id:R0}} AND type='picture' LIMIT 1}}
sqlInsert={{INSERT INTO Note (pathFileName, type, pId) VALUE ('{{fileDestination}}', 'picture', {{id:R0}}) }}
sqlUpdate={{UPDATE Note SET pathFileName = '{{fileDestination}}' WHERE id={{slaveId}} LIMIT 1}}
sqlDelete={{DELETE FROM Note WHERE id={{slaveId}} LIMIT 1}}
* Name: mypathFileNameAvatar
* Type: upload
* Label: Avatar
* Value: {{SELECT pathFileName FROM Note WHERE id={{slaveId}} }}
* Parameter::
fileDestination=fileadmin/user/{{id:R0}}-avatar-{{filename}}
slaveId={{SELECT id FROM Note WHERE pId={{id:R0}} AND type='avatar' LIMIT 1}}
sqlInsert={{INSERT INTO Note (pathFileName, type, pId) VALUE ('{{fileDestination}}', 'avatar', {{id:R0}}) }}
sqlUpdate={{UPDATE Note SET pathFileName = '{{fileDestination}}' WHERE id={{slaveId}} LIMIT 1}}
sqlDelete={{DELETE FROM Note WHERE id={{slaveId}} LIMIT 1}}
Upload Form Advanced 2
^^^^^^^^^^^^^^^^^^^^^^
Table: Person
+---------------------+--------------+
| Name | Type |
+=====================+==============+
| id | int |
+---------------------+--------------+
| name | varchar(255) |
+---------------------+--------------+
| noteIdPicture | int |
+---------------------+--------------+
| noteIdAvatar | int |
+---------------------+--------------+
Table: Note
+---------------------+--------------+
| Name | Type |
+=====================+==============+
| id | int |
+---------------------+--------------+
| pathFileName | varchar(255) |
+---------------------+--------------+
* Form:
* Name: UploadAdvanced2
* Table: Person
* FormElements
* Name: name
* Type: text
* Label: Name
* Name: mypathFileNamePicture
* Type: upload
* Label: Picture
* Value: {{SELECT pathFileName FROM Note WHERE id={{slaveId}} }}
* Parameter::
fileDestination=fileadmin/user/{{id:R0}}-picture-{{filename}}
slaveId={{SELECT id FROM Note WHERE id={{noteIdPicture}} LIMIT 1}}
sqlInsert={{INSERT INTO Note (pathFileName) VALUE ('{{fileDestination}}') }}
sqlUpdate={{UPDATE Note SET pathFileName = '{{fileDestination}}' WHERE id={{slaveId}} LIMIT 1}}
sqlDelete={{DELETE FROM Note WHERE id={{slaveId}} LIMIT 1}}
sqlAfter={{UPDATE Person SET noteIdPicture={{slaveId}} WHERE id={{id:R0}} LIMIT 1
* Name: mypathFileNameAvatar
* Type: upload
* Label: Avatar
* Value: {{SELECT pathFileName FROM Note WHERE id={{slaveId}} }}
* Parameter::
fileDestination=fileadmin/user/{{id:R0}}-avatar-{{filename}}
slaveId={{SELECT id FROM Note WHERE id={{noteIdAvatar}} LIMIT 1}}
sqlInsert={{INSERT INTO Note (pathFileName) VALUE ('{{fileDestination}}') }}
sqlUpdate={{UPDATE Note SET pathFileName = '{{fileDestination}}' WHERE id={{slaveId}} LIMIT 1}}
sqlDelete={{DELETE FROM Note WHERE id={{slaveId}} LIMIT 1}}
sqlAfter={{UPDATE Person SET noteIdAvatar={{slaveId}} WHERE id={{id:R0}} LIMIT 1
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
Typeahead: SQL
^^^^^^^^^^^^^^
Table: Person
+---------------------+--------------+
| Name | Type |
+=====================+==============+
| id | int |
+---------------------+--------------+
| name | varchar(255) |
+---------------------+--------------+
* Form:
* Name: PersonNameTypeahead
* Table: Person
* FormElements
* Name: name
* Type: text
* Label: Name
* Parameter: ``typeAheadSql = SELECT name FROM Person WHERE name LIKE ? OR firstName LIKE ? LIMIT 100``
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
Typeahead: LDAP with additional values
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Table: Person
+---------------------+--------------+
| Name | Type |
+=====================+==============+
| id | int |
+---------------------+--------------+
| name | varchar(255) |
+---------------------+--------------+
| firstname | varchar(255) |
+---------------------+--------------+
| email | varchar(255) |
+---------------------+--------------+
* Form:
* Name: PersonNameTypeaheadSetNames
* Table: Person
* Parameter::
ldapServer = directory.example.com
ldapBaseDn = ou=Addressbook,dc=example,dc=com
* FormElements
* Name: email
* Class: native
* Type: text
* Label: Email
* Note: Name: {{cn:LE}}<br>Email: {{mail:LE}}
* dynamicUpdate: checked
* Parameter::
# Typeahead
typeAheadLdapSearch = (|(cn=*?*)(mail=*?*))
typeAheadLdapValuePrintf ‘%s / %s’, cn, email
typeAheadLdapIdPrintf ‘%s’, email
# dynamicUpdate: show note
fillStoreLdap
ldapSearch = (mail={{email::alnumx}})
ldapAttributes = cn, email
* Name: fillLdapValues
* Class: action
* Type: afterSave
* Parameter::
fillStoreLdap
ldapSearch = (mail={{email::alnumx}})
ldapAttributes = cn, email
slaveId={{id:R0}}
sqlUpdate={{ UPDATE Person AS p SET p.name='{{cn:L:alnumx:s}}' WHERE p.id={{slaveId}} LIMIT 1 }}
Import/merge form
-----------------
The form `copyFormFromExt` copies a form from table `ExtForm / ExtFormElement` to `Form / FormElement`. The import/merge

Carsten Rose
committed
* offers a drop down list with all forms of `ExtForm`,
* an input element for the new form name,
* create new Form.id
* copied FormElements get the new Form.id.
* the copied form will be opened in the FormEditor.

Carsten Rose
committed

Carsten Rose
committed
* Play (do all sql statements on your QFQ database, e.g. via `mysql <dbname> < copyFormFromExt.sql` or `phpMyAdmin`) the
file *<ext_dir>/Classes/Sql/copyFormFromExt.sql*.
* Insert a link/button 'Copy form from ExtForm' to open the import/merge form. A good place is the list of all forms (see `form-editor`_).
E.g.: ::

Carsten Rose
committed
10.head = {{'b|p:id={{pageAlias:T}}&form=copyFormFromExt|t:Copy form from ExtForm' AS _link }} ...

Carsten Rose
committed
If there are several T3/QFQ instances and if forms should be imported frequently/easily, set up a one shot
'import Forms from db xyz' like: ::
10.sql = CREATE OR REPLACE table ExtForm SELECT * FROM <db xyz>.Form
20.sql = CREATE OR REPLACE table ExtFormElement SELECT * FROM <db xyz>.FormElement

Carsten Rose
committed

Carsten Rose
committed
Report
======
QFQ content element
-------------------
The QFQ extension is activated through tt-content records. One or more tt-content records per page are necessary to render
*forms* and *reports*. Specify column and language per content record as wished.

Carsten Rose
committed
The title of the QFQ content element will not be rendered. It's only visible in the backend for orientation of the webmaster.

Carsten Rose
committed
To display a report on any given TYPO3 page, create a content element of type 'QFQ Element' (plugin) on that page.
A simple example
^^^^^^^^^^^^^^^^

Carsten Rose
committed
Assume that the database has a table person with columns firstName and lastName. To create a simple list of all persons, we can do the following::

Carsten Rose
committed
10.sql = SELECT firstName, lastName FROM person

Carsten Rose
committed
The '10' indicates a *root level* of the report (see section `Structure`_). The expression '10.sql' defines an SQL query
for the specific level. When the query is executed, it will return a result having one single column name containing first and last name

Carsten Rose
committed
separated by a space character.
The HTML output, displayed on the page, resulting from only this definition, could look as follows::

Carsten Rose
committed

Carsten Rose
committed
I.e., QFQ will simply output the content of the SQL result row after row for each single level.
Format output: mix style and content
""""""""""""""""""""""""""""""""""""

Carsten Rose
committed
Variant 1: pure SQL
;;;;;;;;;;;;;;;;;;;

Carsten Rose
committed
To format the upper example, just create additional columns::

Carsten Rose
committed
10.sql = SELECT firstName, ", ", lastName, "<br>" FROM person

Carsten Rose
committed
HTML output::

Carsten Rose
committed
Doe, John<br>
Miller, Jane<br>
Star, Frank<br>
Variant 2: SQL plus QFQ helper
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
QFQ provides several helper functions to wrap rows and columns, or to separate them. In this example 'fsep'='field
separate and 'rend' = row end:

Carsten Rose
committed
10.sql = SELECT firstName, lastName FROM person
10.fsep = ', '
10.rend = <br>
HTML output::
Doe, John<br>
Miller, Jane<br>
Star, Frank<br>
Check out all QFQ helpers under qfq_keywords_.
Due to mixing style and content, this becomes harder to maintain with more complex layout.
Format output: separate style and content
"""""""""""""""""""""""""""""""""""""""""
The result of the query can be passed to the `Twig template engine <https://twig.symphony.com/>`_
in order to fill a template with the data.::

Carsten Rose
committed
10.sql = SELECT firstName, lastName FROM person
10.twig = {% for row in result %}
{{ row.lastName }}, {{ row.firstName }<br />
{% endfor %}
HTML output::
Doe, John<br>
Miller, Jane<br>
Star, Frank<br>
Check out using-twig_.

Carsten Rose
committed
.. _`syntax-of-report`:
------------------

Carsten Rose
committed
All **root level queries** will be fired in the order specified by 'level' (Integer value).

Carsten Rose
committed
For **each** row of a query (this means *all* queries), all subqueries will be fired once.

Carsten Rose
committed
* E.g. if the outer query selects 5 rows, and a nested query select 3 rows, than the total number of rows are 5 x 3 = 15 rows.

Carsten Rose
committed
There is a set of **variables** that will get replaced before ('count' also after) the SQL-Query gets executed:

Carsten Rose
committed
``{{<name>[:<store/s>[:...]]}}``
Variables from specific stores.

Carsten Rose
committed

Carsten Rose
committed
``{{<name>:R}}`` - use case of the above generic definition. See also `access-column-values`_.

Carsten Rose
committed

Carsten Rose
committed
``{{<level>.<columnName>}}``
Similar to ``{{<name>:R}}`` but more specific. There is no sanitize class, escape mode or default value.
``{{<level>.line.count}}`` - Current row index
This variable is specific, as it will be replaced before the query is fired in case of ``<level>`` is an outer/previous
level or it will be replaced after a query is fired in case ``<level>`` is the current level.

Carsten Rose
committed
``{{<level>.line.total}}``
Total rows (MySQL ``num_rows`` for *SELECT* and *SHOW*, MySQL ``affected_rows`` for *UPDATE* and *INSERT*.

Carsten Rose
committed
``{{<level>.line.insertId}}``
Last insert id for *INSERT*.

Carsten Rose
committed
``{{<level>.line.content}}``
If the content of `<level>` have been stored, e.g. `<level>.content=hide`.
``{{<level>.line.altCount}}`` - Like 'line.count' but for 'alt' query.
``{{<level>.line.altTotal}}`` - Like 'line.total' but for 'alt' query.
``{{<level>.line.altInsertId}}`` - Like 'line.insertId' but for 'alt' query.

Carsten Rose
committed
See :ref:`variables` for a full list of all available variables.

Carsten Rose
committed
Different types of SQL queries are possible: SELECT, INSERT, UPDATE, DELETE, SHOW, REPLACE

Carsten Rose
committed
Only SELECT and SHOW queries will fire subqueries.

Carsten Rose
committed
Processing of the resulting rows and columns:

Carsten Rose
committed
* In general, all columns of all rows will be printed out sequentially.
* On a per column base, printing of columns can be suppressed by starting the column name with an underscore '_'. E.g.
`SELECT id AS _id`.

Carsten Rose
committed
This might be useful to store values, which will be used later on in another query via the `{{id:R}}` or

Carsten Rose
committed
`{{<level>.columnName}}` variable. To suppress printing of a column, use a underscore as column name prefix. E.g.

Carsten Rose
committed

Carsten Rose
committed
*Reserved column names* have a special meaning and will be processed in a special way. See
`Processing of columns in the SQL result`_ for details.

Carsten Rose
committed
There are extensive ways to wrap columns and rows. See :ref:`wrapping-rows-and-columns`

Carsten Rose
committed
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
.. _`using-twig`:
Using Twig
----------
How to write Twig templates is documented by the `Twig Project <https://twig.symphony.com/>`_.
QFQ passes the result of a given query to the corresponding Twig template using the Twig variable
`result`. So templates need to use this variable to access the result of a query.
Specifying a Template
^^^^^^^^^^^^^^^^^^^^^
By default the string passed to the **twig**-key is used as template directly,
as shown in the simple example above::
10.twig = {% for row in result %}
{{ row.lastName }}, {{ row.firstName }<br />
{% endfor %}
However, if the string starts with **file:**, the template is read from the
file specified.::
10.twig = file:table_sortable.html.twig
The file is searched relative to *<site path>* and if the file is not found there, it's searched relative to
QFQ's *twig_template* folder where the included base templates are stored.
The following templates are available:
``tables/default.html.twig``
A basic table with column headers, sorting and column filters using tablesorter and bootstrap.
``tables/single_vertical.html.twig``
A template to display the values of a single record in a vertical table.
Links
^^^^^
The link syntax described in column-link_ is available inside Twig templates
using the `qfqlink` filter::
{{ "u:http://www.example.com" | qfqlink }}
will render a link to *http://www.example.com*.
Json Decode
^^^^^^^^^^^
A String can be JSON decoded in Twig the following way::
{% set decoded = '["this is one", "this is two"]' | json_decode%}
This can then be used as a normal object in Twig::
{{ decoded[0] }}
will render *this is one*.
Available Store Variables
^^^^^^^^^^^^^^^^^^^^^^^^^
QFQ also provides access to the following stores via the template context.
* record
* sip
* typo3
* user
* system
All stores are accessed using their lower case name as attribute of the
context variable `store`. The active Typo3 front-end user is therefore available as::
{{ store.typo3.feUser }}

Carsten Rose
committed
Example
^^^^^^^
The following block shows an example of a QFQ report.
*10.sql* selects all users who have been assigned files in our file tracker.
.. TODO use content = hide instead of _user once this is implemented
*10.10* then selects all files belonging to this user, prints the username as header

Carsten Rose
committed
and then displays the files in a nice table with links to the files. ::
10.sql = SELECT assigned_to AS _user FROM file_tracker

Carsten Rose
committed
WHERE assigned_to IS NOT NULL
GROUP BY _user
ORDER BY _user
10.10.sql = SELECT id, path_scan FROM file_tracker
WHERE assigned_to = '{{user:R}}'
10.10.twig = <h2>{{ store.record.user }}</h2>

Carsten Rose
committed
<table id="file-list" class="table table-hover tablesorter" id="{{pageAlias:T}}-twig">
<thead><tr><th>ID</th><th>File</th></tr></thead>
<tbody>
{% for row in result %}
<tr>
<td>{{ row.id }}</td>
<td>{{ ("d:|M:pdf|s|t:"~ row.path_scan ~"|F:" ~ row.path_scan ) | qfqlink }}</td>
</tr>
{% endfor %}
</tbody>
</table>

Carsten Rose
committed
Debug the bodytext
------------------
The parsed bodytext could be displayed by activating 'showDebugInfo' (:ref:`debug`) and specifying

Carsten Rose
committed
::
debugShowBodyText = 1
A small symbol with a tooltip will be shown, where the content record will be displayed on the webpage.
Note: :ref:`debug` information will only be shown with *showDebugInfo: yes* in configuration_.

Carsten Rose
committed
.. _`inline-report`:
Inline Report editing
---------------------
For quick changes it can be bothersome to go to the TYPO3 backend to update the page content and reload the page.
For this reason, QFQ offers an inline report editing feature whenever there is a TYPO3 BE user logged in. A small
link symbol will appear on the right-hand side of each report record. Please note that the TYPO3 Frontend cache
is also deleted upon each inline report save.

Carsten Rose
committed
In order for the inline report editing to work, QFQ needs to be able to access the T3 database. This database
is assumed to be accessible with the same credentials as specified with indexQfq.

Carsten Rose
committed
Structure
---------
A report can be divided into several levels. This can make report definitions more readable because it allows for
splitting of otherwise excessively long SQL queries. For example, if your SQL query on the root level selects a number
of person records from your person table, you can use the SQL query on the second level to look up the city where each person lives.

Carsten Rose
committed
See the example below::

Carsten Rose
committed
10.sql = SELECT id AS _pId, CONCAT(firstName, " ", lastName, " ") AS name FROM person

Carsten Rose
committed
10.10.sql = SELECT CONCAT(postal_code, " ", city) FROM address WHERE pId = {{10.pId}}
10.10.rbeg = (
10.10.rend = )
This would result in::

Carsten Rose
committed
John Doe (3004 Bern)
Jane Miller (8008 Zürich)
Frank Star (3012 Bern)
Text across several lines
^^^^^^^^^^^^^^^^^^^^^^^^^
To get better human readable SQL queries, it's possible to split a line across several lines. Lines

Carsten Rose
committed
with keywords are on their own (`QFQ Keywords (Bodytext)`_ start a new line). If a line is not a 'keyword' line, it will
be appended to the last keyword line. 'Keyword' lines are detected on:
* <level>.<keyword> =
* {

Carsten Rose
committed
Example::
10.sql = SELECT 'hello world'
FROM mastertable

Carsten Rose
committed
10.tail = End
20.sql = SELECT 'a warm welcome'
'some additional', 'columns'
FROM another_table

Carsten Rose
committed
WHERE id>100
20.head = <h3>
20.tail = </h3>
Join mode: SQL

Carsten Rose
committed
""""""""""""""

Carsten Rose
committed
This is the default. All lines are joined with a *space* in between. E.g.::
10.sql = SELECT 'hello world'
FROM mastertable
Results to: ``10.sql = SELECT 'hello world' FROM mastertable``
Notice the space between "...world'" and "FROM ...".
Join mode: strip whitespace

Carsten Rose
committed
"""""""""""""""""""""""""""
Ending a line with a \\ strips all leading and trailing whitespaces of that line joins the line directly (no extra

Carsten Rose
committed
space in between). E.g.::
10.sql = SELECT 'hello world', 'd:final.pdf \
|p:id=export \
|t:Download' AS _pdf \
Results to: ``10.sql = SELECT 'hello world', 'd:final.pdf|p:id=export|t:Download' AS _pdf``
Note: the \\ does not force the joining, it only removes the whitespaces.

Carsten Rose
committed
To get the same result, the following is also possible::
10.sql = SELECT 'hello world', CONCAT('d:final.pdf'
'|p:id=export',
'|t:Download') AS _pdf

Carsten Rose
committed
Nesting of levels
^^^^^^^^^^^^^^^^^

Carsten Rose
committed
Levels can be nested. E.g.::

Carsten Rose
committed
10 {
sql = SELECT ...
5 {
sql = SELECT ...
head = ...
}
}

Carsten Rose
committed
This is equal to::

Carsten Rose
committed
10.sql = SELECT ...
10.5.sql = SELECT ...
10.5.head = ...

Carsten Rose
committed
Leading / trailing spaces
^^^^^^^^^^^^^^^^^^^^^^^^^
By default, leading or trailing whitespaces are removed from strings behind '='. E.g. 'rend = test ' becomes 'test' for

Carsten Rose
committed
rend. To prevent any leading or trailing spaces, surround them by using single or double ticks. Example::

Carsten Rose
committed
10.sql = SELECT name FROM Person
10.rsep = ' '
10.head = "Names: "

Carsten Rose
committed
Braces character for nesting
^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Carsten Rose
committed
By default, curly braces '{}' are used for nesting. Alternatively angle braces '<>', round braces '()' or square
braces '[]' are also possible. To define the braces to use, the **first line** of the bodytext has to be a comment line and the

Carsten Rose
committed
last character of that line must be one of '{[(<'. The corresponding braces are used for that QFQ record. E.g.::

Carsten Rose
committed
# Specific code. >
10 <
sql = SELECT
head = <script>
data = [
{
10, 20
}
]
</script>
>
Per QFQ tt-content record, only one type of nesting braces can be used.
Be careful to:
* write nothing else than whitespaces/newline behind an **open brace**

Carsten Rose
committed
* the **closing brace** has to be alone on a line::

Carsten Rose
committed
10.sql = SELECT 'Yearly Report'

Carsten Rose
committed
20 {
sql = SELECT companyName FORM Company LIMIT 1

Carsten Rose
committed
head = <h1>
tail = </h1>
}
30 {
sql = SELECT depName FROM Department
head = <p>
tail = </p>
5 {
sql = SELECT 'detailed information for department'
1.sql = SELECT name FROM Person LIMIT 7
1.head = Employees:

Carsten Rose
committed
}
}
30.5.tail = More will follow

Carsten Rose
committed
50
{
sql = SELECT 'A query with braces on their own'
}
.. _`access-column-values`:

Carsten Rose
committed
Access column values
^^^^^^^^^^^^^^^^^^^^

Carsten Rose
committed
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.
Multiple columns, with the same column name, can't be accessed individually. Only the last column is available.

Carsten Rose
committed
Retrieving the *final* value of `special-column-names`_ is possible via '{{&<column>:R}}. Example::
10.sql = SELECT 'p:home&form=Person|s|b:success|t:Edit' AS _link
10.20.sql = SELECT '{{link:R}}', '{{&link:R}}'
The first column of row `10.20` returns 'p:home&form=Person|s|b:success|t:Edit',the second column returns
'<span class="btn btn-success"><a href="?home&s=badcaffee1234">Edit</a></span>'.

Carsten Rose
committed
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.

Carsten Rose
committed
If there is at least one address, it reports 'dummy', cause that's the last stored content.

Carsten Rose
committed
Example 'level'::
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}}'

Carsten Rose
committed
+-------------+------------------------------------------------------------------------------------------------------------------------+
| Levels |A report is divided into levels. The Example has levels *10*, *20*, *30*, *30.5*, *30.5.1*, *50* |
+-------------+------------------------------------------------------------------------------------------------------------------------+
| Qualifier |A level is divided into qualifiers *30.5.1* has 3 qualifiers *30*, *5*, *1* |
+-------------+------------------------------------------------------------------------------------------------------------------------+
| Root levels |Is a level with one qualifier. E.g.: 10 |
+-------------+------------------------------------------------------------------------------------------------------------------------+
| Sub levels |Is a level with more than one qualifier. E.g. levels *30.5* or *30.5.1* |
+-------------+------------------------------------------------------------------------------------------------------------------------+
| Child |The level *30* has one child and child child: *30.5* and *30.5.1* |
+-------------+------------------------------------------------------------------------------------------------------------------------+
| Example | *10*, *20*, *30*, *50** are root level and will be completely processed one after each other. |
| | *30.5* will be executed as many times as *30* has row numbers. |
| | *30.5.1* will be executed as many times as *30.5* has row numbers. |
+-------------+------------------------------------------------------------------------------------------------------------------------+

Carsten Rose
committed

Carsten Rose
committed
Report Example 1::

Carsten Rose
committed
# Displays current date
10.sql = SELECT CURDATE()
# Show all students from the person table
20.sql = SELECT p.id AS pId, p.firstName, " - ", p.lastName FROM person AS p WHERE p.typ LIKE "student"
# Show all the marks from the current student ordered chronological
20.25.sql = SELECT e.mark FROM exam AS e WHERE e.pId={{20.pId}} ORDER BY e.date
# This query will never be fired, cause there is no direct parent called 20.30.
20.30.10.sql = SELECT 'never fired'
.. _wrapping-rows-and-columns:
Wrapping rows and columns: Level
--------------------------------

Carsten Rose
committed
Order and nesting of queries, will be defined with a TypoScript-alike syntax::
level.sublevel1.subsublevel2. ...
* Each 'level' directive needs a final key, e.g: 20.30.10. **sql**.
* A key **sql** is necessary in order to process a level.

Carsten Rose
committed
See all `QFQ Keywords (Bodytext)`_.

Carsten Rose
committed
Processing of columns in the SQL result
---------------------------------------
* The content of all columns of all rows will be printed sequentially, without separator (except one is defined).
* Rows with `special-column-names`_ will be rendered internally by QFQ and the QFQ output of such processing (if there
is any) is taken as the content.
.. _special-column-names:

Carsten Rose
committed
Special column names
--------------------
.. note::
Twig: respect that the 'special column name'-columns are rendered before Twig becomes active. The recommended
way by using Twig is *not to use* special column names at all. Use the Twig version *qfqLink*.

Carsten Rose
committed
QFQ typically don't care about the content of any SQL-Query - it just copy the content to the output (=Browser).
One exception are columns, whose name starts with '_'. E.g.::
10.sql = SELECT 'All', 'cats' AS red, 'are' AS _green, 'grey in the night' AS _link
* The first and second column are regular columns. No QFQ processing.
* The third column (alias name 'green') is no QFQ special column name, but has an '_' at the beginning: this column
content will be hidden.
* The fourth column (alias name 'link') uses a QFQ special column name. Here, only in this example, it has no
further meaning.
Summary:

Carsten Rose
committed
* Special column names always start with '_'.
* Columns starting with a '_' but not defined as as QFQ special column name are hidden(!) - in other words: they are
not **printed** as output.
* SQL hint: If there is no column alias defined, the column name becomes the value
of the first row. E.g. if the first selected row contains a '_' as the first
character, the column name becomes '_....' - which will be hidden! To be safe: always define an alias!