Commit 48f5a302 authored by Carsten  Rose's avatar Carsten Rose
Browse files

Feature #3881 / Variables: Ex 'keySemId', New 'periodId' (System Store)

Manual.rst: Doc update for periodId.
DatabaseUpdateData.php, formEditor.sql: Table 'Period' and sample record.
Store.php: Implement systemStoreUpdate()
QuickFormQuery.php: call to store->systemStoreUpdate() - might solved in a better way..
parent 7db36c32
......@@ -342,6 +342,9 @@ config.qfq.ini
| DOCUMENTATION_QFQ | DOCUMENTATION_QFQ=http://docs.typo3.org... | Link to the online documentation of QFQ. Every QFQ installation also |
| | | contains a local copy: typo3conf/ext/qfq/Documentation/html/Manual.html |
+-----------------------------+-------------------------------------------------+----------------------------------------------------------------------------+
| VAR_ADD_BY_SQL | VAR_ADD_BY_SQL = {{!SELECT s.id AS ... | Specific values read from the database to fill the system store during QFQ |
| | | load. See `VariablesAddBySql`_ for a usecase. |
+-----------------------------+-------------------------------------------------+----------------------------------------------------------------------------+
Example: *typo3conf/config.qfq.ini*
......@@ -417,10 +420,15 @@ Example: *typo3conf/config.qfq.ini*
;RECORD_LOCK_TIMEOUT_SECONDS = 900
; Local Documentation (doc fits to installed version): typo3conf/ext/qfq/Documentation/html/Manual.html
; Local Documentation (doc fits to installed version): typo3conf/ext/qfq/Documentation/html/Manual.html
;DOCUMENTATION_QFQ = https://docs.typo3.org/typo3cms/drafts/github/T3DocumentationStarter/Public-Info-053/Manual.html
..
;VAR_ADD_BY_SQL = {{!SELECT s.id AS _periodId FROM Period AS s WHERE s.start<=NOW() ORDER BY s.start DESC LIMIT 1}}
.. _`CustomVariables`:
Custom variables
^^^^^^^^^^^^^^^^
It's also possible to setup custom variables in `config.qfq.ini`.
......@@ -436,7 +444,55 @@ E.g. to setup a contact address and reuse the information inside your installati
{{ADMINISTRATIVE_CONTACT:Y}}, {{ADMINISTRATIVE_ADDRESS:Y}}, {{ADMINISTRATIVE_NAME}}
..
.. _`VariablesAddBySql`:
Variables add by SQL
^^^^^^^^^^^^^^^^^^^^
A specified SELECT statement in `config.qfq.ini`_ in variable `VAR_ADD_BY_SQL` fill be fired after filling the SYSTEM STORE.
The query should have 0 (nothing happens) or 1 row. The column names and column values will be added as variables to the SYSTEM_STORE.
Existing variables will be overwritten. Be carefull not to overwrite needed values.
This option is usefull to make generic custom values, saved in the database, accessible to all QFQ Report and Forms.
Access such variables as usual via `{{<varname>:Y}}`.
.. _`periodId :
periodId
''''''''
This is
* a usecase, implemented via `VariablesAddBySql`_,
* a way to access `Period.id` with respect to the current period (the period itself is defined by you).
After a full QFQ installation, three things are prepared:
* a table `Period` (extend / change it to your needs, fill them with your periods),
* one sample record in table `Period`,
* in config.qfq.ini the default definition of `VAR_ADD_BY_SQL` will set the variable `periodId` during QFQ load.
Websites, delivering semester data, schoolyears schedules, or any other type or periods, often need an index to the
*current* period. One way is a) to mark the current period and b) to change the marker every time when the next period
becomes current.
The QFQ approach works without a marker and without manual intervention: the whished index will be computed during QFQ load.
In `config.qfq.ini`: ::
VAR_ADD_BY_SQL = SELECT id AS periodId FROM Period WHERE start<=NOW() ORDER BY start DESC LIMIT 1
a variable 'periodId' will automatically computed and filled in STORE SYSTEM. Access it via `{{periodId:Y0}}`.
To get the name and current period: ::
SELECT name, ' / ', start FROM Period WHERE id={{periodId:Y0}}
Typically, it's necessary to offer a 'previous' / 'next' link. In this example, the STORE SIP holds the new periodId: ::
SELECT CONCAT('id={{pageId:T}}&periodId=', {{periodId:SY0}}-1, '|Next') AS _Page, ' ', name, ' ', CONCAT('id={{pageId:T}}&periodId=', {{periodId:SY0}}+1, '|Next') AS _Page FROM Period AS s WHERE s.id={{periodId:SY0}}
Take care for minimum and maximum indexes (do not render the links if out of range).
.. _`DbUserPrivileges`:
DB USER privileges
^^^^^^^^^^^^^^^^^^
......
......@@ -24,5 +24,5 @@ Online Recruiting Tool
The ORT will show a typical QFQ application with some best practices tips.
Play the SQL file 'onlineRecruitingTool.sql' on a fresh installation. Otherwise some `Form` and `FormElement` ids might be
Play the SQL file 'onlineRecruitingTool.sql' on a fresh installation. Otherwise some `Form` and `FormElement` id's might be
used and playing the file will fail.
......@@ -95,3 +95,4 @@ WKHTMLTOPDF = /opt/wkhtmltox/bin/wkhtmltopdf
; Local Documentation (doc fits to installed version): typo3conf/ext/qfq/Documentation/html/Manual.html
;DOCUMENTATION_QFQ = https://docs.typo3.org/typo3cms/drafts/github/T3DocumentationStarter/Public-Info-053/Manual.html
; VAR_ADD_BY_SQL = SELECT id AS _periodId FROM Period WHERE start<=NOW() ORDER BY start DESC LIMIT 1
\ No newline at end of file
......@@ -434,6 +434,9 @@ const SYSTEM_DB_UPDATE_AUTO = 'auto';
const SYSTEM_RECORD_LOCK_TIMEOUT_SECONDS = 'RECORD_LOCK_TIMEOUT_SECONDS';
const SYSTEM_RECORD_LOCK_TIMEOUT_SECONDS_DEFAULT = 900; // 15 mins
const SYSTEM_VAR_ADD_BY_SQL = 'VAR_ADD_BY_SQL';
const SYSTEM_VAR_ADD_BY_SQL_DEFAULT = 'SELECT id AS periodId FROM Period WHERE start<=NOW() ORDER BY start DESC LIMIT 1';
const DOCUMENTATION_QFQ = 'DOCUMENTATION_QFQ';
const DOCUMENTATION_QFQ_URL = 'https://docs.typo3.org/typo3cms/drafts/github/T3DocumentationStarter/Public-Info-053/Manual.html';
......
......@@ -150,6 +150,7 @@ class QuickFormQuery {
$this->store = Store::getInstance($bodytext, $phpUnit);
$this->store->setVar(TYPO3_TT_CONTENT_UID, $t3data[T3DATA_UID], STORE_TYPO3);
$this->db = new Database();
$this->store->systemStoreUpdate();
$this->eval = new Evaluate($this->store, $this->db);
......
......@@ -91,7 +91,6 @@ class Database {
}
// DB Init
if ($dbInit !== false && $dbInit != '') {
$this->sql($dbInit);
}
......
......@@ -55,7 +55,9 @@ $UPDATE_ARRAY = array(
'0.19.0' => [
"ALTER TABLE `Form` ADD `dirtyMode` ENUM( 'exclusive', 'advisory', 'none' ) NOT NULL DEFAULT 'exclusive' AFTER `requiredParameter`",
"ALTER TABLE `Form` ADD `recordLockTimeoutSeconds` INT NOT NULL DEFAULT '900' AFTER `parameter`"
"ALTER TABLE `Form` ADD `recordLockTimeoutSeconds` INT NOT NULL DEFAULT '900' AFTER `parameter`",
"CREATE TABLE IF NOT EXISTS `Period` (`id` INT(11) NOT NULL AUTO_INCREMENT, `start` DATETIME NOT NULL, `name` VARCHAR(255) NOT NULL, `modified` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `created` DATETIME NOT NULL, PRIMARY KEY (`id`), KEY `start` (`start`)) ENGINE = InnoDB DEFAULT CHARSET = utf8 AUTO_INCREMENT = 0;",
"INSERT INTO Period (start, name, created) VALUES (NOW(), 'dummy', NOW());"
],
);
......
......@@ -176,6 +176,8 @@ class Config {
Support::setIfNotSet($config, DOCUMENTATION_QFQ, DOCUMENTATION_QFQ_URL);
Support::setIfNotSet($config, SYSTEM_VAR_ADD_BY_SQL, SYSTEM_VAR_ADD_BY_SQL_DEFAULT);
return $config;
}
......@@ -240,5 +242,4 @@ class Config {
return $config;
}
}
\ No newline at end of file
......@@ -175,6 +175,7 @@ class Store {
self::fillStoreClient();
self::fillStoreSip();
self::fillStoreExtra();
}
/**
......@@ -772,6 +773,24 @@ class Store {
self::setVar(SYSTEM_SHOW_DEBUG_INFO, $value, STORE_SYSTEM);
}
/**
* Read SYSTEM_VARIABLES_GET_FROM_DB from SYSTEM_STORE and if set:
* a) fire the SQL
* b) merge all columns to SYSTEM_STORE
*/
public static function systemStoreUpdate() {
$storeSystem = self::getStore(STORE_SYSTEM);
if(!empty($storeSystem[SYSTEM_VAR_ADD_BY_SQL])) {
$db = new qfq\Database();
$arr = $db->sql($storeSystem[SYSTEM_VAR_ADD_BY_SQL], ROW_EXPECT_0_1);
if(!empty($arr)) {
$storeSystem = array_merge($storeSystem, $arr);
self::setStore($storeSystem, STORE_SYSTEM, true);
}
}
}
}
......
......@@ -154,6 +154,19 @@ CREATE TABLE IF NOT EXISTS `Dirty` (
AUTO_INCREMENT = 0;
CREATE TABLE IF NOT EXISTS `Period` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`start` DATETIME NOT NULL,
`name` VARCHAR(255) NOT NULL,
`modified` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`created` DATETIME NOT NULL,
PRIMARY KEY (`id`),
KEY `start` (`start`)
)
ENGINE = InnoDB
DEFAULT CHARSET = utf8
AUTO_INCREMENT = 0;
# Delete previous FormElements (if exist)
DELETE FormElement FROM FormElement, Form
WHERE
......@@ -390,4 +403,5 @@ VALUES
'recordDestinationTable=FormElement\ntranslateIdColumn=feIdContainer');
# Default record for table Period
INSERT INTO Period (start, name, created) VALUES (NOW(), 'dummy', NOW());
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