public function ChoiceResponse::score in Quiz 6.6
Implementation of score
Return value
uint
File
- question_types/
choice/ choice.classes.inc, line 637 - The main classes for the choice question type.
Class
- ChoiceResponse
- The short answer question response class.
Code
public function score() {
if ($this->question->choice_boolean) {
$score = 1;
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;
}