當前位置: 首頁>>代碼示例>>PHP>>正文


PHP question_add_context_in_key函數代碼示例

本文整理匯總了PHP中question_add_context_in_key函數的典型用法代碼示例。如果您正苦於以下問題:PHP question_add_context_in_key函數的具體用法?PHP question_add_context_in_key怎麽用?PHP question_add_context_in_key使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了question_add_context_in_key函數的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;
    }
}
開發者ID:e-rasvet,項目名稱:reader,代碼行數:43,代碼來源:questionlib.php

示例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;
    }
}
開發者ID:tyleung,項目名稱:CMPUT401MoodleExams,代碼行數:47,代碼來源:questionlib.php


注:本文中的question_add_context_in_key函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。