Skip to content

Commit 2259783

Browse files
committed
fix(question,section): duplicate a question or section must duplicate inner conditions
1 parent 7bbb9b8 commit 2259783

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

inc/question.class.php

+15
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,21 @@ public function duplicate(array $options = []) {
772772
$export[$key] = $value;
773773
}
774774
}
775+
776+
// Before importing the question, we need to give to the linker the questions
777+
// used in the conditions of the question being duplicated
778+
$conditions = (new PluginFormcreatorCondition())->find([
779+
'itemtype' => self::getType(),
780+
'items_id' => $this->getID()
781+
]);
782+
foreach ($conditions as $row) {
783+
$question = PluginFormcreatorQuestion::getById($row['plugin_formcreator_questions_id']);
784+
if ($question === null || $question === false) {
785+
continue;
786+
}
787+
$linker->addObject($row['plugin_formcreator_questions_id'], $question);
788+
}
789+
775790
$newQuestionId = static::import($linker, $export, $this->fields[$sectionFk]);
776791

777792
if ($newQuestionId === false) {

inc/section.class.php

+14
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,20 @@ public function duplicate(array $options = []) {
239239
) + 1;
240240
$newSectionId = static::import($linker, $export, $this->fields[$formFk]);
241241

242+
// Before importing the section, we need to give to the linker the questions
243+
// used in the conditions of the section being duplicated
244+
$conditions = (new PluginFormcreatorCondition())->find([
245+
'itemtype' => self::getType(),
246+
'items_id' => $this->getID()
247+
]);
248+
foreach ($conditions as $row) {
249+
$question = PluginFormcreatorQuestion::getById($row['plugin_formcreator_questions_id']);
250+
if ($question === null || $question === false) {
251+
continue;
252+
}
253+
$linker->addObject($row['plugin_formcreator_questions_id'], $question);
254+
}
255+
242256
if ($newSectionId === false) {
243257
return false;
244258
}

0 commit comments

Comments
 (0)