CODING.md 12.2 KB
Newer Older
Carsten  Rose's avatar
Carsten Rose committed
1
2
Design / Notes / Best Practices for Coding
==========================================
Carsten  Rose's avatar
Carsten Rose committed
3
4
5
6

General
=======

Carsten  Rose's avatar
Carsten Rose committed
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
* Class QuickFormQuery is the main entry point called by:
  * T3 Extension 'QFQ': called once per tt_content-record. 'bodytext' will be transferred to class QuickFormQuery.
    * The 'bodytext' contains:
      * Report definiton: 10.sql=SELECT ...
      * Form definition (explizit): form=Person
      * <Empty>: do nothing
  * api/save.php: wrapper to receive AJAX post request and instantiate QuickFormQuery.
  * api/load.php: not implemented yet. 
    * Wrapper to receive AJAX get requests.
    * delivers data for jqw grid
    * delivers data for typeahed fields
    * delivers data for select list
    * delivers data for depended (user select/unselect former elements) form elements

LOAD
----
* When qfq starts, 
  * (Form) Looking for a formname at: 
    1. Typo3 Bodytext Element,
Carsten  Rose's avatar
#2067    
Carsten Rose committed
26
    2. For the 'SIP' ($_GET['s'] => $S_SESSION['qfq'][$_GET['s']]="form=person&r=123")
Carsten  Rose's avatar
Carsten Rose committed
27
28
29
30
31
32
33
34
35
36
37
38
    3. $_GET variables 'form' and 'r' (=recordId) - the parameter 'form' has to be allowed in 'Permit URL Parameter' of 
       the specified form. This means: load the form to check, if it is allowed to load the form!?
    * If a formname is found, the search stops and the specified form will be processed.
  * (Report)
    * Process all <number>.[<number.>].sql statements

* Access code variables:     
  * active/valid formname: [$this->store->setVar(SYSTEM_FORM, $formName, STORE_SYSTEM);]
  * SIP: [$this->store->getVar('form', STORE_SIP)]
  * All parameters from active SIP:  [$this->store->getStore(STORE_SIP)]
  * Check Contstants.php for known Store members
  
Carsten  Rose's avatar
#2067    
Carsten Rose committed
39
40
* In QuickFormQuery.php the whole Form will be copied to `$this->formSpec` and depending on further processing, the 
  elements are available in `$this->feNative` and `$this->feAction`.
Carsten  Rose's avatar
Carsten Rose committed
41
  * The Form specificaton (table form) will be evaluated direct after loading.
Carsten  Rose's avatar
Carsten Rose committed
42
43
  * The FormElement specification will be evaluated later on in BuildForm*.php

Carsten  Rose's avatar
#2067    
Carsten Rose committed
44
45
* If a form is called without a SIP (form.permitNew='always'), than a SIP is created on the fly (as a 
  parameter in the form).
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
* Uniq SIP for mutliple tabs with r=0  
  * Depending on `r=0` or `r>0` a form submit will do an MySQL `insert` or `update` later during save.
  * For new records (r=0), clicking on 'save' without closing the form is a tricky situation. Additionally the user might have open multiple
      tabs (same form, all r=0) and after saving the record (wihtout closing the form) the user expects that it's ok to edit 
      the record again and again. Unfortunately, the initial created SIP (before 'form load') is not uniqe anymore (multiple 
      tabs might  contain a saved 'new record'). To guarantee correct saving of r=0 records, a unique on the fly generated SIP 
      is creatd during form load - individually per browser tab.  

 * Formular zusammenbausen
    * QuickFormQuery: doForm > loadFormSpecification  - laedt alle Elemente die nicht genested sind: native, pill, fieldset, templateGroup >> $his->formNative
    * Damit wird '(BuildFormBootstrap / AbstractBuildForm) > process()' aufgerufen.
      * Hier wird AbstractBuildForm->elements() aufgerufen (ein Aufruf fuer alle root elemente).
      * Pro native Element (inkl. pill, fieldset, templateGroup) wird $builElementFunctionName aufgerufen. 
        - buildText()
        - ....
        - buildFieldSet()       << von hier werden alle zum aktuellen 'FieldSet' gehoerenden SubElemente abgearbeitet - via AbstractBuildForm->elements()  (damit schliesst sich der Kreis und wird rekursiv)
        - buildPill()           << von hier werden alle zum aktuellen 'Pill' gehoerenden SubElemente abgearbeitet - via AbstractBuildForm->elements()  (damit schliesst sich der Kreis und wird rekursiv)
        - buildTemplateGroup()  << von hier werden alle zum aktuellen 'Pill' gehoerenden SubElemente abgearbeitet - via AbstractBuildForm->elements()  (damit schliesst sich der Kreis und wird rekursiv)
        >>  
