From 238735c6066d279da89d5710410526a763823c8a Mon Sep 17 00:00:00 2001 From: Denis Chenu Date: Thu, 19 Dec 2024 12:07:38 +0100 Subject: [PATCH] Fixed issue #19899: Order of question when copying are bad --- .../controllers/QuestionAdministrationController.php | 1 + application/models/Question.php | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/application/controllers/QuestionAdministrationController.php b/application/controllers/QuestionAdministrationController.php index c946d735ca3..37b44b273a2 100644 --- a/application/controllers/QuestionAdministrationController.php +++ b/application/controllers/QuestionAdministrationController.php @@ -1698,6 +1698,7 @@ public function actionCopyQuestion() $newQuestionPosition = 1; break; default: //all other cases means after question X (the value coming from frontend is already correct) + Question::increaseAllOrderNumbersForGroup($questionGroupId, $questionPosition); $newQuestionPosition = $questionPosition; } $copyQuestionValues->setQuestionPositionInGroup($newQuestionPosition); diff --git a/application/models/Question.php b/application/models/Question.php index dea083e1dab..08c6371eb56 100644 --- a/application/models/Question.php +++ b/application/models/Question.php @@ -1543,10 +1543,16 @@ public static function getHighestQuestionOrderNumberInGroup($questionGroupId) * Increases all question_order numbers for questions belonging to the group by +1 * * @param int $questionGroupId + * @param integer|null $after questionorder */ - public static function increaseAllOrderNumbersForGroup($questionGroupId) + public static function increaseAllOrderNumbersForGroup($questionGroupId, $after = null) { - $questionsInGroup = Question::model()->findAllByAttributes(["gid" => $questionGroupId]); + $criteria = new CDbCriteria(); + $criteria->compare("gid", $questionGroupId); + if ($after) { + $criteria->compare("question_order", ">=" . $after); + } + $questionsInGroup = Question::model()->findAll($criteria); foreach ($questionsInGroup as $question) { $question->question_order = $question->question_order + 1; $question->save();