Skip to content

Commit

Permalink
Fixed issue #16454: Sometimes, question_order is assigned from survey_id
Browse files Browse the repository at this point in the history
Merge pull request #1482 from gabrieljenik/bug/16454-Sometimes,-question_order-is-assigned-from-survey_id
  • Loading branch information
olleharstedt committed Oct 23, 2020
2 parents d385682 + 1b975c6 commit 078fd36
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions application/models/Question.php
Expand Up @@ -250,10 +250,12 @@ public static function updateSortOrder($gid, $surveyid)

/**
* Fix sort order for questions in a group
* All questions in the group will be assigned a sequential question order,
* starting in the specified value
* @param int $gid
* @param int $position
* @param int $startingOrder the starting question order.
*/
public function updateQuestionOrder($gid, $position = 0)
public function updateQuestionOrder($gid, $startingOrder = 1)
{
$data = Yii::app()->db->createCommand()->select('qid')
->where(array('and', 'gid=:gid', 'parent_qid=0'))
Expand All @@ -262,7 +264,7 @@ public function updateQuestionOrder($gid, $position = 0)
->bindParam(':gid', $gid, PDO::PARAM_INT)
->query();

$position = intval($position);
$position = intval($startingOrder);
foreach ($data->readAll() as $row) {
Yii::app()->db->createCommand()->update(
$this->tableName(),
Expand Down Expand Up @@ -428,7 +430,7 @@ public function delete()
$this->removeFromLastVisited();

if (parent::delete()) {
Question::model()->updateQuestionOrder($this->gid, $this->sid);
Question::model()->updateQuestionOrder($this->gid);
return true;
}
return false;
Expand Down

0 comments on commit 078fd36

Please sign in to comment.