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

MultiForm Save - successful in simple way

parent 234ee19c
Pipeline #2403 passed with stages
in 2 minutes and 57 seconds
......@@ -226,10 +226,7 @@ abstract class AbstractBuildForm {
}
// Check for 'id' or '_id' as column name
$idName = F_MULTI_COL_ID;
if (isset($parentRecords[0]['_' . F_MULTI_COL_ID])) {
$idName = '_' . F_MULTI_COL_ID;
}
$idName = isset($parentRecords[0]['_' . F_MULTI_COL_ID]) ? '_' . F_MULTI_COL_ID : F_MULTI_COL_ID;
// Check that an column 'id' is given
if (!isset($parentRecords[0][$idName])) {
......@@ -281,6 +278,8 @@ abstract class AbstractBuildForm {
/**
* @param array $row
* @return string
* @throws \CodeException
* @throws \UserFormException
*/
private function buildMultiFormTableHead(array $row) {
$line = '';
......@@ -293,8 +292,19 @@ abstract class AbstractBuildForm {
}
// Collect label from FormElements
foreach ($this->feSpecNative as $fe) {
$line .= '<th>' . $fe[FE_LABEL] . '</th>';
foreach ($this->feSpecNative as $formElement) {
$editFeHtml = '';
// debugStack as Tooltip
if ($this->showDebugInfoFlag) {
// Build 'FormElement' Edit symbol
$feEditUrl = $this->createFormEditorUrl(FORM_NAME_FORM_ELEMENT, $formElement[FE_ID], ['formId' => $formElement[FE_FORM_ID]]);
$titleAttr = Support::doAttribute('title', $this->formSpec[FE_NAME] . ' / ' . $formElement[FE_NAME] . ' [' . $formElement[FE_ID] . ']');
$icon = Support::wrapTag('<span class="' . GLYPH_ICON . ' ' . GLYPH_ICON_EDIT . '">', '');
$editFeHtml = ' ' . Support::wrapTag("<a class='hidden " . CLASS_FORM_ELEMENT_EDIT . "' href='$feEditUrl' $titleAttr>", $icon);
}
$line .= '<th>' . $formElement[FE_LABEL] . $editFeHtml . '</th>';
}
return $line;
......@@ -392,7 +402,7 @@ abstract class AbstractBuildForm {
}
/**
* Builds the head area of the form.
* Build the head area of the form.
*
* @param string $mode
* @return string
......@@ -845,16 +855,19 @@ abstract class AbstractBuildForm {
if ($flagOutput) {
// debugStack as Tooltip
if ($this->showDebugInfoFlag && !$flagMulti) {
if ($this->showDebugInfoFlag) {
if (count($debugStack) > 0) {
$elementHtml .= Support::doTooltip($formElement[FE_HTML_ID] . HTML_ID_EXTENSION_TOOLTIP, implode("\n", $debugStack));
}
// Build 'FormElement' Edit symbol
$feEditUrl = $this->createFormEditorUrl(FORM_NAME_FORM_ELEMENT, $formElement[FE_ID], ['formId' => $formElement[FE_FORM_ID]]);
$titleAttr = Support::doAttribute('title', $this->formSpec[FE_NAME] . ' / ' . $formElement[FE_NAME] . ' [' . $formElement[FE_ID] . ']');
$icon = Support::wrapTag('<span class="' . GLYPH_ICON . ' ' . GLYPH_ICON_EDIT . '">', '');
$elementHtml .= Support::wrapTag("<a class='hidden " . CLASS_FORM_ELEMENT_EDIT . "' href='$feEditUrl' $titleAttr>", $icon);
if (!$flagMulti) {
// Build 'FormElement' Edit symbol. MultiForms: Edit symbol is in thead.
$feEditUrl = $this->createFormEditorUrl(FORM_NAME_FORM_ELEMENT, $formElement[FE_ID], ['formId' => $formElement[FE_FORM_ID]]);
$titleAttr = Support::doAttribute('title', $this->formSpec[FE_NAME] . ' / ' . $formElement[FE_NAME] . ' [' . $formElement[FE_ID] . ']');
$icon = Support::wrapTag('<span class="' . GLYPH_ICON . ' ' . GLYPH_ICON_EDIT . '">', '');
$elementHtml .= Support::wrapTag("<a class='hidden " . CLASS_FORM_ELEMENT_EDIT . "' href='$feEditUrl' $titleAttr>", $icon);
}
}
// Construct Marshaller Name: buildRow...
......
......@@ -9,15 +9,15 @@
namespace IMATHUZH\Qfq\Core;
use IMATHUZH\Qfq\Core\Database\Database;
use IMATHUZH\Qfq\Core\Helper\HelperFile;
use IMATHUZH\Qfq\Core\Helper\HelperFormElement;
use IMATHUZH\Qfq\Core\Helper\Logger;
use IMATHUZH\Qfq\Core\Helper\OnArray;
use IMATHUZH\Qfq\Core\Helper\Sanitize;
use IMATHUZH\Qfq\Core\Helper\Support;
use IMATHUZH\Qfq\Core\Store\Store;
use IMATHUZH\Qfq\Core\Store\Sip;
use IMATHUZH\Qfq\Core\Helper\HelperFile;
use IMATHUZH\Qfq\Core\Helper\OnArray;
use IMATHUZH\Qfq\Core\Store\Store;
use IMATHUZH\Qfq\Core\Store\FillStoreForm;
/**
* Class Save
......@@ -70,17 +70,13 @@ class Save {
* @throws \CodeException
* @throws \DbException
* @throws \UserFormException
* @throws \UserReportException
*/
public function process() {
$rc = 0;
if ($this->formSpec[F_MULTI_SQL] !== '') {
$parentRecords = $this->db->sql($this->formSpec[F_MULTI_SQL]);
foreach ($parentRecords as $row) {
$this->store->setStore($row, STORE_PARENT_RECORD, true);
$rc = $this->elements($row['_id']);
}
$rc = $this->saveMultiForm();
} else {
$recordId = $this->store->getVar(SIP_RECORD_ID, STORE_SIP . STORE_ZERO);
$rc = $this->elements($recordId);
......@@ -89,6 +85,48 @@ class Save {
return $rc;
}
/**
* @return int|string
* @throws \CodeException
* @throws \DbException
* @throws \UserFormException
* @throws \UserReportException
*/
private function saveMultiForm() {
$parentRecords = $this->evaluate->parse($this->formSpec[F_MULTI_SQL], ROW_REGULAR);
// No rows: nothing to do.
if (empty($parentRecords)) {
//TODO Meldung konfigurierbar machen.
return 'No data';
}
// Check for 'id' or '_id' as column name
$idName = isset($parentRecords[0]['_' . F_MULTI_COL_ID]) ? '_' . F_MULTI_COL_ID : F_MULTI_COL_ID;
// Check that an column 'id' is given
if (!isset($parentRecords[0][$idName])) {
throw new \UserFormException(
json_encode([ERROR_MESSAGE_TO_USER => 'Missing column "_' . F_MULTI_COL_ID . '"', ERROR_MESSAGE_TO_DEVELOPER => $this->formSpec[F_MULTI_SQL]]),
ERROR_INVALID_OR_MISSING_PARAMETER);
}
$fillStoreForm = new FillStoreForm();
foreach ($parentRecords as $row) {
$this->store->setStore($row, STORE_PARENT_RECORD, true);
// Fake current recordId
$this->store->setVar(SIP_RECORD_ID, $row[$idName], STORE_SIP);
$fillStoreForm->process(FORM_SAVE);
$rc = $this->elements($row[$idName]);
}
return $rc;
}
/**
* Create empty FormElements based on templateGroups, for those who not already exist.
*
......@@ -176,7 +214,7 @@ class Save {
* @throws \UserFormException
* @throws \DbException
*/
public function elements($recordId) {
private function elements($recordId) {
$columnCreated = false;
$columnModified = false;
......
......@@ -345,7 +345,7 @@ 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 are no multi
* separated string (MYSQL ENUM type). If there is no element '_h_${clientFieldName}', than there are no multi
* values - return the already given `$clientValues[$clientFieldName]`.
*
* @param $clientFieldName
......
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