You are here

public function MatchingResponse::save in Quiz 7.5

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.6 question_types/matching/matching.classes.inc \MatchingResponse::save()
  6. 7 question_types/matching/matching.classes.inc \MatchingResponse::save()
  7. 7.4 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 453
Matching classes.

Class

MatchingResponse
Extension of QuizQuestionResponse

Code

public function save() {
  $this
    ->delete();
  $insert = db_insert('quiz_matching_user_answers')
    ->fields(array(
    'match_id',
    'result_answer_id',
    'answer',
    'score',
  ));
  foreach ($this->answer as $key => $value) {
    $insert
      ->values(array(
      'match_id' => $key,
      'result_answer_id' => $this->result_answer_id,
      'answer' => (int) $value,
      'score' => $key == $value ? 1 : 0,
    ));
  }
  $insert
    ->execute();
}