You are here

DEVELOPER.txt in Quiz 6.4

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:

You need to create a new module that extends the existing 
question type core. The multichoice 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 extends QuizQuestion and QuizQuestionResponse.
   For a complete example, see multichoice.classes.inc.
  
  
  
  
==================================================
How to clean up the database during development
==================================================

# see what questions are deleted but still in quizzes
SELECT qnr.* FROM quiz_node_relationship qnr
LEFT JOIN node n ON qnr.child_nid = n.nid 
WHERE n.nid IS NULL

# delete questions that are deleted but still in quizzes
DELETE qnr
FROM quiz_node_relationship qnr
LEFT JOIN node n ON qnr.child_nid = n.nid 
WHERE n.nid IS NULL

# see what quizzes are deleted but still have questions
SELECT qnr.* FROM quiz_node_relationship qnr
LEFT JOIN node n ON qnr.parent_nid = n.nid 
WHERE n.nid IS NULL

# delete quizzes that are deleted but still have questions
DELETE qnr
FROM quiz_node_relationship qnr
LEFT JOIN node n ON qnr.parent_nid = n.nid 
WHERE n.nid IS NULL

# see what revisions are stored for nodes that are deleted
SELECT nr.* FROM node_revisions nr
LEFT JOIN node n ON nr.nid = n.nid 
WHERE n.nid IS NULL

# delete orphaned revisions
DELETE nr
FROM node_revisions nr
LEFT JOIN node n ON nr.nid = n.nid 
WHERE n.nid IS NULL

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. You need to create a new module that extends the existing
  9. question type core. The multichoice question type provides a precise example.
  10. Here are the steps:
  11. 1. Create a new module
  12. 2. Use your module's .install file to create the necessary tables
  13. 3. Make sure you module implements hook_quiz_question_info()
  14. 4. Define classes that extends QuizQuestion and QuizQuestionResponse.
  15. For a complete example, see multichoice.classes.inc.
  16. ==================================================
  17. How to clean up the database during development
  18. ==================================================
  19. # see what questions are deleted but still in quizzes
  20. SELECT qnr.* FROM quiz_node_relationship qnr
  21. LEFT JOIN node n ON qnr.child_nid = n.nid
  22. WHERE n.nid IS NULL
  23. # delete questions that are deleted but still in quizzes
  24. DELETE qnr
  25. FROM quiz_node_relationship qnr
  26. LEFT JOIN node n ON qnr.child_nid = n.nid
  27. WHERE n.nid IS NULL
  28. # see what quizzes are deleted but still have questions
  29. SELECT qnr.* FROM quiz_node_relationship qnr
  30. LEFT JOIN node n ON qnr.parent_nid = n.nid
  31. WHERE n.nid IS NULL
  32. # delete quizzes that are deleted but still have questions
  33. DELETE qnr
  34. FROM quiz_node_relationship qnr
  35. LEFT JOIN node n ON qnr.parent_nid = n.nid
  36. WHERE n.nid IS NULL
  37. # see what revisions are stored for nodes that are deleted
  38. SELECT nr.* FROM node_revisions nr
  39. LEFT JOIN node n ON nr.nid = n.nid
  40. WHERE n.nid IS NULL
  41. # delete orphaned revisions
  42. DELETE nr
  43. FROM node_revisions nr
  44. LEFT JOIN node n ON nr.nid = n.nid
  45. WHERE n.nid IS NULL