public function MultichoiceResponse::score in Quiz 8.4
Implementation of score
Return value
uint
Overrides QuizQuestionResponse::score
See also
QuizQuestionResponse#score()
File
- question_types/
multichoice/ lib/ Drupal/ multichoice/ MultichoiceResponse.php, line 128
Class
- MultichoiceResponse
- Extension of QuizQuestionResponse
Namespace
Drupal\multichoiceCode
public function score() {
if ($this->question->choice_boolean || $this
->isAllWrong()) {
$score = $this
->getMaxScore();
foreach ($this->question->alternatives as $key => $alt) {
if (in_array($alt['id'], $this->user_answer_ids)) {
if ($alt['score_if_chosen'] <= $alt['score_if_not_chosen']) {
$score = 0;
}
}
else {
if ($alt['score_if_chosen'] > $alt['score_if_not_chosen']) {
$score = 0;
}
}
}
}
else {
$score = 0;
foreach ($this->question->alternatives as $key => $alt) {
if (in_array($alt['id'], $this->user_answer_ids)) {
$score += $alt['score_if_chosen'];
}
else {
$score += $alt['score_if_not_chosen'];
}
}
}
return $score;
}