You are here

function multichoice_nodeapi in Quiz 6.6

Same name and namespace in other branches
  1. 6.3 question_types/multichoice/multichoice.module \multichoice_nodeapi()
  2. 6.5 question_types/multichoice/multichoice.module \multichoice_nodeapi()

Implementation of hook_nodeapi(). This is supposed to replace the hook_submit() features from the 5.x version.

File

question_types/multichoice/multichoice.module, line 456
Multiple choice question type for the Quiz module.

Code

function multichoice_nodeapi(&$node, $op) {
  if ($op == 'presave' && $node->type == 'multichoice') {
    if (!user_access('allow user titles') || empty($node->title)) {

      // User is not allowed to set a title or they left it blank, so make one for them.
      $node->title = theme('multichoice_generate_title', $node);
    }
    if (!user_access('allow multiple correct answers')) {

      // Convert the select box to the old checkbox.
      $node->answers[$node->correct]['correct'] = TRUE;
    }
  }
  if ($op == 'prepare' && $node->type == 'multichoice') {

    // Set defaults to pass E_STRICT on new node creation
    if (!isset($node->multiple_answers)) {
      $node->multiple_answers = FALSE;
    }
    if (!isset($node->answers)) {
      $node->answers = NULL;
    }
  }
}