Commit 2eb0d601 authored by Carsten  Rose's avatar Carsten Rose
Browse files

UsersManual/index.rst: Updated examples.

FormAction.php: cleanup
parent 9a876908
......@@ -961,7 +961,7 @@ Types:
* Insert / Update / Delete records
* Save values of a form to different record(s), optionally on different table(s).
* Typically usefull on 'afterSave'.
* Typically usefull on 'afterSave' - be carefull when using it earlier, e.g. beforeLoad.
FormElement.’‘’parameter’‘’:
......@@ -969,11 +969,14 @@ Types:
`action`-FormElement will be processed.
* ‘’‘slaveId‘’‘:
* If `slaveId` does not exist or is empty (e.g. a defined query has an empty result):
* If there is a primary table column, with the same name as the current `action`-FormElement: take the value from that column as `slaveId`.
* If not: treat it as '0'.
* A value of `0` means the following `sqlInsert` will be fired.
* A value > `0` means the following `sqlUpdate` will be fired and the `slaveId` specifies which one.
* If there is no `slaveId` defined and if there is a column name with the same name as the current `action`-FormElement:
take the value from that column as `slaveId`.
* Access the `slaveId` by using the variable `{{slaveId:V}}` inside of `sqlUpdate` or `sqlInsert`.
* Access the `slaveId` by using the variable `{{slaveId:V}}` inside of `sqlUpdate`, `sqlInsert` or `sqlDelete`.
* ‘’‘sqlUpdate‘’‘ - query. E.g.: `sqlUpdate={{UPDATE Address SET street = '{{street:F:all}}' WHERE id={{slaveId:V}} LIMIT 1}}`
* ‘’‘sqlInsert‘’‘ - query. E.g.: `sqlInsert={{INSERT INTO Address (pId, street) VALUES ( {{id:R}}, '{{street:F:all}}' WHERE id={{slaveId:V}} }}`
......@@ -2111,11 +2114,11 @@ Formatting Examples
Formating (i.e. wrapping of data with HTML tags etc.) can be achieved in two different ways:
One can add formatting output directly into the SQL by either putting it in a separate column of the output or by using concat to concatenate data and formatting output in a single column.
One can add formatting output directly into the SQL by either putting it in a separate column of the output or by using concat to concatenate data and formatting output in a single column.
One can use ?level keys to define formatting information that will be put before/after/between all rows/columns of the actual levels result.
One can use ?level keys to define formatting information that will be put before/after/between all rows/columns of the actual levels result.
Two columns
Two columns
::
......@@ -2127,7 +2130,7 @@ Formating (i.e. wrapping of data with HTML tags etc.) can be achieved in two dif
Result:
Result:
::
......@@ -2141,7 +2144,7 @@ Formating (i.e. wrapping of data with HTML tags etc.) can be achieved in two dif
One column 'rend'
One column 'rend'
::
......@@ -2151,9 +2154,7 @@ Formating (i.e. wrapping of data with HTML tags etc.) can be achieved in two dif
..
Result:
Result:
::
......@@ -2165,9 +2166,7 @@ Formating (i.e. wrapping of data with HTML tags etc.) can be achieved in two dif
..
More HTML
More HTML
::
......@@ -2180,9 +2179,7 @@ Formating (i.e. wrapping of data with HTML tags etc.) can be achieved in two dif
..
Result:
Result:
::
......@@ -2207,7 +2204,7 @@ The same as above, but with braces::
::
Two queries
Two queries
::
......@@ -2219,9 +2216,7 @@ The same as above, but with braces::
..
Two queries: nested
Two queries: nested
::
......@@ -2252,7 +2247,7 @@ Two queries: nested with variables
..
* For every record of '10', all assigned records of 10.10 will be printed.
* For every record of '10', all assigned records of 10.10 will be printed.
Two queries: nested with hidden variables in a table
......@@ -2346,14 +2341,14 @@ unchanged.
* Primary form, `subrecord` formelement, field `parameter`: set
::
::
detail=id:formId,{{SELECT '&', IFNULL(fe.ord,0)+10 FROM Form AS f LEFT JOIN FormElement AS fe ON fe.formId=f.id WHERE f.id={{r:S0}} ORDER BY fe.ord DESC LIMIT 1}}:ord
detail=id:formId,{{SELECT '&', IFNULL(fe.ord,0)+10 FROM Form AS f LEFT JOIN FormElement AS fe ON fe.formId=f.id WHERE f.id={{r:S0}} ORDER BY fe.ord DESC LIMIT 1}}:ord
* Secondary form, `ord` formelement, field `value`: set
::
::
`{{RS0}}`.
......@@ -2364,15 +2359,17 @@ Compute the next 'ord' as default value direct inside the secondary form. No cha
* Secondary form, `ord` formelement, field `value`: set `{{SELECT IF({{ord:R0}}=0, MAX(IFNULL(fe.ord,0))+10,{{ord:R0}}) FROM (SELECT 1) AS a LEFT JOIN FormElement AS fe ON fe.formId={{formId:S0}} GROUP BY fe.formId}}`.
Form: Person Wizard
-------------------
Form: Person Wizard - firstname, city
-------------------------------------
Requirement: A form that displays the column 'firstname' from table 'Person' and 'city' from table 'Address'. If the
records not exist, the form should create it.
Form primary table: Person
Form salve table: Address
Relation: Person.id = Address.personId
Relation: `Person.id = Address.personId`
* Form: wizard
......@@ -2394,7 +2391,7 @@ Relation: Person.id = Address.personId
* Type: **text**
* Name: city
* Label: City
* Value: {{SELECT city FROM Address WHERE personId={{r}} ORDER BY id LIMIT 1}}
* Value: `{{SELECT city FROM Address WHERE personId={{r}} ORDER BY id LIMIT 1}}`
* FormElement: insert/update address record
......@@ -2402,9 +2399,57 @@ Relation: Person.id = Address.personId
* 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}}
* `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 not 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}} }}`
......@@ -230,11 +230,11 @@ class FormAction {
// Check if there is a column with the same name as the 'action'-FormElement.
if (false !== $this->store->getVar($fe[FE_NAME], STORE_RECORD)) {
// After an insert or update, update the (new) slave id to the master record.
// After an insert or update, propagate the (new) slave id to the master record.
$this->db->sql("UPDATE " . $this->primaryTableName . " SET " . $fe[FE_NAME] . " = $slaveId WHERE id = ? LIMIT 1", ROW_REGULAR, [$recordId]);
}
// If given fire a delete query
// If given: fire a delete query
$this->evaluate->parse($fe[FE_SQL_DELETE]);
return $slaveId;
......
......@@ -7,6 +7,7 @@ CREATE TABLE Person (
gender ENUM('', 'male', 'female') NOT NULL DEFAULT 'male',
groups SET('', 'a', 'b', 'c') NOT NULL DEFAULT '',
birthday DATE NOT NULL DEFAULT '0000-00-00',
noteId BIGINT NOT NULL DEFAULT 0,
modified TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
created DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00'
);
......@@ -107,7 +108,6 @@ CREATE TABLE Address (
grIdTyp BIGINT NOT NULL DEFAULT 0,
modified TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
created DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00'
);
INSERT INTO Address (personId, street, city, country) VALUES
......@@ -116,4 +116,18 @@ INSERT INTO Address (personId, street, city, country) VALUES
(1, 'Winter Street', 'Paris', 'France'),
(2, 'Summer Street', 'Berlin', 'Germany');
#------------------------------------------------------------------------
#
DROP TABLE IF EXISTS Note;
CREATE TABLE Note (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
note VARCHAR(128) NOT NULL DEFAULT '',
xId BIGINT NOT NULL DEFAULT 0,
grIdTyp BIGINT NOT NULL DEFAULT 0,
modified TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
created DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00'
);
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