本文整理汇总了PHP中add_indented_names函数的典型用法代码示例。如果您正苦于以下问题:PHP add_indented_names函数的具体用法?PHP add_indented_names怎么用?PHP add_indented_names使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了add_indented_names函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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 $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;
}
}
示例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 $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;
}
}
示例3: question_category_options
/**
* Output an array of question categories.
*
* Categories from this course and (optionally) published categories from other courses
* are included. Optionally, only categories the current user may edit can be included.
*
* @param integer $courseid the id of the course to get the categories for.
* @param integer $published if true, include publised categories from other courses.
* @param integer $only_editable if true, exclude categories this user is not allowed to edit.
* @return array The list of categories.
*/
function question_category_options($courseid, $published = false, $only_editable = false)
{
global $CFG;
// get sql fragment for published
$publishsql = "";
if ($published) {
$publishsql = " OR publish = 1";
}
$categories = get_records_sql("\n SELECT cat.*, c.shortname AS coursename\n FROM {$CFG->prefix}question_categories cat, {$CFG->prefix}course c\n WHERE c.id = cat.course AND (cat.course = {$courseid} {$publishsql})\n ORDER BY (CASE WHEN cat.course = {$courseid} THEN 0 ELSE 1 END), cat.parent, cat.sortorder, cat.name ASC");
$categories = add_indented_names($categories);
$categoriesarray = array();
foreach ($categories as $category) {
$cid = $category->id;
$cname = question_category_coursename($category, $courseid);
if (!$only_editable || has_capability('moodle/question:managecategory', get_context_instance(CONTEXT_COURSE, $category->course))) {
$categoriesarray[$cid] = $cname;
}
}
return $categoriesarray;
}