You are here

public function MatchingQuestion::saveNodeProperties in Quiz 6.4

Same name and namespace in other branches
  1. 7.6 question_types/matching/matching.classes.inc \MatchingQuestion::saveNodeProperties()
  2. 7 question_types/matching/matching.classes.inc \MatchingQuestion::saveNodeProperties()
  3. 7.4 question_types/matching/matching.classes.inc \MatchingQuestion::saveNodeProperties()
  4. 7.5 question_types/matching/matching.classes.inc \MatchingQuestion::saveNodeProperties()

Implementation of saveNodeProperties

Overrides QuizQuestion::saveNodeProperties

See also

QuizQuestion#saveNodeProperties($is_new)

File

question_types/matching/matching.classes.inc, line 34
matching.classes

Class

MatchingQuestion
Extension of QuizQuestion.

Code

public function saveNodeProperties($is_new = FALSE) {

  // Loop through each question-answer combination
  foreach ($this->node->match as $match) {
    $match['feedback'] = isset($match['feedback']) ? $match['feedback'] : '';

    // match_id is not so it is a new question.
    if (empty($match['match_id']) || $this->node->revision) {
      if (!empty($match['question']) && !empty($match['answer'])) {
        $sql = "INSERT INTO {quiz_matching_node} (nid, vid, question, answer, feedback) VALUES (%d, %d, '%s', '%s', '%s')";
        db_query($sql, $this->node->nid, $this->node->vid, $match['question'], $match['answer'], $match['feedback']);
      }
    }
    else {
      if (empty($match['question']) && empty($match['answer'])) {

        // remove sub question.
        db_query("DELETE FROM {quiz_matching_node} WHERE match_id = %d", $match['match_id']);
      }
      else {

        // update sub question.
        $sql = "UPDATE {quiz_matching_node} SET question = '%s', answer = '%s', feedback = '%s' WHERE match_id = %d";
        db_query($sql, $match['question'], $match['answer'], $match['feedback'], $match['match_id']);
      }
    }
  }
}