Skip to content
Snippets Groups Projects
Commit 84e2a5b6 authored by Carsten  Rose's avatar Carsten Rose
Browse files

FillStoreForm.php: Recode. Class Evaluate will be instantiated only once....

FillStoreForm.php: Recode. Class Evaluate will be instantiated only once. collectMultiValues() recoded not to use arrays anymore, instead a string with the final values, seperated by comma, is returned.
parent b08a6db2
No related branches found
No related tags found
No related merge requests found
......@@ -31,13 +31,21 @@ class FillStoreForm {
*/
private $feSpecNative = array();
/**
* @var Evaluate
*/
private $evaluate = null;
/**
*
*/
public function __construct() {
$this->store = Store::getInstance();
$this->db = new Database();
$this->feSpecNative = $this->loadFormElementsBasedOnSIP();
$this->evaluate = new Evaluate($this->store, $this->db);
}
/**
......@@ -106,21 +114,16 @@ class FillStoreForm {
// Preparation for Log, Debug
$this->store->setVar(SYSTEM_FORM_ELEMENT, Logger::formatFormElementName($formElement), STORE_SYSTEM);
// evaluate current FormElement: e.g. FE_MODE_SQL
$evaluate = new Evaluate($this->store, $this->db);
$formElement = $evaluate->parseArray($formElement, $debugStack);
// Evaluate current FormElement: e.g. FE_MODE_SQL
$formElement = $this->evaluate->parseArray($formElement, $debugStack);
// Get related formElement.
// construct the field name used in the form
// Get related formElement. Construct the field name used in the form.
$clientFieldName = HelperFormElement::buildFormElementId($formElement['name'], $sipValues[SIP_RECORD_ID]);
// Some Defaults
$formElement = Support::setFeDefaults($formElement);
// Preparation for Log, Debug
// $this->store->setVar(SYSTEM_FORM_ELEMENT, $formElement['name'] . ' / ' . $formElement['id'], STORE_SYSTEM);
if ($formElement[FE_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);
......@@ -131,8 +134,8 @@ class FillStoreForm {
}
// Checkbox Multi: collect values
if ($formElement[FE_TYPE] == 'checkbox') {
$clientValues[$clientFieldName] = $this->collectCheckboxMultiValue($clientFieldName, $clientValues);
if ($formElement[FE_TYPE] === 'checkbox') {
$clientValues[$clientFieldName] = $this->collectMultiValues($clientFieldName, $clientValues);
}
if ($formElement[FE_MODE] === FE_MODE_REQUIRED) {
......@@ -146,16 +149,6 @@ class FillStoreForm {
case FE_MODE_SHOW:
if (isset($clientValues[$clientFieldName])) {
// CHECKBOX MULTI (SELECT MULTI ?): delivered as array - implode them.
if (is_array($clientValues[$clientFieldName])) {
// E.g. Checkboxes needs a 'HIDDEN' HTML input to detect 'unset' of values. These 'HIDDEN' element
// needs to be removed, if there is at least one checkbox is checked (=submitted)
if (count($clientValues[$clientFieldName]) > 1)
array_shift($clientValues[$clientFieldName]);
$clientValues[$clientFieldName] = implode(',', $clientValues[$clientFieldName]);
}
switch ($formElement[FE_TYPE]) {
case 'date':
case 'datetime':
......@@ -183,21 +176,23 @@ class FillStoreForm {
}
/**
* Steps through all $clientValues (POST vars) and collect all with the name _?_${clientFieldName} in a comma seperated string (MYSQL ENUM type).
* If there is no element '_h_${clientFieldName}', than there no multi values - return the already given `$clientValues[$clientFieldName]`.
*
* @param $clientFieldName
* @param array $clientValues
* @return mixed
* @return string
*/
private function collectCheckboxMultiValue($clientFieldName, array $clientValues) {
$checkboxValue = array();
private function collectMultiValues($clientFieldName, array $clientValues) {
$checkboxKey = HelperFormElement::prependFormElementIdCheckBoxMulti($clientFieldName, 'h');
// Check there is a hidden value with naming in checkbox multi syntax
if (isset($clientValues[$checkboxKey])) {
$checkboxValue[] = $clientValues[$checkboxKey];
$checkboxValue = $clientValues[$checkboxKey];
$pattern = '/' . HelperFormElement::prependFormElementIdCheckBoxMulti($clientFieldName, '\d+') . '/';
foreach ($clientValues as $key => $value) {
if (1 === preg_match($pattern, $key)) {
$checkboxValue[] = $value;
$checkboxValue .= ',' . $value;
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment