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

1 Answer 1


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.


 * 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)) {

  // 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);


  // If the quiz is saved as not randomized we have to make sure that questions
  // belonging to the quiz are saved as not random.



 * 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.



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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