本文整理汇总了PHP中question_add_tops函数的典型用法代码示例。如果您正苦于以下问题:PHP question_add_tops函数的具体用法?PHP question_add_tops怎么用?PHP question_add_tops使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了question_add_tops函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: question_category_options
/**
* 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;
}
}
示例2: question_category_options
/**
* 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;
}
}