Commit 0b613ec0 authored by Carsten  Rose's avatar Carsten Rose
Browse files

Form: added phpdoc, do evaluation during construct, add/rename render modes, evaluates formElements

parent a274090a
......@@ -40,8 +40,19 @@ require_once(__DIR__ . '/../qfq/FormBuildPlain.php');
class Form {
/**
* @var Store instantiated class
*/
protected $store = null;
/**
* @var Database instantiated class
*/
protected $db = null;
/**
* @var Evaluate instantiated class
*/
protected $eval = null;
protected $formSpec = array(); // Form Definition: copy of the loaded form
protected $feSpecAction = array(); // FormEelement Definition: all formElement.class='action' of the loaded form
protected $feSpecNative = array(); // FormEelement Definition: all formElement.class='native' of the loaded form
......@@ -69,6 +80,7 @@ class Form {
$this->store = \qfq\store\Store::getInstance($bodytext);
$this->db = new Database();
$this->eval = new Evaluate($this->store, $this->db);
}
/**
......@@ -96,15 +108,17 @@ class Form {
$this->store->createSipAfterFormLoad($formName);
}
$this->store->fillStoreTableDefinition($this->formSpec['tableName']);
$this->store->fillStoreTableDefaultColumnType($this->formSpec['tableName']);
// TODO: replace switch() by Marschaller
// render: FormPlain | FormBootstrap
switch ($this->formSpec['render']) {
case 'Plain':
case 'plain':
$build = new FormBuildPlain($this->formSpec, $this->feSpecAction, $this->feSpecNative);
break;
case 'Bootstrap':
case 'table':
//TODO: implement bootstrap rendering: FormBuildBootstrap
// $build = new FormBuildBootstrap($this->formDef, $this->feDefAction, $this->feDefNative);
break;
case 'bootstrap':
//TODO: implement bootstrap rendering: FormBuildBootstrap
// $build = new FormBuildBootstrap($this->formDef, $this->feDefAction, $this->feDefNative);
break;
......@@ -115,9 +129,7 @@ class Form {
switch ($mode) {
case FORM_LOAD:
// $this->formActionBefore();
$html .= $build->head();
$html .= $build->elements();
$html .= $build->tail();
$html .= $build->process();
// $this->formActionAfter();
break;
case FORM_SAVE:
......@@ -141,6 +153,13 @@ class Form {
}
/**
* Loads specification of recent form.
* Evaluates Form and all FormElements.
*
* Loaded Form is in $this->formSpec
* Loaded 'action' FormElements are in $this->feSpecAction
* Loaded 'native' FormElements are in $this->feSpecNative
*
* @return string formName
* @throws DbException
* @throws UserException
......@@ -148,11 +167,18 @@ class Form {
private function loadFormSpecification() {
$formName = $this->getFormName();
$this->formSpec = $this->db->sql("SELECT * FROM Form AS f WHERE f.name LIKE ? AND f.deleted='no'", ROW_EXACT_1, [$formName]);
$this->store->setVar(SYSTEM_FORM, $formName, STORE_SYSTEM);
$sql = "SELECT * FROM FormElement AS fe WHERE fe.formId = ? AND fe.deleted='no' AND fe.class = ? AND fe.enabled='yes' ORDER BY fe.order, fe.id";
$this->feSpecAction = $this->db->sql($sql, ROW_REGULAR, [$this->formSpec["id"], 'action']);
$this->formSpec = $this->eval->parseArray($this->db->sql("SELECT * FROM Form AS f WHERE f.name LIKE ? AND f.deleted='no'", ROW_EXACT_1, [$formName]));
$this->store->setVar(SYSTEM_FORM_ELEMENT, '', STORE_SYSTEM);
$sql = "SELECT * FROM FormElement AS fe WHERE fe.formId = ? AND fe.deleted='no' AND fe.class = ? AND fe.enabled='yes' ORDER BY fe.ord, fe.id";
$this->feSpecAction = $this->eval->parseArray($this->db->sql($sql, ROW_REGULAR, [$this->formSpec["id"], 'action']));
$this->explodeFormElementParameter($this->feSpecAction);
// Native FormElements will be evaluated later
$this->feSpecNative = $this->db->sql($sql, ROW_REGULAR, [$this->formSpec["id"], 'native']);
$this->explodeFormElementParameter($this->feSpecNative);
return $formName;
}
......@@ -165,7 +191,7 @@ class Form {
private function getFormName() {
$formName = $this->store->getVar(TYPO3_FORM, STORE_TYPO3 . STORE_SIP . STORE_CLIENT);
$formName = $this->store->getVar(SIP_FORM, STORE_TYPO3 . STORE_SIP . STORE_CLIENT);
if ($formName !== false)
return $formName;
......@@ -173,6 +199,34 @@ class Form {
throw new UserException("Missing form name. Not found in T3_BODYTEXT / SIP / GET", ERROR_MISSING_FORM_NAME);
}
/**
* Iterates over all FormElements in $elements.
* If $element['parameter'] exist and is filled: explode the content and apend them to the current FormElement Array.
*
* @param array $elements
* @throws UserException
*/
private function explodeFormElementParameter(array &$elements) {
// Iterate all FormElements
foreach ($elements AS $key => $element) {
// Something to explode?
if (isset($element['parameter']) && $element['parameter'] !== '') {
// Explode
$arr = helper\KeyValueStringParser::parse($element['parameter'], "=", "\n");
// Check if some of the exploded keys conflict with existing keys
$checkKeys = array_keys($arr);
foreach ($checkKeys AS $checkKey) {
if (isset($element[$checkKey])) {
$this->store->setVar(SYSTEM_FORM_ELEMENT, $element['name'] . ' / ' . $element['id'], STORE_SYSTEM);
$this->store->setVar(SYSTEM_FORM_ELEMENT_COLUMN, 'parameter', STORE_SYSTEM);
throw new UserException("Found reserved keyname '$checkKey'");
}
}
$elements[$key] = array_merge($element, $arr);
}
}
}
/**
* @return bool - 'true' if SIP exists, else 'false'
* @throws CodeException
......
This diff is collapsed.
......@@ -6,6 +6,7 @@ CREATE TABLE IF NOT EXISTS `Form` (
`noteInternal` TEXT NOT NULL,
`tableName` VARCHAR(255) NOT NULL DEFAULT '',
`permitNew` ENUM('sip', 'logged_in', 'logged_out', 'always', 'never') NOT NULL DEFAULT 'sip',
`permitEdit` ENUM('sip', 'logged_in', 'logged_out', 'always', 'never') NOT NULL DEFAULT 'sip',
`permitUrlParameter` VARCHAR(255) NOT NULL DEFAULT '',
......@@ -67,9 +68,9 @@ CREATE TABLE IF NOT EXISTS `FormElement` (
`label` VARCHAR(255) NOT NULL DEFAULT '',
`mode` ENUM('show', 'readonly', 'required', 'lock', 'disabled') NOT NULL DEFAULT 'show',
`class` ENUM('native', 'action', 'group') NOT NULL DEFAULT 'native',
`class` ENUM('native', 'action', 'fieldset', 'pill') NOT NULL DEFAULT 'native',
`type` ENUM('checkbox', 'dateJQW', 'datetimeJQW', 'email', 'gridJQW', 'hidden', 'input',
'note', 'password', 'radio', 'select', 'subrecord', 'upload', 'url',
'note', 'password', 'radio', 'select', 'subrecord', 'upload',
'before_load', 'before_save', 'before_insert', 'before_update', 'before_delete', 'after_load',
'after_save', 'after_insert', 'after_update', 'after_delete', 'group',
'sendmail') NOT NULL DEFAULT 'input',
......@@ -122,6 +123,12 @@ INSERT INTO FormElement (formId, name, label, mode, type, ord, size, maxLength,
VALUES
(1, 'id', 'id', 'readonly', 'input', 10, 30, 10, '', '', '', '', '', ''),
(1, 'name', 'Name', 'show', 'input', 20, 20, 10, '', '', '', '', '', 'autofocus=on'),
(1, 'label', 'Label', 'show', 'input', 20, 10, 10, '', '', '', '', '', '');
(1, 'title', 'Title', 'show', 'input', 30, 10, 10, '', '', '', '', '', ''),
(1, 'noteInternal', 'Note', 'show', 'input', 40, '10,3', 0, '', '', '', '', '', ''),
# (1, 'permitNew', 'Permit New', 'show', 'radio', 50, 0, 0, '', '', '', '', '', ''),
# (1, 'permitEdit', 'Permit Edit', 'show', 'radio', 50, 0, 0, '', '', '', '', '', 'itemList=hello,world'),
(1, 'render', 'Render', 'show', 'radio', 60, 0, 0, '', '', '', '{{!select name AS label, id AS id from FormElement}}',
'', ''),
(1, 'deleted', 'Deleted', 'show', 'checkbox', 200, 0, 0, '', '', '', '', '', '');
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