diff --git a/lib/questionlib.php b/lib/questionlib.php index 6abc4cdf853..f861f921648 100644 --- a/lib/questionlib.php +++ b/lib/questionlib.php @@ -645,7 +645,7 @@ function question_delete_course($course, $feedback=true) { //Cache some strings $strcatdeleted = get_string('unusedcategorydeleted', 'quiz'); $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); - $categoriescourse = $DB->get_records('question_categories', array('contextid'=>$coursecontext->id), 'parent', 'id, parent, name'); + $categoriescourse = $DB->get_records('question_categories', array('contextid'=>$coursecontext->id), 'parent', 'id, parent, name, contextid'); if ($categoriescourse) { @@ -809,7 +809,7 @@ function question_delete_activity($cm, $feedback=true) { //Cache some strings $strcatdeleted = get_string('unusedcategorydeleted', 'quiz'); $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id); - if ($categoriesmods = $DB->get_records('question_categories', array('contextid'=>$modcontext->id), 'parent', 'id, parent, name')){ + if ($categoriesmods = $DB->get_records('question_categories', array('contextid'=>$modcontext->id), 'parent', 'id, parent, name, contextid')){ //Sort categories following their tree (parent-child) relationships //this will make the feedback more readable $categoriesmods = sort_categories_by_tree($categoriesmods); @@ -2265,8 +2265,9 @@ function sort_categories_by_tree(&$categories, $id = 0, $level = 1) { //If level = 1, we have finished, try to look for non processed categories (bad parent) and sort them too if ($level == 1) { foreach ($keys as $key) { - //If not processed and it's a good candidate to start (because its parent doesn't exist in the course) - if (!isset($categories[$key]->processed) && !$DB->record_exists('question_categories', array('course'=>$categories[$key]->course, 'id'=>$categories[$key]->parent))) { + // If not processed and it's a good candidate to start (because its parent doesn't exist in the course) + if (!isset($categories[$key]->processed) && !$DB->record_exists( + 'question_categories', array('contextid'=>$categories[$key]->contextid, 'id'=>$categories[$key]->parent))) { $children[$key] = $categories[$key]; $categories[$key]->processed = true; $children = $children + sort_categories_by_tree($categories, $children[$key]->id, $level+1);