public function MatchingResponse::save in Quiz 7
Same name and namespace in other branches
- 6.6 question_types/matching/matching.classes.inc \MatchingResponse::save()
- 6.3 question_types/matching/matching.classes.inc \MatchingResponse::save()
- 6.4 question_types/matching/matching.classes.inc \MatchingResponse::save()
- 6.5 question_types/matching/matching.classes.inc \MatchingResponse::save()
- 7.6 question_types/matching/matching.classes.inc \MatchingResponse::save()
- 7.4 question_types/matching/matching.classes.inc \MatchingResponse::save()
- 7.5 question_types/matching/matching.classes.inc \MatchingResponse::save()
Implementation of save
Overrides QuizQuestionResponse::save
See also
QuizQuestionResponse#save()
File
- question_types/
matching/ matching.classes.inc, line 401 - matching.classes
Class
- MatchingResponse
- Extension of QuizQuestionResponse
Code
public function save() {
if (!isset($this->answer) || !is_array($this->answer)) {
return;
}
$insert = db_insert('quiz_matching_user_answers')
->fields(array(
'match_id',
'result_id',
'answer',
'score',
));
foreach ($this->answer as $key => $value) {
$insert
->values(array(
'match_id' => $key,
'result_id' => $this->rid,
'answer' => (int) $value,
'score' => $key == $value ? 1 : 0,
));
}
$insert
->execute();
}