Commit 86ccb5eb authored by Carsten  Rose's avatar Carsten Rose
Browse files

Bug #3912 / templateGroup: max. 5 instances are saved.

FormAction.php: get templateGroup.maxLength (=maxCopies) via a generic function.
HelperFormElement.php: new tgGetMaxLength()
FillStoreForm.php: fixed a broken if statement. Use of new tgGetMaxLength() function.
parent 2df4900d
......@@ -1054,7 +1054,7 @@ const TOKEN_ACTION_DELETE_CLOSE = 'c';
const TOKEN_CLASS_NONE = 'n';
const TOKEN_CLASS_INTERNAL = 'i';
const TOKEN_CLASfindS_EXTERNAL = 'e';
const TOKEN_CLASS_EXTERNAL = 'e';
const WKHTML_OPTION_VIEWPORT = '--viewport-size';
const WKHTML_OPTION_VIEWPORT_VALUE = '1280x1024';
......
......@@ -87,22 +87,19 @@ class FormAction {
// Process templateGroup action elements
if (isset($fe[FE_ID_CONTAINER]) && $fe[FE_ID_CONTAINER] > 0) {
//TODO: hier muss ein FE_TG_DEFAULT gesetzt werden, im Fall es ist keine maxlength angegeben.
// Get native 'templateGroup'-FE - to retrieve MAX_LENGTH
$feTemplateGroup = $this->db->sql(SQL_FORM_ELEMENT_TEMPLATE_GROUP_FE_ID, ROW_REGULAR, [$fe[FE_ID_CONTAINER]]);
if (isset($feTemplateGroup[0][FE_TYPE]) && $feTemplateGroup[0][FE_TYPE] == FE_TYPE_TEMPLATE_GROUP) {
if (count($feTemplateGroup) == 1) {
$fe[FE_ID_CONTAINER] = 0;
for ($ii = 1; $ii <= $feTemplateGroup[0][FE_MAX_LENGTH]; $ii++) {
$feNew = OnArray::arrayValueReplace($fe, FE_TEMPLATE_GROUP_NAME_PATTERN, $ii);
$feNew = OnArray::arrayValueReplace($feNew, FE_TEMPLATE_GROUP_NAME_PATTERN_0, $ii - 1);
if ($this->elements($recordId, [$feNew], $feTypeList)) {
$flagModified = true;
}
$templateGroup = $this->db->sql(SQL_FORM_ELEMENT_TEMPLATE_GROUP_FE_ID, ROW_EXPECT_1, [$fe[FE_ID_CONTAINER]],
"In FormElement.id=" . $fe[FE_ID] . ", feIdContainer=" . $fe[FE_ID_CONTAINER] . ' should point to a templateGroup');
if (isset($templateGroup[FE_TYPE]) && $templateGroup[FE_TYPE] == FE_TYPE_TEMPLATE_GROUP) {
$maxCopies = HelperFormElement::tgGetMaxLength($templateGroup[FE_MAX_LENGTH]);
$fe[FE_ID_CONTAINER] = 0; // Flag to make the nested TG unnested and therefore the SQLs are fired.
for ($ii = 1; $ii <= $maxCopies; $ii++) {
$feNew = OnArray::arrayValueReplace($fe, FE_TEMPLATE_GROUP_NAME_PATTERN, $ii);
$feNew = OnArray::arrayValueReplace($feNew, FE_TEMPLATE_GROUP_NAME_PATTERN_0, $ii - 1);
if ($this->elements($recordId, [$feNew], $feTypeList)) {
$flagModified = true;
}
} else {
// At the moment 'action' elements have to point to a templateGroup - nothing else is defined. Break if there is something else
throw new UserFormException("Expect a 'templateGroup' record in FormElement.id=" . $fe[FE_ID_CONTAINER], ERROR_RECORD_NOT_FOUND);
}
continue; // skip to next FormElement
}
......
......@@ -320,4 +320,13 @@ EOF;
return $formElement;
}
/**
* Returns $maxLenght if greater than 0, else FE_TEMPLATE_GROUP_DEFAULT_MAX_LENGTH
*
* @param $maxLength
* @return int
*/
public static function tgGetMaxLength($maxLength) {
return (empty($maxLength)) ? FE_TEMPLATE_GROUP_DEFAULT_MAX_LENGTH : $maxLength;
}
}
\ No newline at end of file
......@@ -96,12 +96,12 @@ class FillStoreForm {
if ($fe[FE_ID_CONTAINER] > 0) {
// Search for a corresponding template group.
foreach ($feSpecTemplateGroup as $templateGroup) {
if ($fe[FE_ID_CONTAINER] = $templateGroup[FE_ID]) {
if ($fe[FE_ID_CONTAINER] == $templateGroup[FE_ID]) {
$flagCopied = true;
// Get max copies per template group
$maxCopies = ($templateGroup[FE_MAX_LENGTH] == 0 || $templateGroup[FE_MAX_LENGTH] == '') ? FE_TEMPLATE_GROUP_DEFAULT_MAX_LENGTH : $templateGroup[FE_MAX_LENGTH];
$maxCopies = HelperFormElement::tgGetMaxLength($templateGroup[FE_MAX_LENGTH]);
// Copy each native FormElement
$template = $fe[FE_NAME];
......@@ -170,7 +170,7 @@ class FillStoreForm {
foreach ($this->feSpecNative AS $formElement) {
// Never get a predefined 'id'
if ($formElement[FE_NAME] === 'id')
if ($formElement[FE_NAME] === COLUMN_ID)
continue;
// Preparation for Log, Debug
......
......@@ -160,6 +160,26 @@ class HelperFormElementTest extends \PHPUnit_Framework_TestCase {
$this->assertEquals($expect, $result, "Both arrays should be equal");
}
public function testTgGetMaxLength() {
$result = HelperFormElement::tgGetMaxLength('');
$this->assertEquals(FE_TEMPLATE_GROUP_DEFAULT_MAX_LENGTH, $result, "Expect Default");
$result = HelperFormElement::tgGetMaxLength(0);
$this->assertEquals(FE_TEMPLATE_GROUP_DEFAULT_MAX_LENGTH, $result, "Expect Default");
$result = HelperFormElement::tgGetMaxLength('0');
$this->assertEquals(FE_TEMPLATE_GROUP_DEFAULT_MAX_LENGTH, $result, "Expect Default");
$result = HelperFormElement::tgGetMaxLength('1');
$this->assertEquals('1', $result, "Expect Default");
$result = HelperFormElement::tgGetMaxLength('10');
$this->assertEquals('10', $result, "Expect Default");
$result = HelperFormElement::tgGetMaxLength(10);
$this->assertEquals('10', $result, "Expect Default");
}
// public function testExplodeTemplateGroupElements() {
// $formElements = array();
//
......
Supports Markdown
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