public function MatchingResponse::save in Quiz 8.4
Implementation of save
Overrides QuizQuestionResponse::save
See also
QuizQuestionResponse#save()
File
- question_types/
matching/ lib/ Drupal/ matching/ MatchingResponse.php, line 52
Class
- MatchingResponse
- Extension of QuizQuestionResponse
Namespace
Drupal\matchingCode
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();
}