Skip to content

Commit fedf621

Browse files
committed
fix(section,question): don't force ordering on import
questins and sections may be shuffled on import. Don't overwrite order property Signed-off-by: Thierry Bugier <tbugier@teclib.com>
1 parent db689c0 commit fedf621

File tree

4 files changed

+24
-25
lines changed

4 files changed

+24
-25
lines changed

inc/exportabletrait.class.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535

3636
trait PluginFormcreatorExportableTrait
3737
{
38+
39+
protected $useAutomaticOrdering = true;
40+
3841
/**
3942
* Insert the export of sub items in the export
4043
*

inc/form.class.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1966,16 +1966,6 @@ public static function import(PluginFormcreatorLinker $linker, $input = [], $con
19661966
// add the form to the linker
19671967
$linker->addObject($originalId, $item);
19681968

1969-
// sort sections
1970-
if (isset($input['_sections']) && is_array($input['_sections'])) {
1971-
usort($input['_sections'], function($a, $b) {
1972-
if ($a['order'] == $b['order']) {
1973-
return 0;
1974-
}
1975-
return ($a['order'] < $b['order']) ? -1 : 1;
1976-
});
1977-
}
1978-
19791969
$subItems = [
19801970
'_profiles' => PluginFormcreatorForm_Profile::class,
19811971
'_sections' => PluginFormcreatorSection::class,

inc/question.class.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -379,14 +379,16 @@ public function prepareInputForAdd($input) {
379379
}
380380
$sectionFk = PluginFormcreatorSection::getForeignKeyField();
381381
// Get next row
382+
if ($this->useAutomaticOrdering) {
382383
$sectionFk = PluginFormcreatorSection::getForeignKeyField();
383-
$maxRow = PluginFormcreatorCommon::getMax($this, [
384-
$sectionFk => $input[$sectionFk]
385-
], 'row');
386-
if ($maxRow === null) {
387-
$input['row'] = 0;
388-
} else {
389-
$input['row'] = $maxRow + 1;
384+
$maxRow = PluginFormcreatorCommon::getMax($this, [
385+
$sectionFk => $input[$sectionFk]
386+
], 'row');
387+
if ($maxRow === null) {
388+
$input['row'] = 0;
389+
} else {
390+
$input['row'] = $maxRow + 1;
391+
}
390392
}
391393

392394
// generate a unique id
@@ -915,6 +917,7 @@ public static function import(PluginFormcreatorLinker $linker, $input = [], $con
915917
);
916918
$item->update($input);
917919
} else {
920+
$item->useAutomaticOrdering = false;
918921
unset($input['id']);
919922
$itemId = $item->add($input);
920923
}

inc/section.class.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,16 @@ public function prepareInputForAdd($input) {
8585
}
8686

8787
// Get next order
88-
$formId = $input['plugin_formcreator_forms_id'];
89-
$maxOrder = PluginFormcreatorCommon::getMax($this, [
90-
"plugin_formcreator_forms_id" => $formId
91-
], 'order');
92-
if ($maxOrder === null) {
93-
$input['order'] = 1;
94-
} else {
95-
$input['order'] = $maxOrder + 1;
88+
if ($this->useAutomaticOrdering) {
89+
$formId = $input['plugin_formcreator_forms_id'];
90+
$maxOrder = PluginFormcreatorCommon::getMax($this, [
91+
"plugin_formcreator_forms_id" => $formId
92+
], 'order');
93+
if ($maxOrder === null) {
94+
$input['order'] = 1;
95+
} else {
96+
$input['order'] = $maxOrder + 1;
97+
}
9698
}
9799

98100
return $input;
@@ -297,6 +299,7 @@ public static function import(PluginFormcreatorLinker $linker, $input = [], $con
297299
$item->update($input);
298300
} else {
299301
unset($input['id']);
302+
$item->useAutomaticOrdering = false;
300303
$itemId = $item->add($input);
301304
}
302305
if ($itemId === false) {

0 commit comments

Comments
 (0)