Commit 7fd36792 authored by Carsten  Rose's avatar Carsten Rose
Browse files

FormAction.phhp, Store.php, AbstractBuildForm.php, Constants.php,...

FormAction.phhp, Store.php, AbstractBuildForm.php, Constants.php, QuickForemQuery.php, Index.rst: Added STORE_BEFORE, #3146
parent 04686840
......@@ -235,6 +235,8 @@ Only variables that are known in a specified store can be substituted.
+-----+----------------------------------------------------------------------------------------+----------------------------------------------------------------------------+
| R | :ref:`STORE_RECORD`: Record - the current record loaded in the form | All columns of the current record from the current table |
+-----+----------------------------------------------------------------------------------------+----------------------------------------------------------------------------+
| B | :ref:`STORE_BEFORE`: Record - the current record loaded in the form before any update | All columns of the current record from the current table |
+-----+----------------------------------------------------------------------------------------+----------------------------------------------------------------------------+
| P | Parent record. E.g.: on multi forms the current record of the outer query | All columns of the MultiSQL Statement from the table for the current row |
+-----+----------------------------------------------------------------------------------------+----------------------------------------------------------------------------+
| D | Default values column : The *table.column* specified *default value*. | |
......@@ -254,7 +256,7 @@ Only variables that are known in a specified store can be substituted.
| | be used in an SQL statement | |
+-----+----------------------------------------------------------------------------------------+----------------------------------------------------------------------------+
| Y | :ref:`STORE_SYSTEM`: a) Database, b) helper vars for logging/debugging: | |
| | SYSTEM_SQL_RAW ... SYSTEM_FORM_ELEMENT_COLUMN | |
| | SYSTEM_SQL_RAW ... SYSTEM_FORM_ELEMENT_COLUMN, c) Any custom fields: CONTACT, HELP, .. | |
+-----+----------------------------------------------------------------------------------------+----------------------------------------------------------------------------+
* Default *<prio>*: *FSRD* - Form / SIP / Record / Table definition.
......@@ -327,6 +329,20 @@ Store: *RECORD* - R
| <column name> | Name of a column of the primary table (as defined in the current form). To get, exactly and only, the specified form *FormElement*: *{{p_id:R}}* |
+------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
.. _STORE_BEFORE:
Store: *BEFORE* - B
^^^^^^^^^^^^^^^^^^^
* Current record loaded in Form withour any modification.
* If r=0, alle values are empty.
+------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
| Name | Explanation |
+========================+==================================================================================================================================================+
| <column name> | Name of a column of the primary table (as defined in the current form). To get, exactly and only, the specified form *FormElement*: *{{p_id:R}}* |
+------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
.. _STORE_CLIENT:
Store: *CLIENT* - C
......
......@@ -347,6 +347,7 @@ abstract class AbstractBuildForm {
if ($recordId > 0 && $this->store->getVar('id', STORE_RECORD) === false) {
$row = $this->db->sql("SELECT * FROM " . $this->formSpec[F_TABLE_NAME] . " WHERE id = ?", ROW_EXPECT_1, array($recordId), "Form '" . $this->formSpec[F_NAME] . "' failed to load record '$recordId' from table '" . $this->formSpec[F_TABLE_NAME] . "'.");
$this->store->setVarArray($row, STORE_RECORD);
$this->store->setVarArray($row, STORE_BEFORE);
}
$this->checkAutoFocus();
......
......@@ -220,6 +220,7 @@ const ERROR_SUBSTITUTE_FOUND = 2100;
const STORE_FORM = "F"; // form, still not saved in database
const STORE_SIP = "S"; // SIP
const STORE_RECORD = "R"; // selected record from primary table.
const STORE_BEFORE = "B"; // selected record from primary table before any modifcations.
const STORE_PARENT_RECORD = "P"; // on multi forms the recent record of the outer query (multi).
const STORE_TABLE_DEFAULT = "D"; // definition of primary table.
const STORE_TABLE_COLUMN_TYPES = "M"; // column types of primary table.
......
......@@ -250,6 +250,10 @@ class QuickFormQuery {
$this->store->createSipAfterFormLoad($formName);
}
if ($this->store->getVar('id', STORE_BEFORE) === false) {
$this->fillStoreWithRecord($this->formSpec[F_TABLE_NAME], $recordId, STORE_BEFORE);
}
if ($formMode === FORM_DELETE) {
$build = new Delete();
......@@ -298,13 +302,13 @@ class QuickFormQuery {
$formAction->elements($recordId, $this->feSpecAction, FE_TYPE_BEFORE_INSERT . ',' . FE_TYPE_BEFORE_UPDATE . ',' . FE_TYPE_BEFORE_SAVE);
// If an old record exist: load it. Necessary to delete uploaded files which should be overwritten.
$this->fillStoreRecord($this->formSpec[F_TABLE_NAME], $recordId);
$this->fillStoreWithRecord($this->formSpec[F_TABLE_NAME], $recordId, STORE_RECORD);
$save = new Save($this->formSpec, $this->feSpecAction, $this->feSpecNative);
$rc = $save->process();
// Reload fresh saved record and fill STORE_RECORD with it.
$this->fillStoreRecord($this->formSpec[F_TABLE_NAME], $rc);
$this->fillStoreWithRecord($this->formSpec[F_TABLE_NAME], $rc, STORE_RECORD);
$save->processAllUploads($rc);
......@@ -312,7 +316,7 @@ class QuickFormQuery {
$modified = $formAction->elements($rc, $this->feSpecAction, FE_TYPE_AFTER_INSERT . ',' . FE_TYPE_AFTER_UPDATE . ',' . FE_TYPE_AFTER_SAVE);
if ($modified) {
// Reload fresh saved record and fill STORE_RECORD with it.
$this->fillStoreRecord($this->formSpec[F_TABLE_NAME], $rc);
$this->fillStoreWithRecord($this->formSpec[F_TABLE_NAME], $rc, STORE_RECORD);
}
$htmlElementNameIdZero = false;
......@@ -654,18 +658,19 @@ class QuickFormQuery {
}
/**
* Load record $id from $table.
* Load record $id from $table and saves them in $store
*
* @param string $table
* @param string $recordId
* @param string $table tablename from where to load record wiht $recordId
* @param string $recordId record ID of current record
* @param string $store name of store where to save the record
* @throws CodeException
* @throws DbException
* @throws UserFormException
*/
private function fillStoreRecord($table, $recordId) {
private function fillStoreWithRecord($table, $recordId, $store = STORE_RECORD) {
if ($recordId !== false && $recordId > 0) {
$record = $this->db->sql("SELECT * FROM $table WHERE id = ?", ROW_EXPECT_1, [$recordId]);
$this->store->setVarArray($record, STORE_RECORD, true);
$this->store->setVarArray($record, $store, true);
}
}
......
......@@ -145,6 +145,7 @@ class FormAction {
if (!is_string($table) || $table === '') {
throw new UserFormException("");
}
if ($recordId !== false && $recordId > 0) {
$record = $this->db->sql("SELECT * FROM $table WHERE id = ?", ROW_EXPECT_1, [$recordId]);
$this->store->setVarArray($record, STORE_RECORD, true);
......
......@@ -145,6 +145,7 @@ class Store {
STORE_FORM => true,
STORE_SIP => false,
STORE_RECORD => false,
STORE_BEFORE => false,
STORE_PARENT_RECORD => false,
STORE_TABLE_DEFAULT => false,
STORE_TABLE_COLUMN_TYPES => false,
......@@ -187,7 +188,6 @@ class Store {
try {
//TODO: Vernuenftige Fehlermeldung falls nicht auf qfq.ini zugegriffen werden kann.
//TODO: sinnvollen Platz fuer qfq.ini bestimmen. In der Installationsdoku erwaehnen.
// $config = parse_ini_file(__DIR__ . '/../../../' . CONFIG_INI, false);
$config = parse_ini_file($configIni, false);
......
Markdown is supported
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