public function MultichoiceResponse::getReportFormResponse in Quiz 8.4
Implementation of getReportFormResponse
Overrides QuizQuestionResponse::getReportFormResponse
See also
getReportFormResponse($showpoints, $showfeedback, $allow_scoring)
File
- question_types/
multichoice/ lib/ Drupal/ multichoice/ MultichoiceResponse.php, line 189
Class
- MultichoiceResponse
- Extension of QuizQuestionResponse
Namespace
Drupal\multichoiceCode
public function getReportFormResponse($showpoints = TRUE, $showfeedback = TRUE, $allow_scoring = FALSE) {
$i = 0;
$this
->orderAlternatives($this->question->alternatives);
// Find the alternative with the highest score
if ($this->question->choice_multi == 0) {
$max_score_if_chosen = -999;
while (isset($this->question->alternatives[$i]) && is_array($this->question->alternatives[$i])) {
$short = $this->question->alternatives[$i];
if ($short['score_if_chosen'] > $max_score_if_chosen) {
$max_score_if_chosen = $short['score_if_chosen'];
}
$i++;
}
$i = 0;
}
// Fetch all data for the report
$data = array();
while (isset($this->question->alternatives[$i])) {
$short = $this->question->alternatives[$i];
if (drupal_strlen($this
->checkMarkup($short['answer'], $short['answer_format'])) > 0) {
$alternative = array();
// Did the user choose the alternative?
$alternative['is_chosen'] = in_array($short['id'], $this->user_answer_ids);
// Questions where multiple answers isn't allowed are scored differently...
if ($this->question->choice_multi == 0) {
if ($this->question->choice_boolean == 0) {
if ($short['score_if_chosen'] > $short['score_if_not_chosen']) {
$alternative['is_correct'] = $short['score_if_chosen'] < $max_score_if_chosen ? 1 : 2;
}
else {
$alternative['is_correct'] = 0;
}
}
else {
$alternative['is_correct'] = $short['score_if_chosen'] > $short['score_if_not_chosen'] ? 2 : 0;
}
}
else {
$alternative['is_correct'] = $short['score_if_chosen'] > $short['score_if_not_chosen'] ? 2 : 0;
}
$alternative['answer'] = $this
->checkMarkup($short['answer'], $short['answer_format'], FALSE);
$not = $alternative['is_chosen'] ? '' : '_not';
$alternative['feedback'] = $this
->checkMarkup($short['feedback_if' . $not . '_chosen'], $short['feedback_if' . $not . '_chosen_format'], FALSE);
$data[] = $alternative;
}
$i++;
}
// Return themed report
return array(
'#markup' => theme('multichoice_response', array(
'data' => $data,
)),
);
}