/** * Output an array of question categories. */ 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; } }
/** * Output an array of question categories. */ 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 $contextid) { $context = context::instance_by_id($contextid); $contextstring = $context->get_context_name(true, true); foreach ($categories as $category) { if ($category->contextid == $contextid) { $cid = $category->id; if ($currentcat != $cid || $currentcat == 0) { $countstring = !empty($category->questioncount) ? " ({$category->questioncount})" : ''; $categoriesarray[$contextstring][$cid] = format_string($category->indentedname, true, array('context' => $context)) . $countstring; } } } } if ($popupform) { $popupcats = array(); foreach ($categoriesarray as $contextstring => $optgroup) { $group = array(); foreach ($optgroup as $key => $value) { $key = str_replace($CFG->wwwroot, '', $key); $group[$key] = $value; } $popupcats[] = array($contextstring => $group); } return $popupcats; } else { return $categoriesarray; } }