You are here

DEVELOPER.txt in Quiz 6.6

NOTES ON DEVELOPING EXTENSIONS FOR QUIZ
=======================================

Hooks for interacting with a quiz:
 - hook_quiz_begin($quiz, $rid): This hook is called when a user first begins a quiz.
 - hook_quiz_finished($quiz, $score, $rid): This hook is called immediately after a user finishes taking a quiz.
 - hook_quiz_scored($quiz, $score, $rid): This is called when a quiz score is updated. See http://drupal.org/node/460456
 

DEVELOPING NEW QUESTION TYPES:

There are two different ways to create a new question type: the "old" way, which 
uses traditional Drupal hooks, but requires substantial coding, and the "new" OO
way, which is much faster to develop.

1. Creating a question type the old way
=======================================

To create a question type the "old" way, you will need to develop a custom 
module that parforms all of the necessary actions. There are several hooks you 
will need to implement. The best place to start is with the multichoice module.

Hooks you need to implement when developing a new question type:

hook_list_questions() // List of questions
hook_quiz_question_info() // Info about a question type.
hook_evaluate_question() // Check whether question is correct or not.
hook_get_report()
hook_render_question()

hook_quiz_question_score() // Given information about a quiz question, determine the score
hook_quiz_personality_question_score() // Given information about a quiz question, determine the personality category

Theme functions
===============
Where {$type} is the question type, e.g. multichoice or long_answer...

theme_{$type}_report() // Report at end of quiz
theme_{$type}_feedback() // Feedback given during the taking of the quiz.


2. Creating a new question type using quiz_question
===================================================

In this method, you need to create a new module that extends the existing 
question type core. The True/False question type provides a precise example.

Here are the steps:

1. Create a new module
2. Use your module's .install file to create the necessary tables
3. Make sure you module implements hook_quiz_question_info()
4. Define classes that implement QuizQuestion and QuizQuestionResponse.
  (Hint: You may want to extend the Abstract classes where available.)
  For a complete example, see quiz_question.truefalse.inc.

File

DEVELOPER.txt
View source
  1. NOTES ON DEVELOPING EXTENSIONS FOR QUIZ
  2. =======================================
  3. Hooks for interacting with a quiz:
  4. - hook_quiz_begin($quiz, $rid): This hook is called when a user first begins a quiz.
  5. - hook_quiz_finished($quiz, $score, $rid): This hook is called immediately after a user finishes taking a quiz.
  6. - hook_quiz_scored($quiz, $score, $rid): This is called when a quiz score is updated. See http://drupal.org/node/460456
  7. DEVELOPING NEW QUESTION TYPES:
  8. There are two different ways to create a new question type: the "old" way, which
  9. uses traditional Drupal hooks, but requires substantial coding, and the "new" OO
  10. way, which is much faster to develop.
  11. 1. Creating a question type the old way
  12. =======================================
  13. To create a question type the "old" way, you will need to develop a custom
  14. module that parforms all of the necessary actions. There are several hooks you
  15. will need to implement. The best place to start is with the multichoice module.
  16. Hooks you need to implement when developing a new question type:
  17. hook_list_questions() // List of questions
  18. hook_quiz_question_info() // Info about a question type.
  19. hook_evaluate_question() // Check whether question is correct or not.
  20. hook_get_report()
  21. hook_render_question()
  22. hook_quiz_question_score() // Given information about a quiz question, determine the score
  23. hook_quiz_personality_question_score() // Given information about a quiz question, determine the personality category
  24. Theme functions
  25. ===============
  26. Where {$type} is the question type, e.g. multichoice or long_answer...
  27. theme_{$type}_report() // Report at end of quiz
  28. theme_{$type}_feedback() // Feedback given during the taking of the quiz.
  29. 2. Creating a new question type using quiz_question
  30. ===================================================
  31. In this method, you need to create a new module that extends the existing
  32. question type core. The True/False question type provides a precise example.
  33. Here are the steps:
  34. 1. Create a new module
  35. 2. Use your module's .install file to create the necessary tables
  36. 3. Make sure you module implements hook_quiz_question_info()
  37. 4. Define classes that implement QuizQuestion and QuizQuestionResponse.
  38. (Hint: You may want to extend the Abstract classes where available.)
  39. For a complete example, see quiz_question.truefalse.inc.