function question_delete_course in Quiz 6.6
Same name and namespace in other branches
- 6.5 includes/moodle/lib/questionlib.php \question_delete_course()
All question categories and their questions are deleted for this course.
Parameters
object $mod an object representing the activity:
boolean $feedback to specify if the process must output a summary of its work:
Return value
boolean
File
- includes/
moodle/ lib/ questionlib.php, line 513
Code
function question_delete_course($course, $feedback = true) {
//To store feedback to be showed at the end of the process
$feedbackdata = array();
//Cache some strings
$strcatdeleted = get_string('unusedcategorydeleted', 'quiz');
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
$categoriescourse = get_records('question_categories', 'contextid', $coursecontext->id, 'parent', 'id, parent, name');
if ($categoriescourse) {
//Sort categories following their tree (parent-child) relationships
//this will make the feedback more readable
$categoriescourse = sort_categories_by_tree($categoriescourse);
foreach ($categoriescourse as $category) {
//Delete it completely (questions and category itself)
//deleting questions
if ($questions = get_records("question", "category", $category->id)) {
foreach ($questions as $question) {
delete_question($question->id);
}
delete_records("question", "category", $category->id);
}
//delete the category
delete_records('question_categories', 'id', $category->id);
//Fill feedback
$feedbackdata[] = array(
$category->name,
$strcatdeleted,
);
}
//Inform about changes performed if feedback is enabled
if ($feedback) {
$table = new stdClass();
$table->head = array(
get_string('category', 'quiz'),
get_string('action'),
);
$table->data = $feedbackdata;
print_table($table);
}
}
return true;
}