You are here

public function MatchingResponse::save in Quiz 7.6

Same name and namespace in other branches
  1. 6.6 question_types/matching/matching.classes.inc \MatchingResponse::save()
  2. 6.3 question_types/matching/matching.classes.inc \MatchingResponse::save()
  3. 6.4 question_types/matching/matching.classes.inc \MatchingResponse::save()
  4. 6.5 question_types/matching/matching.classes.inc \MatchingResponse::save()
  5. 7 question_types/matching/matching.classes.inc \MatchingResponse::save()
  6. 7.4 question_types/matching/matching.classes.inc \MatchingResponse::save()
  7. 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 455
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->result_id,
      'answer' => (int) $value,
      'score' => $key == $value ? 1 : 0,
    ));
  }
  $insert
    ->execute();
}