From 22ad0a2e450047cd19f3971a6c1b10ee8a7ef918 Mon Sep 17 00:00:00 2001 From: stronk7 Date: Mon, 30 May 2005 22:25:52 +0000 Subject: [PATCH] Now the quizzes_category_used() function supports searching for uses recursively plus an array of excluded categories. Needed to solve bug 2459...in progress. --- mod/quiz/locallib.php | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/mod/quiz/locallib.php b/mod/quiz/locallib.php index fe02ec49717..41929a4833d 100644 --- a/mod/quiz/locallib.php +++ b/mod/quiz/locallib.php @@ -2466,14 +2466,20 @@ function quizzes_question_used($id) { } /** -* Array of names of quizzes a category appears in +* Array of names of quizzes a category (and optionally its childs) appears in * * @return array Array of quiz names (with quiz->id as array keys) * @param integer Quiz category id +* @param boolean Examine category childs recursively +* @param array Array of categories (id) to exclude */ -function quizzes_category_used($id) { +function quizzes_category_used($id, $recursive=false, &$excluded = array()) { + + echo "Analyse category: $id
"; $quizlist = array(); + + //Look for each question in the category if ($questions = get_records('quiz_questions', 'category', $id)) { foreach ($questions as $question) { $qlist = quizzes_question_used($question->id); @@ -2481,6 +2487,21 @@ function quizzes_category_used($id) { } } + //Mark this category as checked + $excluded[] = $id; + + //Look under child categories recursively + if ($recursive) { + if ($childs = get_records('quiz_categories', 'parent', $id)) { + foreach ($childs as $child) { + //Only if the category isn't excluded + if (!in_array($child->id, $excluded)) { + $quizlist = $quizlist + quizzes_category_used($child->id, $recursive, $excluded); + } + } + } + } + return $quizlist; }