function question_category_isused in Quiz 6.5
Same name and namespace in other branches
- 6.6 includes/moodle/lib/questionlib.php \question_category_isused()
Tests whether a category is in use by any activity module
Parameters
integer $categoryid:
boolean $recursive Whether to examine category children recursively:
Return value
boolean
File
- includes/
moodle/ lib/ questionlib.php, line 395
Code
function question_category_isused($categoryid, $recursive = false) {
//Look at each question in the category
if ($questions = get_records('question', 'category', $categoryid)) {
foreach ($questions as $question) {
if (count(question_list_instances($question->id))) {
return true;
}
}
}
//Look under child categories recursively
if ($recursive) {
if ($children = get_records('question_categories', 'parent', $categoryid)) {
foreach ($children as $child) {
if (question_category_isused($child->id, $recursive)) {
return true;
}
}
}
}
return false;
}