You are here

public function QuizQuestion::save in Quiz 6.4

Same name and namespace in other branches
  1. 6.6 question_types/quiz_question/quiz_question.core.inc \QuizQuestion::save()
  2. 6.3 question_types/quiz_question/quiz_question.core.inc \QuizQuestion::save()
  3. 6.5 question_types/quiz_question/quiz_question.core.inc \QuizQuestion::save()
  4. 7.6 question_types/quiz_question/quiz_question.core.inc \QuizQuestion::save()
  5. 7 question_types/quiz_question/quiz_question.core.inc \QuizQuestion::save()
  6. 7.4 question_types/quiz_question/quiz_question.core.inc \QuizQuestion::save()
  7. 7.5 question_types/quiz_question/quiz_question.core.inc \QuizQuestion::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.

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.

See also

hook_update and hook_insert in quiz_question.module

File

question_types/quiz_question/quiz_question.core.inc, line 353
Classes used in the Quiz Question module.

Class

QuizQuestion
A base implementation of a quiz_question, adding a layer of abstraction between the node API, quiz API and the question types.

Code

public function save($is_new = FALSE) {

  // We call the abstract function saveNodeProperties to save type specific data
  $this
    ->saveNodeProperties($is_new);
  $is_new_node = $is_new || $this->node->revision == 1;

  // Save general data
  if ($is_new_node) {
    $sql = 'INSERT INTO {quiz_question_properties}
              (nid, vid, max_score)
              VALUES(%d, %d, %d)';
    db_query($sql, $this->node->nid, $this->node->vid, $this
      ->getMaximumScore());
  }
  else {
    $sql = 'UPDATE {quiz_question_properties}
              SET max_score = %d
              WHERE nid = %d AND vid = %d';
    db_query($sql, $this
      ->getMaximumScore(), $this->node->nid, $this->node->vid);
  }

  // Save what quizzes this question belongs to.
  $quizzes_kept = $this
    ->saveRelationships();
  if ($quizzes_kept && $this->node->revision) {
    if (user_access('manual quiz revisioning') && !variable_get('quiz_auto_revisioning', 1)) {
      unset($_REQUEST['destination']);
      unset($_REQUEST['edit']['destination']);
      drupal_goto('quiz_question/' . $this->node->nid . '/' . $this->node->vid . '/revision_actions');
    }
    else {
      $form_state = array();
      $form_state['values']['op'] = t('Submit');
      require_once drupal_get_path('module', 'quiz_question') . '/quiz_question.pages.inc';
      drupal_execute('quiz_question_revision_actions', $form_state, $this->node->nid, $this->node->vid);
    }
  }
}