Skip to content

Commit

Permalink
fixed issue #19108 - move subquestion code by typing instead of dragging
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin-foster-uk committed Sep 23, 2023
1 parent 02838ac commit dc083bd
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions application/controllers/QuestionAdministrationController.php
Expand Up @@ -2858,8 +2858,16 @@ private function storeSubquestions($question, $subquestionsArray)
$subquestionIds = [];
foreach ($subquestionsArray as $subquestionArray) {
foreach ($subquestionArray as $scaleId => $data) {
$subquestion = null;
if (isset($data['oldcode'])) {
// If the subquestion with given code already exists, update it.

This comment has been minimized.

Copy link
@Shnoulle

Shnoulle Sep 25, 2023

Collaborator

My opinion : only previous question must be updated. Here : you update not related question.

Then you can keep uneeded default value

$subquestion = Question::model()->findByAttributes([
'sid' => $question->sid,
'parent_qid' => $question->qid,
'title' => $data['code'],
'scale_id' => $scaleId
]);
if (!$subquestion && isset($data['oldcode'])) {
// If the subquestion with given code does not exist
// - but subquestion with old code exists, update it.
$subquestion = Question::model()->findByAttributes([
'sid' => $question->sid,
'parent_qid' => $question->qid,
Expand All @@ -2871,8 +2879,8 @@ private function storeSubquestions($question, $subquestionsArray)
$subquestion = new Question();
}

$subquestion->sid = $question->sid;
$subquestion->gid = $question->gid;
$subquestion->sid = $question->sid;
$subquestion->gid = $question->gid;
$subquestion->parent_qid = $question->qid;
$subquestion->question_order = $questionOrder;
$questionOrder++;
Expand All @@ -2882,11 +2890,11 @@ private function storeSubquestions($question, $subquestionsArray)
'Internal error: Missing mandatory field code for question: ' . json_encode($data)
);
}
$subquestion->title = $data['code'];
$subquestion->title = $data['code'];
if ($scaleId === 0) {
$subquestion->relevance = $data['relevance'];
$subquestion->relevance = $data['relevance'];
}
$subquestion->scale_id = $scaleId;
$subquestion->scale_id = $scaleId;
if (!$subquestion->save()) {
array_push($errorQuestions, $subquestion);
continue;
Expand Down

0 comments on commit dc083bd

Please sign in to comment.