Skip to content

Commit

Permalink
GHI167 - Fixing feedback score calculations for boolean questions.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Churchward committed Dec 1, 2018
1 parent 51b8324 commit 80fdab2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
16 changes: 12 additions & 4 deletions classes/response/boolean.php
Expand Up @@ -103,12 +103,20 @@ public function get_feedback_scores(array $rids) {
}
$params[] = 'y';

$sql = 'SELECT response_id as rid, COUNT(response_id) AS score ' .
$feedbackscores = false;
$sql = 'SELECT response_id, choice_id ' .
'FROM {'.$this->response_table().'} ' .
'WHERE question_id= ? ' . $rsql . ' AND choice_id = ? ' .
'GROUP BY response_id ' .
'WHERE question_id= ? ' . $rsql . ' ' .
'ORDER BY response_id ASC';
return $DB->get_recordset_sql($sql, $params);
if ($responses = $DB->get_recordset_sql($sql, $params)) {
$feedbackscores = [];
foreach ($responses as $rid => $response) {
$feedbackscores[$rid] = new \stdClass();
$feedbackscores[$rid]->rid = $rid;
$feedbackscores[$rid]->score = ($response->choice_id == 'y') ? 1 : 0;
}
}
return $feedbackscores;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion classes/response/single.php
Expand Up @@ -152,7 +152,7 @@ public function get_feedback_scores(array $rids) {
'INNER JOIN {questionnaire_quest_choice} c ON r.choice_id = c.id ' .
'WHERE r.question_id= ? ' . $rsql . ' ' .
'ORDER BY response_id ASC';
return $DB->get_recordset_sql($sql, $params);
return $DB->get_records_sql($sql, $params);
}

/**
Expand Down

0 comments on commit 80fdab2

Please sign in to comment.