function question_category_options in Quiz 6.6
Same name and namespace in other branches
- 6.5 includes/moodle/lib/questionlib.php \question_category_options()
Output an array of question categories.
2 calls to question_category_options()
- qformat_coursetestmanager::importprocess in includes/
moodle/ question/ format/ coursetestmanager/ format.php - Process the file This method should not normally be overidden
- question_category_select_menu in includes/
moodle/ lib/ questionlib.php - Output a select menu of question categories.
File
- includes/
moodle/ lib/ questionlib.php, line 1951
Code
function question_category_options($contexts, $top = false, $currentcat = 0, $popupform = false, $nochildrenof = -1) {
global $CFG;
$pcontexts = array();
foreach ($contexts as $context) {
$pcontexts[] = $context->id;
}
$contextslist = join($pcontexts, ', ');
$categories = get_categories_for_contexts($contextslist);
$categories = question_add_context_in_key($categories);
if ($top) {
$categories = question_add_tops($categories, $pcontexts);
}
$categories = add_indented_names($categories, $nochildrenof);
//sort cats out into different contexts
$categoriesarray = array();
foreach ($pcontexts as $pcontext) {
$contextstring = print_context_name(get_context_instance_by_id($pcontext), true, true);
foreach ($categories as $category) {
if ($category->contextid == $pcontext) {
$cid = $category->id;
if ($currentcat != $cid || $currentcat == 0) {
$countstring = !empty($category->questioncount) ? " ({$category->questioncount})" : '';
$categoriesarray[$contextstring][$cid] = $category->indentedname . $countstring;
}
}
}
}
if ($popupform) {
$popupcats = array();
foreach ($categoriesarray as $contextstring => $optgroup) {
$popupcats[] = '--' . $contextstring;
$popupcats = array_merge($popupcats, $optgroup);
$popupcats[] = '--';
}
return $popupcats;
}
else {
return $categoriesarray;
}
}