You are here

public function TrueFalseQuestion::save in Quiz 6.6

Same name and namespace in other branches
  1. 6.3 question_types/quiz_question/quiz_question.truefalse.inc \TrueFalseQuestion::save()
  2. 6.5 question_types/quiz_question/quiz_question.truefalse.inc \TrueFalseQuestion::save()

Responsible for handling insert/update of question-specific data. This is typically called from within the Node API, so there is no need to save the node. This function is only responsible for saving data specific to the implement ation.

The $is_new flag is set to TRUE whenever the node is being initially created.

A save function is required to handle the following three situations:

  • A new node is created ($is_new is TRUE)
  • A new node *revision* is created ($is_new is NOT set, because the node itself is not new).
  • An existing node revision is modified.

Parameters

$is_new: TRUE when the node is initially created.

Overrides QuizQuestion::save

File

question_types/truefalse/truefalse.classes.inc, line 24
Defines the classes necessary for a True/False quiz.

Class

TrueFalseQuestion
Implementation of QuizQuestion.

Code

public function save($is_new = FALSE) {

  //drupal_set_message('Save called', 'status');
  if (!isset($this->node->feedback)) {
    $this->node->feedback = '';
  }
  if ($is_new || $this->node->revision == 1) {
    $sql = "INSERT INTO {quiz_truefalse_node} (nid, vid, correct_answer, feedback) VALUES (%d, %d, %d, '%s')";
    db_query($sql, $this->node->nid, $this->node->vid, (int) $this->node->correct_answer, $this->node->feedback);
  }
  else {
    drupal_set_message('Updating', 'status');
    $sql = "UPDATE {quiz_truefalse_node} SET correct_answer = %d, feedback = '%s' WHERE nid = %d AND vid = %d";
    db_query($sql, (int) $this->node->correct_answer, $this->node->feedback, $this->node->nid, $this->node->vid);
  }
}