Skip to content

Commit

Permalink
fix(section,question): don't force ordering on import
Browse files Browse the repository at this point in the history
 questins and sections may be shuffled on import. Don't overwrite order property

Signed-off-by: Thierry Bugier <tbugier@teclib.com>
  • Loading branch information
btry committed Nov 24, 2020
1 parent db689c0 commit fedf621
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 25 deletions.
3 changes: 3 additions & 0 deletions inc/exportabletrait.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@

trait PluginFormcreatorExportableTrait
{

protected $useAutomaticOrdering = true;

/**
* Insert the export of sub items in the export
*
Expand Down
10 changes: 0 additions & 10 deletions inc/form.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1966,16 +1966,6 @@ public static function import(PluginFormcreatorLinker $linker, $input = [], $con
// add the form to the linker
$linker->addObject($originalId, $item);

// sort sections
if (isset($input['_sections']) && is_array($input['_sections'])) {
usort($input['_sections'], function($a, $b) {
if ($a['order'] == $b['order']) {
return 0;
}
return ($a['order'] < $b['order']) ? -1 : 1;
});
}

$subItems = [
'_profiles' => PluginFormcreatorForm_Profile::class,
'_sections' => PluginFormcreatorSection::class,
Expand Down
17 changes: 10 additions & 7 deletions inc/question.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -379,14 +379,16 @@ public function prepareInputForAdd($input) {
}
$sectionFk = PluginFormcreatorSection::getForeignKeyField();
// Get next row
if ($this->useAutomaticOrdering) {
$sectionFk = PluginFormcreatorSection::getForeignKeyField();
$maxRow = PluginFormcreatorCommon::getMax($this, [
$sectionFk => $input[$sectionFk]
], 'row');
if ($maxRow === null) {
$input['row'] = 0;
} else {
$input['row'] = $maxRow + 1;
$maxRow = PluginFormcreatorCommon::getMax($this, [
$sectionFk => $input[$sectionFk]
], 'row');
if ($maxRow === null) {
$input['row'] = 0;
} else {
$input['row'] = $maxRow + 1;
}
}

// generate a unique id
Expand Down Expand Up @@ -915,6 +917,7 @@ public static function import(PluginFormcreatorLinker $linker, $input = [], $con
);
$item->update($input);
} else {
$item->useAutomaticOrdering = false;
unset($input['id']);
$itemId = $item->add($input);
}
Expand Down
19 changes: 11 additions & 8 deletions inc/section.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,16 @@ public function prepareInputForAdd($input) {
}

// Get next order
$formId = $input['plugin_formcreator_forms_id'];
$maxOrder = PluginFormcreatorCommon::getMax($this, [
"plugin_formcreator_forms_id" => $formId
], 'order');
if ($maxOrder === null) {
$input['order'] = 1;
} else {
$input['order'] = $maxOrder + 1;
if ($this->useAutomaticOrdering) {
$formId = $input['plugin_formcreator_forms_id'];
$maxOrder = PluginFormcreatorCommon::getMax($this, [
"plugin_formcreator_forms_id" => $formId
], 'order');
if ($maxOrder === null) {
$input['order'] = 1;
} else {
$input['order'] = $maxOrder + 1;
}
}

return $input;
Expand Down Expand Up @@ -297,6 +299,7 @@ public static function import(PluginFormcreatorLinker $linker, $input = [], $con
$item->update($input);
} else {
unset($input['id']);
$item->useAutomaticOrdering = false;
$itemId = $item->add($input);
}
if ($itemId === false) {
Expand Down

0 comments on commit fedf621

Please sign in to comment.