You are here

public function QuizQuestion::save in OG Quiz 7

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

includes/og_quiz_question.php, line 425
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);
  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(),
  ))
    ->execute();

  // 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($_GET['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_ROOT . '/' . drupal_get_path('module', 'quiz_question') . '/quiz_question.pages.inc';
      drupal_form_submit('quiz_question_revision_actions', $form_state, $this->node->nid, $this->node->vid);
    }
  }
}