Carsten  Rose's avatar
Carsten Rose committed
65
66
67
68
SAVE
----
* Via wrapper api/save.php
* SID must be supplied via FORM POST
Carsten  Rose's avatar
Carsten Rose committed
69
* The SID supplies the <formname> and the <recordid>
Carsten  Rose's avatar
Carsten Rose committed
70
71
72
73
* form.render: plain/table/bootstrap
  * Client will handle the response of save.php.
  * Optional redirection initiated by client.
  
Carsten  Rose's avatar
#2067    
Carsten Rose committed
74
75
76
77
78
79
80
81
82
83
84
85
New records
...........
* r=0 (missing 'r' means r=0)
* After saving the SIP content will be updated with the new record. 
  Remember that the SIP in the URL is *not* the SIP used in the form to identify the form/record. The form use a 
  individual 'new record' SIP.

Existing records
................
* r>0 ('r' have to exist)

  
86
87
88
89
90
91
92
93
94
DELETE
------
* Via wrapper api/delete.php
* The element who should dissappear after successfull deleting: class=record
* Button:

  * class=record-delete
  * Button: data-sip={{SIP}}

95
96
97
98
99
100
101
102
   * SIP values:

     * SIP_RECORD_ID: Mandatory.
     * SIP_TABLE: Either SIP_TABLE or SIP_FORM has to be given.
     * SIP_FORM: Either SIP_TABLE or SIP_FORM has to be given. Not implemented now.
     * SIP_TARGET_URL: Only with SIP_MODE_ANSWER=MODE_HTML - Url to redirect browser to. 
     * SIP_MODE_ANSWER: MODE_JSON / MODE_HTML. If not given, this means MODE_JSON. 

103
104
* Three possible variants with delete links:
  
105
   * (1) Form: main record
106
107
108
109
   * HTML Code:
   
     <button id="delete-button" type="button" class="btn btn-default navbar-btn" ><span class="glyphicon glyphicon-trash"></span></button>
   
110
   * (2) Form: subrecord, one delete button per record 
111
112
113
   * HTML Code:
   
     <button type="button" class="record-delete" data-sip={{SIP}} ><span class="glyphicon glyphicon-trash"></span></button>
114
115
116
117
118
119
     
   * (3) Report: typially inside a table, but maybe different.

     <button type="button" class="record-delete" data-sip={{SIP}} ><span class="glyphicon glyphicon-trash"></span></button>


120
121
122
123
Upload
-----------------

* The upload UI consist of three elements
124
  * 1) A <div> tag with a) an optional filename of an earlier uploaded file and b) a trash button.
125
  * 2) The 'browse' button (<input type='file' name='<feName>'>). This element will not be send by post.
126
  * 3) A HTML hidden element with name=<feName> containing the <sipUpload>.
127
128
129
130
* A new uniq SIP (sipUpload) will be created for every upload formElement. These 'sipUpload' will be assigned to the upload 
  browse button and to the upload delete button.  
  * The individual sipUpload is necessary to correctly handle multiple simultaenously forms when using r=0. Also, through 
    this uniq id it's easy to distinguish between asynchron uploaded files.
131
132
  * The SIP on ther server contains the individual '_FILES' information submitted during the upload.
* Via the hidden element <feName> 'save()', access to the form individual upload status informations is given. 
133
134
135

