You are here

public function MatchingQuestion::saveNodeProperties in Quiz 7

Same name and namespace in other branches
  1. 6.4 question_types/matching/matching.classes.inc \MatchingQuestion::saveNodeProperties()
  2. 7.6 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 36
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')";

        // TODO Please review the conversion of this statement to the D7 database API syntax.

        /* db_query($sql, $this->node->nid, $this->node->vid, $match['question'], $match['answer'], $match['feedback']) */
        $id = db_insert('quiz_matching_node')
          ->fields(array(
          'nid' => $this->node->nid,
          'vid' => $this->node->vid,
          'question' => $match['question'],
          'answer' => $match['answer'],
          'feedback' => $match['feedback'],
        ))
          ->execute();
      }
    }
    else {
      if (empty($match['question']) && empty($match['answer'])) {

        // remove sub question.
        // TODO Please review the conversion of this statement to the D7 database API syntax.

        /* db_query("DELETE FROM {quiz_matching_node} WHERE match_id = %d", $match['match_id']) */
        db_delete('quiz_matching_node')
          ->condition('match_id', $match['match_id'])
          ->execute();
      }
      else {

        // update sub question.

        //$sql = "UPDATE {quiz_matching_node} SET question = '%s', answer = '%s', feedback = '%s' WHERE match_id = %d";

        // TODO Please review the conversion of this statement to the D7 database API syntax.

        /* db_query($sql, $match['question'], $match['answer'], $match['feedback'], $match['match_id']) */
        db_update('quiz_matching_node')
          ->fields(array(
          'question' => $match['question'],
          'answer' => $match['answer'],
          'feedback' => $match['feedback'],
        ))
          ->condition('match_id', $match['match_id'])
          ->execute();
      }
    }
  }
}