You are here

public function QuizQuestion::save in Quiz 7.6

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.4 question_types/quiz_question/quiz_question.core.inc \QuizQuestion::save()
  4. 6.5 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 216
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($this->node->is_new);
  db_merge('quiz_question_properties')
    ->key(array(
    'nid' => $this->node->nid,
    'vid' => $this->node->vid,
  ))
    ->fields(array(
    'nid' => $this->node->nid,
    'vid' => $this->node->vid,
    'max_score' => $this
      ->getMaximumScore(),
    'feedback' => !empty($this->node->feedback['value']) ? $this->node->feedback['value'] : '',
    'feedback_format' => !empty($this->node->feedback['format']) ? $this->node->feedback['format'] : filter_default_format(),
  ))
    ->execute();

  // Save what quizzes this question belongs to.
  // @kludge the quiz nid/vid are still on the node
  if (!empty($this->node->quiz_nid)) {
    $this
      ->saveRelationships($this->node->quiz_nid, $this->node->quiz_vid);
  }
  if (!empty($this->node->revision)) {
    if (user_access('manual quiz revisioning') && !variable_get('quiz_auto_revisioning', 1)) {
      unset($_GET['destination']);
      unset($_REQUEST['edit']['destination']);
      drupal_goto("node/{$this->node->nid}/question-revision-actions");
    }
  }
}