Commit cd0a4818 authored by Carsten  Rose's avatar Carsten Rose
Browse files

Replaced string 'mode' and 'type' for formelements against constants FE_MODE and FE_TYPE

Support.php, FillStore.php, AbstractBuildFrom.php, BuildFormPlain.php, BuildFormTables.php, Constants.php, Save.php, BuildFormPlainTest.php
parent 4c49115a
......@@ -336,8 +336,8 @@ abstract class AbstractBuildForm {
// Iterate over all FormElements
foreach ($this->feSpecNative as $fe) {
if (($filter === FORM_ELEMENTS_NATIVE && $fe['type'] === 'subrecord')
|| ($filter === FORM_ELEMENTS_SUBRECORD && $fe['type'] !== 'subrecord')
if (($filter === FORM_ELEMENTS_NATIVE && $fe[FE_TYPE] === 'subrecord')
|| ($filter === FORM_ELEMENTS_SUBRECORD && $fe[FE_TYPE] !== 'subrecord')
// || ($filter === FORM_ELEMENTS_DYNAMIC_UPDATE && $fe['dynamicUpdate'] === 'no')
) {
continue; // skip this FE
......@@ -369,7 +369,7 @@ abstract class AbstractBuildForm {
$htmlFormElementId = HelperFormElement::buildFormElementId($formElement['name'], ($htmlElementNameIdZero) ? 0 : $recordId);
// Construct Marshaller Name: buildElement
$buildElementFunctionName = 'build' . $this->buildElementFunctionName[$formElement['type']];
$buildElementFunctionName = 'build' . $this->buildElementFunctionName[$formElement[FE_TYPE]];
$jsonElement = array();
// Render pure element
......@@ -397,7 +397,7 @@ abstract class AbstractBuildForm {
}
// Construct Marshaller Name: buildRow
$buildRowName = 'buildRow' . $this->buildRowName[$formElement['type']];
$buildRowName = 'buildRow' . $this->buildRowName[$formElement[FE_TYPE]];
$html .= $this->$buildRowName($formElement, $elementHtml, $htmlFormElementId);
// break;
......@@ -566,7 +566,7 @@ abstract class AbstractBuildForm {
$attribute .= $this->getAttributeMode($formElement);
$json = $this->getJsonElementUpdate($htmlFormElementId, $value, $formElement['mode']);
$json = $this->getJsonElementUpdate($htmlFormElementId, $value, $formElement[FE_MODE]);
return "$htmlTag $attribute>$textarea" . $this->getHelpBlock();
......@@ -580,7 +580,7 @@ abstract class AbstractBuildForm {
// MIN( $formElement['maxLength'], tabledefinition)
$maxLength = $this->getColumnSize($formElement['name']);
switch ($formElement['type']) {
switch ($formElement[FE_TYPE]) {
case 'date':
$feMaxLength = 10;
break;
......@@ -647,7 +647,7 @@ abstract class AbstractBuildForm {
* Builds a HTML attribute list, based on $attributeList.
*
* E.g.: attributeList: [ 'type', 'autofocus' ]
* generates: 'type="$formElement['type']" autofocus="$formElement['autofocus']" '
* generates: 'type="$formElement[FE_TYPE]" autofocus="$formElement['autofocus']" '
*
* @param array $formElement
* @param array $attributeList
......@@ -714,7 +714,7 @@ abstract class AbstractBuildForm {
}
/**
* Set corresponding html attributes readonly/required/disabled, based on $formElement['mode'].
* Set corresponding html attributes readonly/required/disabled, based on $formElement[FE_MODE].
*
* @param array $formElement
* @return string
......@@ -723,7 +723,7 @@ abstract class AbstractBuildForm {
private function getAttributeMode(array $formElement) {
$attribute = '';
switch ($formElement['mode']) {
switch ($formElement[FE_MODE]) {
case 'show':
break;
case 'readonly':
......@@ -740,8 +740,8 @@ abstract class AbstractBuildForm {
default:
// Preparation for Log, Debug
$this->store->setVar(SYSTEM_FORM_ELEMENT, Logger::formatFormElementName($formElement), STORE_SYSTEM);
$this->store->setVar(SYSTEM_FORM_ELEMENT_COLUMN, 'mode', STORE_SYSTEM);
throw new UserFormException("Unknown mode '" . $formElement['mode'] . "'", ERROR_UNKNOWN_MODE);
$this->store->setVar(SYSTEM_FORM_ELEMENT_COLUMN, FE_MODE, STORE_SYSTEM);
throw new UserFormException("Unknown mode '" . $formElement[FE_MODE] . "'", ERROR_UNKNOWN_MODE);
break;
}
return $attribute;
......@@ -790,7 +790,7 @@ abstract class AbstractBuildForm {
}
$attributeBase = $this->getAttributeMode($formElement);
$attributeBase .= Support::doAttribute('type', $formElement['type']);
$attributeBase .= Support::doAttribute('type', $formElement[FE_TYPE]);
switch ($formElement['checkBoxMode']) {
case 'single':
......@@ -803,7 +803,7 @@ abstract class AbstractBuildForm {
throw new UserFormException('checkBoxMode: \'' . $formElement['checkBoxMode'] . '\' is unknown.', ERROR_CHECKBOXMODE_UNKNOWN);
}
$json = $this->getJsonElementUpdate($htmlFormElementId, $value, $formElement['mode']);
$json = $this->getJsonElementUpdate($htmlFormElementId, $value, $formElement[FE_MODE]);
// return Support::wrapTag('<div class="checkbox">', $html, true);
return $html;
}
......@@ -1099,7 +1099,7 @@ abstract class AbstractBuildForm {
$attributeBase = $this->getAttributeMode($formElement);
$attributeBase .= Support::doAttribute('name', $htmlFormElementId);
$attributeBase .= Support::doAttribute('type', $formElement['type']);
$attributeBase .= Support::doAttribute('type', $formElement[FE_TYPE]);
$attributeBase .= Support::doAttribute('data-load', ($formElement['dynamicUpdate'] === 'yes') ? 'data-load' : '');
$jj = 0;
......@@ -1126,8 +1126,8 @@ abstract class AbstractBuildForm {
// $element = Support::wrapTag('<label>',$element);
// if(isset($this->feDivClass[$formElement['type']]) && $this->feDivClass[$formElement['type']] != '') {
// $element = Support::wrapTag('<div class="' . $this->feDivClass[$formElement['type']] .'">', $element);
// if(isset($this->feDivClass[$formElement[FE_TYPE]]) && $this->feDivClass[$formElement[FE_TYPE]] != '') {
// $element = Support::wrapTag('<div class="' . $this->feDivClass[$formElement[FE_TYPE]] .'">', $element);
// }
$html .= $element;
......@@ -1138,7 +1138,7 @@ abstract class AbstractBuildForm {
}
}
$json = $this->getJsonElementUpdate($htmlFormElementId, $value, $formElement['mode']);
$json = $this->getJsonElementUpdate($htmlFormElementId, $value, $formElement[FE_MODE]);
return $html;
}
......@@ -1192,7 +1192,7 @@ abstract class AbstractBuildForm {
$option .= '>' . $itemValue[$ii] . '</option>';
}
$json = $this->getJsonElementUpdate($htmlFormElementId, $jsonValues, $formElement['mode']);
$json = $this->getJsonElementUpdate($htmlFormElementId, $jsonValues, $formElement[FE_MODE]);
return '<select ' . $attribute . '>' . $option . '</select>' . $this->getHelpBlock();
}
......@@ -1577,7 +1577,7 @@ abstract class AbstractBuildForm {
} else {
$textDeleteClass = '';
$uploadClass = 'hidden';
$formElement['mode'] = 'disabled';
$formElement[FE_MODE] = 'disabled';
}
$attribute .= $this->getAttributeMode($formElement);
......@@ -1591,7 +1591,7 @@ abstract class AbstractBuildForm {
// <button type="button" class="file-delete" data-sip="571d1fc9e6974"><span class="glyphicon glyphicon-trash"></span></button>
$json = $this->getJsonElementUpdate($htmlFormElementId, $value, $formElement['mode']);
$json = $this->getJsonElementUpdate($htmlFormElementId, $value, $formElement[FE_MODE]);
return $htmlTextDelete . $htmlInputFile . $hiddenSipUpload;
}
......@@ -1643,7 +1643,7 @@ abstract class AbstractBuildForm {
$attribute .= $this->getAttributeMode($formElement);
$json = $this->getJsonElementUpdate($htmlFormElementId, $value, $formElement['mode']);
$json = $this->getJsonElementUpdate($htmlFormElementId, $value, $formElement[FE_MODE]);
return "$htmlTag $attribute>$textarea";
......@@ -1671,11 +1671,11 @@ abstract class AbstractBuildForm {
$arrMinMax = null;
$this->adjustMaxLength($formElement);
$showTime = ($formElement['type'] == 'time' || $formElement['type'] == 'datetime') ? 1 : 0;
$showTime = ($formElement[FE_TYPE] == 'time' || $formElement[FE_TYPE] == 'datetime') ? 1 : 0;
$value = Support::convertDateTime($value, $formElement[FE_DATE_FORMAT], $formElement[FE_SHOW_ZERO], $showTime, $formElement[FE_SHOW_SECONDS]);
$tmpPattern = $formElement['checkPattern'];
$formElement['checkPattern'] = Support::dateTimeRegexp($formElement['type'], $formElement['dateFormat']);
$formElement['checkPattern'] = Support::dateTimeRegexp($formElement[FE_TYPE], $formElement['dateFormat']);
switch ($formElement['checkType']) {
......@@ -1702,7 +1702,7 @@ abstract class AbstractBuildForm {
$value = substr($value, 0, $formElement['maxLength']);
}
$type = $formElement['type'];
$type = $formElement[FE_TYPE];
if ($type === 'datetime')
$type = 'datetime-local';
......@@ -1715,7 +1715,7 @@ abstract class AbstractBuildForm {
if ($formElement['placeholder'] == '') {
$timePattern = ($formElement[FE_SHOW_SECONDS] == 1) ? 'hh:mm:ss' : 'hh:mm';
switch ($formElement['type']) {
switch ($formElement[FE_TYPE]) {
case 'date':
$placeholder = $formElement['dateFormat'];
break;
......@@ -1726,7 +1726,7 @@ abstract class AbstractBuildForm {
$placeholder = $timePattern;
break;
default:
throw new UserFormException("Unexpected Formelement type: '" . $formElement['type'] . "'", ERROR_FORMELEMENT_TYPE);
throw new UserFormException("Unexpected Formelement type: '" . $formElement[FE_TYPE] . "'", ERROR_FORMELEMENT_TYPE);
}
$formElement['placeholder'] = $placeholder;
}
......@@ -1743,7 +1743,7 @@ abstract class AbstractBuildForm {
$attribute .= $this->getAttributeMode($formElement);
$json = $this->getJsonElementUpdate($htmlFormElementId, $value, $formElement['mode']);
$json = $this->getJsonElementUpdate($htmlFormElementId, $value, $formElement[FE_MODE]);
return "<input $attribute>" . $this->getHelpBlock();
......@@ -1827,7 +1827,7 @@ abstract class AbstractBuildForm {
// restore parent processed FE's
$this->feSpecNative = $tmpStore;
$json = $this->getJsonElementUpdate($htmlFormElementId, $value, $formElement['mode']);
$json = $this->getJsonElementUpdate($htmlFormElementId, $value, $formElement[FE_MODE]);
return $html;
}
......
......@@ -70,7 +70,7 @@ class BuildFormPlain extends AbstractBuildForm {
$html = '';
// Construct Marshaller Name
// $buildElementFunctionName = 'build' . $this->buildElementFunctionName[$formElement['type']];
// $buildElementFunctionName = 'build' . $this->buildElementFunctionName[$formElement[FE_TYPE]];
if($formElement['nestedInFieldSet']==='no')
......
......@@ -97,9 +97,9 @@ class BuildFormTable extends AbstractBuildForm {
$html = '';
// Construct Marshaller Name
$buildElementFunctionName = 'build' . $this->buildElementFunctionName[$formElement['type']];
$buildElementFunctionName = 'build' . $this->buildElementFunctionName[$formElement[FE_TYPE]];
if ($formElement['type'] === 'subrecord') {
if ($formElement[FE_TYPE] === 'subrecord') {
// subrecord in render='table' are outside the table
$html .= $this->wrapItem(WRAP_SETUP_SUBRECORD, $formElement['label']);
$html .= $this->wrapItem(WRAP_SETUP_SUBRECORD, $htmlElement);
......
......@@ -373,6 +373,7 @@ const FE_SUBRECORD_ROW_TITLE = '_rowTitle';
// FormElement columns: real
const FE_TYPE = 'type';
const FE_MODE = 'mode';
// FormElement columns: via parameter field
const FE_DATE_FORMAT = 'dateFormat'; // value: FORMAT_DATE_INTERNATIONAL | FORMAT_DATE_GERMAN
......
......@@ -123,7 +123,7 @@ class Save {
foreach ($this->feSpecNative AS $formElement) {
// skip non upload formElements
if ($formElement['type'] != 'upload') {
if ($formElement[FE_TYPE] != 'upload') {
continue;
}
......
......@@ -425,7 +425,7 @@ class Support {
public static function getDateTimePlaceholder(array $formElement) {
$timePattern = ($formElement[FE_SHOW_SECONDS] == 1) ? 'hh:mm:ss' : 'hh:mm';
switch ($formElement['type']) {
switch ($formElement[FE_TYPE]) {
case 'date':
$placeholder = $formElement['dateFormat'];
break;
......@@ -436,7 +436,7 @@ class Support {
$placeholder = $timePattern;
break;
default:
throw new UserFormException("Unexpected Formelement type: '" . $formElement['type'] . "'", ERROR_FORMELEMENT_TYPE);
throw new UserFormException("Unexpected Formelement type: '" . $formElement[FE_TYPE] . "'", ERROR_FORMELEMENT_TYPE);
}
return $placeholder;
......
......@@ -120,7 +120,7 @@ class FillStoreForm {
// Preparation for Log, Debug
// $this->store->setVar(SYSTEM_FORM_ELEMENT, $formElement['name'] . ' / ' . $formElement['id'], STORE_SYSTEM);
if ($formElement['type'] == 'hidden') {
if ($formElement[FE_TYPE] == 'hidden') {
// Hidden elements will be transferred by SIP
if (!isset($sipValues[$formElement['name']])) {
throw new CodeException("Missing the hidden field '" . $formElement['name'] . "' in SIP.", ERROR_MISSING_HIDDEN_FIELD_IN_SIP);
......@@ -130,13 +130,13 @@ class FillStoreForm {
continue;
}
if ($formElement['mode'] === FE_MODE_REQUIRED) {
if ($formElement[FE_MODE] === FE_MODE_REQUIRED) {
if (!isset($clientValues[$clientFieldName]) || ($clientValues[$clientFieldName] === '')) {
throw new UserFormException("Missing required value.", ERROR_REQUIRED_VALUE_EMPTY);
}
}
switch ($formElement['mode']) {
switch ($formElement[FE_MODE]) {
case FE_MODE_REQUIRED:
case FE_MODE_SHOW:
if (isset($clientValues[$clientFieldName])) {
......@@ -151,7 +151,7 @@ class FillStoreForm {
$clientValues[$clientFieldName] = implode(',', $clientValues[$clientFieldName]);
}
switch ($formElement['type']) {
switch ($formElement[FE_TYPE]) {
case 'date':
case 'datetime':
case 'time':
......@@ -171,7 +171,7 @@ class FillStoreForm {
case FE_MODE_DISABLED:
continue;
default:
throw new CodeException("Unknown mode: " . $formElement['mode'], ERROR_UNKNOWN_MODE);
throw new CodeException("Unknown mode: " . $formElement[FE_MODE], ERROR_UNKNOWN_MODE);
}
}
......@@ -188,14 +188,14 @@ class FillStoreForm {
*/
private function doDateTime(array &$formElement, $value) {
$regexp = Support::dateTimeRegexp($formElement['type'], $formElement['dateFormat']);
$regexp = Support::dateTimeRegexp($formElement[FE_TYPE], $formElement['dateFormat']);
if (1 !== preg_match('/' . $regexp . '/', $value, $matches)) {
$placeholder = Support::getDateTimePlaceholder($formElement);
throw new UserFormException("DateTime format not recognized: $placeholder / $value ", ERROR_DATE_TIME_FORMAT_NOT_RECOGNISED);
}
$showTime = $formElement['type'] == 'date' ? '0' : '1';
$showTime = $formElement[FE_TYPE] == 'date' ? '0' : '1';
$value = Support::convertDateTime($value, FORMAT_DATE_INTERNATIONAL, '1', $showTime, $formElement[FE_SHOW_SECONDS]);
return $value;
......
......@@ -193,9 +193,9 @@ class BuildFormPlainTest extends AbstractDatabaseTest {
'enabled' => 'yes',
'name' => 'name',
'label' => 'Name',
'mode' => 'show',
FE_MODE => 'show',
'class' => 'native',
'type' => 'input',
FE_TYPE => 'input',
'value' => '',
'sql1' => '',
'parameter' => '',
......
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