Skip to content

Commit

Permalink
fix(question,section): duplicate a question or section must duplicate…
Browse files Browse the repository at this point in the history
… inner conditions
  • Loading branch information
btry committed Jul 6, 2023
1 parent 7bbb9b8 commit 2259783
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
15 changes: 15 additions & 0 deletions inc/question.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,21 @@ public function duplicate(array $options = []) {
$export[$key] = $value;
}
}

// Before importing the question, we need to give to the linker the questions
// used in the conditions of the question being duplicated
$conditions = (new PluginFormcreatorCondition())->find([
'itemtype' => self::getType(),
'items_id' => $this->getID()
]);
foreach ($conditions as $row) {
$question = PluginFormcreatorQuestion::getById($row['plugin_formcreator_questions_id']);
if ($question === null || $question === false) {
continue;
}
$linker->addObject($row['plugin_formcreator_questions_id'], $question);
}

$newQuestionId = static::import($linker, $export, $this->fields[$sectionFk]);

if ($newQuestionId === false) {
Expand Down
14 changes: 14 additions & 0 deletions inc/section.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,20 @@ public function duplicate(array $options = []) {
) + 1;
$newSectionId = static::import($linker, $export, $this->fields[$formFk]);

// Before importing the section, we need to give to the linker the questions
// used in the conditions of the section being duplicated
$conditions = (new PluginFormcreatorCondition())->find([
'itemtype' => self::getType(),
'items_id' => $this->getID()
]);
foreach ($conditions as $row) {
$question = PluginFormcreatorQuestion::getById($row['plugin_formcreator_questions_id']);
if ($question === null || $question === false) {
continue;
}
$linker->addObject($row['plugin_formcreator_questions_id'], $question);
}

if ($newSectionId === false) {
return false;
}
Expand Down

0 comments on commit 2259783

Please sign in to comment.