Upload to server, before 'save'
...............................
136
137
* If a user open's a file for upload via the browse button, that file is immediately transmitted to the server. The user 
  will see a turning wheel until the upload finished.
138
* After successfull upload the 'Browse' button disappears and the filename, plus the delete button, will be displayed (client logic). 
139
* The uploaded file will be checked: maxsize, mime type, check script.
140
141
* The uploaded file is still temporary. It has been renamed from '[STORE_EXTRA][<uploadSip>][FILES_TMP_NAME]' to  
  '[STORE_EXTRA][<uploadSip>][FILES_TMP_NAME].cached'.
142
143
144
145
146
* The upload action will be saved in the user session:
    [STORE_EXTRA][<uploadSip>][FILES_TMP_NAME]
    [STORE_EXTRA][<uploadSip>][FILES_NAME]
    [STORE_EXTRA][<uploadSip>][FILES_ERROR]
    [STORE_EXTRA][<uploadSip>][FILE_SIZE]
147
* Clicks the user on delete button:
148
149
  * In the usersession a flagDelete will be set: 
     [STORE_EXTRA][<uploadSip>][FILES_FLAG_DELETE]='1'
150
  * An optional previous upload file (still not saved on the final place) will be deleted.
151
152
  * An optional existing variable [STORE_EXTRA][<uploadSip>][FILES_TMP_NAME] will be deleted. The 'flagDelete' must not 
    be change - it's later needed to detect to delete earlier uploaded files.
153
154
155

Form save
.........
156
* Step 1: insert / update the record. 
Carsten  Rose's avatar
Carsten Rose committed
157
* Step 2: process all 'uploads'.
158
159
160
161
162
163
    * Get every uniq uploadSip (=[STORE_CLIENT][<feName>]) of every upload formElement. Get the corresponding temporary uploaded filename.
    * If [STORE_EXTRA][<uploadSip>][FILES_FLAG_DELETE]='1' is set, delete previous uploaded file.
    * If [STORE_EXTRA][<uploadSip>][FILES_TMP_NAME]!='': indicates that there is an upload.
    * Calculate <fileDestination>
    * mv <file>.cached <fileDestination>
    * clientvalue[<feName>] = <fileDestination>
164
    * delete [STORE_EXTRA][<uploadSip>]
165
* Step 3: update record with final <fileDestination>    
166

167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
Formelement type: DATE / DATETIME / TIME
----------------------------------------
 * Available Formats:
   * 'yyyy-mm-dd' = FORMAT_DATE_INTERNATIONAL. 
   * 'dd.mm.yyyy' = FORMAT_DATE_GERMAN.
 * The 'DATE_FORMAT' can be specified systemwide in `config.ini`
 * The default format is FORMAT_DATE_INTERNATIONAL.
 * Optional: 'dateFormat' can be specified per form element in `form.parameter` - this overwrites 'systemwide'.
 * If there is no placeholder defined on the form element, the defined dateFormat is shown as placeholder.
 
 * Browser: 
   * checks the input with a system regexp.
   * regexp might be user defined. If given, do not use system regexp!
   * No min/max check.
 * Server: 
   * check with system wirde regexp 
   * regexp might be user defined. If given, do not use system regexp!
   * Do min/max check.
 
 * MySQL data: 1000-01-01 - 9999-12-31 and 0000-00-00
 * MySQL time: 00:00:00 - 23:59:59
 
 * datetime format: 'DATE TIME'

Carsten  Rose's avatar
Carsten Rose committed
191
192
Debug / Log
===========
Carsten  Rose's avatar
Carsten Rose committed
193
194
195

* Before firing a SQL or doing processing of an FormElement, set some debugging / error variables:

196
    [src] $this->store->setVar(SYSTEM_SQL_RAW, STORE_SYSTEM)
Carsten  Rose's avatar
Carsten Rose committed
197
198

