In which part of the code is a new quiz stored in the database? What are the functions responsible for storing a new quiz in the database upon the submission of the form for creating a new quiz?

I'm trying to accomplish two things:

  1. Timer per question
  2. Dynamic question selection strategy

Quiz Module Version: 7.x-5.3

You need to be familiar with Drupal concepts like Nodes and Entities because they are used to model a Quiz.

The logic to keep the pieces synchronized is implemented via Hooks, like _hook_insert_ and _hook_update_, located on the quiz.module file.

Quiz 2.0 Architecture Information

A Quiz is a Drupal node, and thus the node table contains a row for each Quiz. Similarly, a Question is also a Drupal node, so it too has an entry in the node table. Additional properties for Quizzes can be found in the rows of the quiz_node_properties table. Similarly, all question-types have a table called quiz_node_question_properties to store additional data. Each question-type also makes it's own set of tables to hold answers and user feedback. That means the multichoice.module question-type gets a quiz_multichoice_answers and a quiz_multichoice_user_answers.

hook_insert

/**
 * Implements hook_insert().
 */
function quiz_insert($node) {
  // Need to set max_score if this is a cloned node.
  $max_score = 0;

  // Copy all the questions belonging to the quiz if this is a new translation.
  if ($node->is_new && isset($node->translation_source)) {
    quiz_copy_questions($node);
  }

  // Add references to all the questions belonging to the quiz if this is a
  // cloned quiz (node_clone compatibility).
  if ($node->is_new && isset($node->clone_from_original_nid)) {
    $old_quiz = node_load($node->clone_from_original_nid);

    $max_score = $old_quiz->max_score;

    $questions = quiz_get_questions($old_quiz->nid, $old_quiz->vid);

    quiz_set_questions($node, $questions);
  }

  _quiz_common_presave_actions($node);

  // If the quiz is saved as not randomized we have to make sure that questions
  // belonging to the quiz are saved as not random.
  _quiz_check_num_random($node);
  _quiz_check_num_always($node);

  quiz_update_defaults($node);
  _quiz_insert_resultoptions($node);
}

hook_update

/**
 * Implements hook_update().
 */
function quiz_update($node) {
  // Quiz node vid (revision) was updated.
  if (isset($node->revision) && $node->revision) {
    // Create new quiz-question relation entries in the quiz_node_relationship
    // table.
    quiz_update_quiz_question_relationship($node->old_vid, $node->vid, $node->nid);
    drupal_set_message(t('Some of the updated settings may not apply to quiz being taken already. To see all changes in action you need to start again.'), 'warning');
  }

  // Update an existing row in the quiz_node_properties table.
  _quiz_common_presave_actions($node);

  quiz_update_defaults($node);
  _quiz_update_resultoptions($node);

  _quiz_check_num_random($node);
  _quiz_check_num_always($node);
  quiz_update_max_score_properties(array($node->vid));
}

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.