From: moodler Date: Wed, 21 Jan 2004 16:44:22 +0000 (+0000) Subject: New function quiz_delete_course() which deletes all the leftover stuff X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=b2d594c8ded001c6974866e430934c52e8082b0b;p=moodle.git New function quiz_delete_course() which deletes all the leftover stuff while a course is being deleted --- diff --git a/mod/quiz/lib.php b/mod/quiz/lib.php index 7ab8c9fabb..a8f6d3d67c 100644 --- a/mod/quiz/lib.php +++ b/mod/quiz/lib.php @@ -165,6 +165,35 @@ function quiz_delete_instance($id) { return $result; } +function quiz_delete_course($course) { +/// Given a course object, this function will clean up anything that +/// would be leftover after all the instances were deleted +/// In this case, all the quiz categories and questions + + if ($categories = get_records("quiz_categories", "course", $course->id)) { + foreach ($categories as $category) { + if ($questions = get_records("quiz_questions", "category", $category->id)) { + foreach ($questions as $question) { + delete_records("quiz_answers", "question", $question->id); + delete_records("quiz_match", "question", $question->id); + delete_records("quiz_match_sub", "question", $question->id); + delete_records("quiz_multianswers", "question", $question->id); + delete_records("quiz_multichoice", "question", $question->id); + delete_records("quiz_numerical", "question", $question->id); + delete_records("quiz_randommatch", "question", $question->id); + delete_records("quiz_responses", "question", $question->id); + delete_records("quiz_shortanswer", "question", $question->id); + delete_records("quiz_truefalse", "question", $question->id); + } + delete_records("quiz_questions", "category", $category->id); + } + } + return delete_records("quiz_categories", "course", $course->id); + } + return true; +} + + function quiz_user_outline($course, $user, $mod, $quiz) { /// Return a small object with summary information about what a /// user has done with a given particular instance of this module