* Available fields:
199
200
201
202
203
204
205
206
207
208

    <code>
    SYSTEM_SQL_RAW
    SYSTEM_SQL_FINAL
    SYSTEM_SQL_COUNT
    SYSTEM_SQL_PARAM_ARRAY
    SYSTEM_FORM = CLIENT_FORM;                        // '<formName> / <formId>'
    SYSTEM_FORM_ELEMENT = 'formElement';              // '<formElementName> / <formElementeId>'
    SYSTEM_FORM_ELEMENT_COLUMN = 'formElementColumn'; // '<columnname of current processed formElement>'
    </code>
Carsten  Rose's avatar
Carsten Rose committed
209

Carsten  Rose's avatar
Carsten Rose committed
210
211
* Form.debugShowInfo: yes|no will display a tooltip near beside every formelement and show parse/evaluate as tooltip.

212
213
214
215
* Check to display debug info:
 
    $this->store->getVar(SYSTEM_SHOW_DEBUG_INFO, STORE_SYSTEM) === 'yes'

Carsten  Rose's avatar
Carsten Rose committed
216
217
218
219
220
221
222
223
224
225
226
227
228
229
Errormessages & Eceptions
=========================

* Exception types:
  * Code 
  * Db
  * User Form
  * user Report 
  * plus an Errorhandler which throws exceptions
  
* Exceptions inside of an API call delivers the error code and msg as JSON to the client.
* Typo3 suppress E_NOTICE (e.g. undefined index). To catch E_NOTICE in QFQ, it will be temporaly enabled in QfqCongroller.php.
  

Carsten  Rose's avatar
Carsten Rose committed
230
231
232
Stores
======

233
* Retrieve 'get' or 'post' variables by:
Carsten  Rose's avatar
Carsten Rose committed
234
235
236
237
238
239
240
241
242
243
244
245
246
247

[src] $values = $this->store->getStore(STORE_CLIENT)



Primary Table
=============
* For the primary table all informations are available in STORE_TABLE_DEFAULT and STORE_TABLE_COLUMN_TYPES.
* Get all columns of the primary table by

[src] array_keys($this->getStore(STORE_TABLE_COLUMN_TYPES))

* Get the recent record in STORE_RECORD and the parent record (multiforms) in STORE_PARENT_RECORD.

Carsten  Rose's avatar
Carsten Rose committed
248
249
250

Typo3
=====
Carsten  Rose's avatar
Carsten Rose committed
251
252
253
* PageId: $this->store->getVar(TYPO3_PAGE_ID, STORE_TYPO3)
  * Based on: $GLOBALS["TSFE"]->id   current Page
 
Carsten  Rose's avatar
Carsten Rose committed
254
255
256
257
258
259
260
261
* $GLOBALS["TSFE"]->fe_user->user["uid"]   fe_user_uid

* https://wiki.typo3.org/Extbase_HowTos
  * Old: $this->cObj->data['bodytext']
  * New:
        $contentObject = $this->configurationManager->getContentObject();
        $configuration = $contentObject->data['bodytext'];

262
263
264
* Verzeichnisstruktur Extension: https://docs.typo3.org/typo3cms/CoreApiReference/ExtensionArchitecture/FilesAndLocations/Index.html
* http://api.typo3.org/
  * http://api.typo3.org/typo3cms/62/html/index.html
Carsten  Rose's avatar
Carsten Rose committed
265
266
267
268
269
270
* https://docs.typo3.org/typo3cms/CoreApiReference/Introduction/Index.html

SIP
===
Page loaded: www.example.com?index.php&id=start&s=badcaffee1234&type=2&L=3, with $_SESSION['badcaffee1234'] => 'form=Person&r=1'

271
272
* $_SESSION['qfq'][$sip] => <urlparam>  >> $_SESSION['qfq']['badcaffee1234'] => 'form=Person&r=1'
* $_SESSION['qfq'][$urlparam] => <sip>  >> $_SESSION['qfq']['form=Person&r=1'] => 'badcaffee1234'
Carsten  Rose's avatar
Carsten Rose committed
273
274


275
276
277
278
279
280
281
282
283
284
FormElement
===========

Checkbox
--------

    <div class="checkbox">
        <label>
            <input type="checkbox">label 1
        </label>
Carsten  Rose's avatar
Carsten Rose committed
285
286
    </div>
    
287