Skip to content

Commit

Permalink
Fixed issue #19899: Order of question when copying are bad
Browse files Browse the repository at this point in the history
  • Loading branch information
Shnoulle committed Dec 19, 2024
1 parent dfad6fb commit 238735c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 8 additions & 2 deletions application/models/Question.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 238735c

Please sign in to comment.