Commit 7bf7d517 authored by Carsten  Rose's avatar Carsten Rose

Refs #9517: TypeAhead - Implements insert/delete glue records

parent dbfc591b
Pipeline #3303 passed with stages
in 3 minutes and 41 seconds
......@@ -736,7 +736,8 @@ abstract class AbstractBuildForm {
$html = '';
// The following 'FormElement.parameter' will never be used during load (fe.type='upload'). FE_PARAMETER has been already expanded.
$skip = [FE_SQL_UPDATE, FE_SQL_INSERT, FE_SQL_DELETE, FE_SQL_AFTER, FE_SQL_BEFORE, FE_PARAMETER, FE_FILL_STORE_VAR, FE_FILE_DOWNLOAD_BUTTON];
$skip = [FE_SQL_UPDATE, FE_SQL_INSERT, FE_SQL_DELETE, FE_SQL_AFTER, FE_SQL_BEFORE, FE_PARAMETER,
FE_FILL_STORE_VAR, FE_FILE_DOWNLOAD_BUTTON, FE_TYPEAHEAD_GLUE_INSERT, FE_TYPEAHEAD_GLUE_DELETE, FE_TYPEAHEAD_TAG_INSERT];
// get current data record
$primaryKey = $this->formSpec[F_PRIMARY_KEY];
......@@ -1487,7 +1488,6 @@ abstract class AbstractBuildForm {
$attribute .= Support::doAttribute('data-load', ($formElement[FE_DYNAMIC_UPDATE] === 'yes') ? 'data-load' : '');
$attribute .= Support::doAttribute('title', $formElement[FE_TOOLTIP]);
$attribute .= HelperFormElement::getAttributeFeMode($formElement[FE_MODE], false);
$attribute .= Support::doAttribute('class', $class);
......
......@@ -728,7 +728,8 @@ const VAR_FILENAME_EXT = 'filenameExt'; // Extension of the original filename of
const VAR_FILE_MIME_TYPE = 'mimeType';
const VAR_FILE_SIZE = 'fileSize';
const VAR_ALL_REQUIRED_GIVEN = 'allRequiredGiven'; // If all required FE are given: 1, else: 0. If there is no required FE: 1
const VAR_TAG_ID = 'tagId';
const VAR_TAG_VALUE = 'tagValue';
// PHP class Typeahead
const TYPEAHEAD_API_QUERY = 'query'; // Name of parameter in API call of typeahead.php?query=...&s=... - See also FE_TYPE_AHEAD_SQL
......@@ -1242,7 +1243,7 @@ const FE_TYPEAHEAD_PEDANTIC = F_TYPEAHEAD_PEDANTIC;
const FE_TYPEAHEAD_TAG = 'typeAheadTag';
const FE_TYPEAHEAD_TAG_DELIMITER = 'typeAheadTagDelimiter';
const FE_TYPEAHEAD_GLUE_INSERT = 'typeAheadGlueInsert';
const FE_TYPEAHEAD_GLUE_TAG = 'typeAheadGlueTable';
const FE_TYPEAHEAD_GLUE_DELETE = 'typeAheadGlueDelete';
const FE_TYPEAHEAD_TAG_INSERT = 'typeAheadTagInsert';
const FE_TYPEAHEAD_TAG_TABLE = 'typeAheadTagTable';
......
......@@ -342,12 +342,15 @@ class FormAction {
}
/**
* Process slaveId, sqlBefore, sqlInsert|sqlUpdate|sqlDelete, sqlAfter.
* flagFeAction=false: for Native Elements
* flagFeAction=true: for Action Elements
*
* Create the slave record. First try to evaluate a slaveId. Depending if the slaveId > 0 choose `sqlUpdate` or
* `sqlInsert`
*
* @param array $fe
* @param int $recordId
*
* @param bool $flagFeAction indicates of the FE are of type 'native' or 'action'.
* @return int ACTION_ELEMENT_MODIFIED if there are potential(!) changes on the DB like INSERT / UPDATE,
* ACTION_ELEMENT_NO_CHANGE if nothing happened
......
......@@ -12,6 +12,7 @@ use IMATHUZH\Qfq\Core\Database\Database;
use IMATHUZH\Qfq\Core\Form\FormAction;
use IMATHUZH\Qfq\Core\Helper\HelperFile;
use IMATHUZH\Qfq\Core\Helper\HelperFormElement;
use IMATHUZH\Qfq\Core\Helper\KeyValueStringParser;
use IMATHUZH\Qfq\Core\Helper\Logger;
use IMATHUZH\Qfq\Core\Helper\OnArray;
use IMATHUZH\Qfq\Core\Helper\Sanitize;
......@@ -288,7 +289,6 @@ class Save {
}
$newValues[$column] = $formValues[$column];
$realColumnFound = true;
}
// Only save record if real columns exist.
......@@ -315,6 +315,8 @@ class Save {
}
/**
* Process sqlBefore, sqlInsert|.... for all native FE.
*
* @param $recordId
*
* @throws \CodeException
......@@ -330,6 +332,56 @@ class Save {
$this->store->setVar(SYSTEM_FORM_ELEMENT_ID, $fe[FE_ID], STORE_SYSTEM);
$this->formAction->doSqlBeforeSlaveAfter($fe, $recordId, false);
$this->typeAheadDoTagGlue($fe);
}
}
/**
* typeAhead: if given, process Tag or Glue.
*
* @param array $fe
* @throws \CodeException
* @throws \DbException
* @throws \UserFormException
* @throws \UserReportException
*/
private function typeAheadDoTagGlue(array $fe) {
if (($fe[FE_TYPEAHEAD_TAG] ?? '0') == '0' || (!isset($fe[FE_TYPEAHEAD_GLUE_INSERT]) && !isset($fe[FE_TYPEAHEAD_TAG_INSERT]))) {
return;
}
if (empty($fe[FE_TYPEAHEAD_GLUE_INSERT]) || empty($fe[FE_TYPEAHEAD_GLUE_DELETE])) {
throw new \UserFormException("Missing 'typeAheadGlueInsert' or 'typeAheadGlueDelete'", ERROR_MISSING_REQUIRED_PARAMETER);
}
// Extract assigned tags: last
$tagLast = KeyValueStringParser::parse($this->evaluate->parse($fe[FE_VALUE], ROW_EXPECT_0_1));
// Extract assigned tags: new
$tagNew = KeyValueStringParser::parse($this->store->getVar($fe[FE_NAME], STORE_FORM,
($fe[FE_CHECK_TYPE] == SANITIZE_ALLOW_AUTO) ? SANITIZE_ALLOW_ALNUMX : $fe[FE_CHECK_TYPE]));
// Get all tags who are new
$result = array_diff_assoc($tagNew, $tagLast);
// Create glue records
foreach ($result as $id => $value) {
$this->store->setVar(VAR_TAG_ID, $id, STORE_VAR);
$this->store->setVar(VAR_TAG_VALUE, $value, STORE_VAR);
// Create glue
$this->evaluate->parse($fe[FE_TYPEAHEAD_GLUE_INSERT]);
}
// Get all tags who has been removed
$result = array_diff_assoc($tagLast, $tagNew);
// Delete Glue records
foreach ($result as $id => $value) {
$this->store->setVar(VAR_TAG_ID, $id, STORE_VAR);
$this->store->setVar(VAR_TAG_VALUE, $value, STORE_VAR);
// Delete glue
$this->evaluate->parse($fe[FE_TYPEAHEAD_GLUE_DELETE]);
}
}
......
......@@ -174,7 +174,8 @@ class FillStoreForm {
public function process($formMode = FORM_SAVE) {
// The following will never be used during load (fe.type='upload').
$skip = [FE_SLAVE_ID, FE_SQL_UPDATE, FE_SQL_INSERT, FE_SQL_DELETE, FE_SQL_AFTER, FE_SQL_BEFORE, FE_PARAMETER, FE_VALUE, FE_FILL_STORE_VAR];
$skip = [FE_SLAVE_ID, FE_SQL_UPDATE, FE_SQL_INSERT, FE_SQL_DELETE, FE_SQL_AFTER, FE_SQL_BEFORE, FE_PARAMETER,
FE_VALUE, FE_FILL_STORE_VAR, FE_TYPEAHEAD_GLUE_INSERT, FE_TYPEAHEAD_GLUE_DELETE, FE_TYPEAHEAD_TAG_INSERT];
$html = '';
$newValues = array();
......
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