当前位置: 首页>>代码示例>>PHP>>正文


PHP question_make_default_categories函数代码示例

本文整理汇总了PHP中question_make_default_categories函数的典型用法代码示例。如果您正苦于以下问题:PHP question_make_default_categories函数的具体用法?PHP question_make_default_categories怎么用?PHP question_make_default_categories使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了question_make_default_categories函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: question_edit_setup

/**
 * Common setup for all pages for editing questions.
 * @param string $edittab code for this edit tab
 * @param boolean $requirecmid require cmid? default false
 * @param boolean $requirecourseid require courseid, if cmid is not given? default true
 * @return array $thispageurl, $contexts, $cmid, $cm, $module, $pagevars
 */
function question_edit_setup($edittab, $requirecmid = false, $requirecourseid = true)
{
    global $COURSE, $QUESTION_EDITTABCAPS;
    //$thispageurl is used to construct urls for all question edit pages we link to from this page. It contains an array
    //of parameters that are passed from page to page.
    $thispageurl = new moodle_url();
    if ($requirecmid) {
        $cmid = required_param('cmid', PARAM_INT);
    } else {
        $cmid = optional_param('cmid', 0, PARAM_INT);
    }
    if ($cmid) {
        list($module, $cm) = get_module_from_cmid($cmid);
        $courseid = $cm->course;
        $thispageurl->params(compact('cmid'));
        require_login($courseid, false, $cm);
        $thiscontext = get_context_instance(CONTEXT_MODULE, $cmid);
    } else {
        $module = null;
        $cm = null;
        if ($requirecourseid) {
            $courseid = required_param('courseid', PARAM_INT);
        } else {
            $courseid = optional_param('courseid', 0, PARAM_INT);
        }
        if ($courseid) {
            $thispageurl->params(compact('courseid'));
            require_login($courseid, false);
            $thiscontext = get_context_instance(CONTEXT_COURSE, $courseid);
        } else {
            $thiscontext = null;
        }
    }
    if ($thiscontext) {
        $contexts = new question_edit_contexts($thiscontext);
        $contexts->require_one_edit_tab_cap($edittab);
    } else {
        $contexts = null;
    }
    $pagevars['qpage'] = optional_param('qpage', -1, PARAM_INT);
    //pass 'cat' from page to page and when 'category' comes from a drop down menu
    //then we also reset the qpage so we go to page 1 of
    //a new cat.
    $pagevars['cat'] = optional_param('cat', 0, PARAM_SEQUENCE);
    // if empty will be set up later
    if ($category = optional_param('category', 0, PARAM_SEQUENCE)) {
        if ($pagevars['cat'] != $category) {
            // is this a move to a new category?
            $pagevars['cat'] = $category;
            $pagevars['qpage'] = 0;
        }
    }
    if ($pagevars['cat']) {
        $thispageurl->param('cat', $pagevars['cat']);
    }
    if ($pagevars['qpage'] > -1) {
        $thispageurl->param('qpage', $pagevars['qpage']);
    } else {
        $pagevars['qpage'] = 0;
    }
    $pagevars['qperpage'] = optional_param('qperpage', -1, PARAM_INT);
    if ($pagevars['qperpage'] > -1) {
        $thispageurl->param('qperpage', $pagevars['qperpage']);
    } else {
        $pagevars['qperpage'] = DEFAULT_QUESTIONS_PER_PAGE;
    }
    $sortoptions = array('alpha' => 'name, qtype ASC', 'typealpha' => 'qtype, name ASC', 'age' => 'id ASC');
    if ($sortorder = optional_param('qsortorder', '', PARAM_ALPHA)) {
        $pagevars['qsortorderdecoded'] = $sortoptions[$sortorder];
        $pagevars['qsortorder'] = $sortorder;
        $thispageurl->param('qsortorder', $sortorder);
    } else {
        $pagevars['qsortorderdecoded'] = $sortoptions['typealpha'];
        $pagevars['qsortorder'] = 'typealpha';
    }
    $defaultcategory = question_make_default_categories($contexts->all());
    $contextlistarr = array();
    foreach ($contexts->having_one_edit_tab_cap($edittab) as $context) {
        $contextlistarr[] = "'{$context->id}'";
    }
    $contextlist = join($contextlistarr, ' ,');
    if (!empty($pagevars['cat'])) {
        $catparts = explode(',', $pagevars['cat']);
        if (!$catparts[0] || FALSE !== array_search($catparts[1], $contextlistarr) || !count_records_select("question_categories", "id = '" . $catparts[0] . "' AND contextid = {$catparts['1']}")) {
            print_error('invalidcategory', 'quiz');
        }
    } else {
        $category = $defaultcategory;
        $pagevars['cat'] = "{$category->id},{$category->contextid}";
    }
    if (($recurse = optional_param('recurse', -1, PARAM_BOOL)) != -1) {
        $pagevars['recurse'] = $recurse;
        $thispageurl->param('recurse', $recurse);
//.........这里部分代码省略.........
开发者ID:edwinphillips,项目名称:moodle-485cb39,代码行数:101,代码来源:editlib.php

示例2: __construct

 public function __construct($questiontext, $specificfeedback)
 {
     $syscontext = context_system::instance();
     $category = question_make_default_categories(array($syscontext));
     $fakequestion = new stdClass();
     $fakequestion->qtype = 'stack';
     $fakequestion->category = $category->id;
     $fakequestion->questiontext = $questiontext;
     $fakequestion->options = new stdClass();
     $fakequestion->options->specificfeedback = $specificfeedback;
     $fakequestion->formoptions = new stdClass();
     $fakequestion->formoptions->movecontext = null;
     $fakequestion->formoptions->repeatelements = true;
     $fakequestion->inputs = null;
     parent::__construct(new moodle_url('/'), $fakequestion, $category, new question_edit_contexts($syscontext));
 }
开发者ID:sowirepo,项目名称:moodle-qtype_stack,代码行数:16,代码来源:editform_test.php

示例3: __construct

 public function __construct()
 {
     $syscontext = context_system::instance();
     $category = question_make_default_categories(array($syscontext));
     $fakequestion = new stdClass();
     $fakequestion->qtype = 'stack';
     $fakequestion->category = $category->id;
     $fakequestion->questiontext = 'Test [[1]] question [[2]]';
     $fakequestion->options = new stdClass();
     $fakequestion->options->answers = array();
     $fakequestion->formoptions = new stdClass();
     $fakequestion->formoptions->movecontext = null;
     $fakequestion->formoptions->repeatelements = true;
     $fakequestion->inputs = null;
     parent::__construct(new moodle_url('/'), $fakequestion, $category, new question_edit_contexts($syscontext));
 }
开发者ID:evltuma,项目名称:moodle,代码行数:16,代码来源:edit_form_test.php

示例4: test_question_category_created

 /**
  * Test the question category created event.
  */
 public function test_question_category_created()
 {
     $this->setAdminUser();
     $course = $this->getDataGenerator()->create_course();
     $quiz = $this->getDataGenerator()->create_module('quiz', array('course' => $course->id));
     $contexts = new question_edit_contexts(context_module::instance($quiz->cmid));
     $defaultcategoryobj = question_make_default_categories(array($contexts->lowest()));
     $defaultcategory = $defaultcategoryobj->id . ',' . $defaultcategoryobj->contextid;
     $qcobject = new question_category_object(1, new moodle_url('/mod/quiz/edit.php', array('cmid' => $quiz->cmid)), $contexts->having_one_edit_tab_cap('categories'), $defaultcategoryobj->id, $defaultcategory, null, $contexts->having_cap('moodle/question:add'));
     // Trigger and capture the event.
     $sink = $this->redirectEvents();
     $categoryid = $qcobject->add_category($defaultcategory, 'newcategory', '', true);
     $events = $sink->get_events();
     $event = reset($events);
     // Check that the event data is valid.
     $this->assertInstanceOf('\\core\\event\\question_category_created', $event);
     $this->assertEquals(context_module::instance($quiz->cmid), $event->get_context());
     $expected = array($course->id, 'quiz', 'addcategory', 'view.php?id=' . $quiz->cmid, $categoryid, $quiz->cmid);
     $this->assertEventLegacyLogData($expected, $event);
     $this->assertEventContextNotUsed($event);
 }
开发者ID:evltuma,项目名称:moodle,代码行数:24,代码来源:events_test.php

示例5: get_string

        $out .= get_string('addrandom', 'quiz', $select);
        $out .= '<input type="hidden" name="recurse" value="' . $recurse . '" />';
        $out .= '<input type="hidden" name="categoryid" value="' . $category->id . '" />';
        $out .= ' <input type="submit" name="addrandom" value="' . get_string('addtoquiz', 'quiz') . '"' . $disabled . ' />';
        $out .= $OUTPUT->help_icon('addarandomquestion', 'quiz');
    }
    return $out;
}
// These params are only passed from page request to request while we stay on
// this page otherwise they would go in question_edit_setup.
$quiz_reordertool = optional_param('reordertool', -1, PARAM_BOOL);
$quiz_qbanktool = optional_param('qbanktool', -1, PARAM_BOOL);
$scrollpos = optional_param('scrollpos', '', PARAM_INT);
list($thispageurl, $contexts, $cmid, $cm, $quiz, $pagevars) = question_edit_setup('editq', '/mod/quiz/edit.php', true);
$quiz->questions = quiz_clean_layout($quiz->questions);
$defaultcategoryobj = question_make_default_categories($contexts->all());
$defaultcategory = $defaultcategoryobj->id . ',' . $defaultcategoryobj->contextid;
if ($quiz_qbanktool > -1) {
    $thispageurl->param('qbanktool', $quiz_qbanktool);
    set_user_preference('quiz_qbanktool_open', $quiz_qbanktool);
} else {
    $quiz_qbanktool = get_user_preferences('quiz_qbanktool_open', 0);
}
if ($quiz_reordertool > -1) {
    $thispageurl->param('reordertool', $quiz_reordertool);
    set_user_preference('quiz_reordertab', $quiz_reordertool);
} else {
    $quiz_reordertool = get_user_preferences('quiz_reordertab', 0);
}
$canaddrandom = $contexts->have_cap('moodle/question:useall');
$canaddquestion = (bool) $contexts->having_add_and_use();
开发者ID:saurabh947,项目名称:MoodleLearning,代码行数:31,代码来源:edit.php

示例6: generate_test

 /**
  * Abstract function implemented by each question type. It runs all the code
  * required to set up and save a question of any type for testing purposes.
  * Alternate DB table prefix may be used to facilitate data deletion.
  */
 function generate_test($name, $courseid = null)
 {
     $form = new stdClass();
     $form->name = $name;
     $form->questiontextformat = 1;
     $form->questiontext = 'test question, generated by script';
     $form->defaultgrade = 1;
     $form->penalty = 0.1;
     $form->generalfeedback = "Well done";
     $context = get_context_instance(CONTEXT_COURSE, $courseid);
     $newcategory = question_make_default_categories(array($context));
     $form->category = $newcategory->id . ',1';
     $question = new stdClass();
     $question->courseid = $courseid;
     $question->qtype = $this->qtype;
     return array($form, $question);
 }
开发者ID:kai707,项目名称:ITSA-backup,代码行数:22,代码来源:questiontype.php

示例7: quiz_print_pagecontrols

/**
 * Print all the controls for adding questions directly into the
 * specific page in the edit tab of edit.php
 *
 * @param unknown_type $quiz
 * @param unknown_type $pageurl
 * @param unknown_type $page
 * @param unknown_type $hasattempts
 */
function quiz_print_pagecontrols($quiz, $pageurl, $page, $hasattempts)
{
    global $CFG;
    static $randombuttoncount = 0;
    $randombuttoncount++;
    echo '<div class="pagecontrols">';
    // Get the current context
    $thiscontext = get_context_instance(CONTEXT_COURSE, $quiz->course);
    $contexts = new question_edit_contexts($thiscontext);
    // Get the default category.
    $defaultcategory = question_make_default_categories($contexts->all());
    // Create the url the question page will return to
    $returnurl_addtoquiz = new moodle_url($pageurl->out(true), array('addonpage' => $page));
    // Print a button linking to the choose question type page.
    $newquestionparams = array('returnurl' => $returnurl_addtoquiz->out(false), 'cmid' => $quiz->cmid, 'appendqnumstring' => 'addquestion');
    create_new_question_button($defaultcategory->id, $newquestionparams, get_string('addaquestion', 'quiz'), get_string('createquestionandadd', 'quiz'), $hasattempts);
    if ($hasattempts) {
        $disabled = 'disabled="disabled"';
    } else {
        $disabled = '';
    }
    ?>
    <div class="singlebutton">
        <form class="randomquestionform" action="<?php 
    echo $CFG->wwwroot;
    ?>
/mod/quiz/addrandom.php" method="get">
            <div>
                <input type="hidden" class="addonpage_formelement" name="addonpage_form" value="<?php 
    echo $page;
    ?>
" />
                <input type="hidden" name="cmid" value="<?php 
    echo $quiz->cmid;
    ?>
" />
                <input type="hidden" name="courseid" value="<?php 
    echo $quiz->course;
    ?>
" />
                <input type="hidden" name="returnurl" value="<?php 
    echo urlencode($pageurl->out(true));
    ?>
" />
                <input type="submit" id="addrandomdialoglaunch_<?php 
    echo $randombuttoncount;
    ?>
" value="<?php 
    echo get_string('addarandomquestion', 'quiz');
    ?>
" <?php 
    echo " {$disabled}";
    ?>
 />
            </div>
        </form>
    </div>
    <?php 
    helpbutton('random', get_string('random', 'quiz'), 'quiz', true, false, '');
    ?>
    <?php 
    echo "\n</div>";
}
开发者ID:nicolasconnault,项目名称:moodle2.0,代码行数:72,代码来源:editlib.php

示例8: qcreate_student_q_access_sync

qcreate_student_q_access_sync($qcreate, $modulecontext, $course);
require_login($course->id);
if (has_capability('mod/qcreate:grade', $modulecontext)) {
    redirect($CFG->wwwroot . '/mod/qcreate/edit.php?cmid=' . $cm->id);
}
/// Print the page header
$strqcreates = get_string("modulenameplural", "qcreate");
$strqcreate = get_string("modulename", "qcreate");
$navlinks = array();
$navlinks[] = array('name' => $strqcreates, 'link' => "index.php?id={$course->id}", 'type' => 'activity');
$navlinks[] = array('name' => format_string($qcreate->name), 'link' => '', 'type' => 'activityinstance');
$navigation = build_navigation($navlinks);
$headerargs = array(format_string($qcreate->name), "", $navigation, "", "", true, update_module_button($cm->id, $course->id, $strqcreate), navmenu($course, $cm));
if (!($cats = get_categories_for_contexts($modulecontext->id))) {
    //if it has not been made yet then make a default cat
    question_make_default_categories(array($modulecontext));
    $cats = get_categories_for_contexts($modulecontext->id);
}
$catsinctx = array();
foreach ($cats as $catinctx) {
    $catsinctx[] = $catinctx->id;
}
$catsinctxlist = join($catsinctx, ',');
$cat = array_shift($cats);
if ($delete && question_require_capability_on($delete, 'edit')) {
    if ($confirm && confirm_sesskey()) {
        if (!delete_records_select('question', "id = {$delete} AND category IN ({$catsinctxlist})")) {
            print_error('question_not_found');
        } else {
            qcreate_update_grades($qcreate, $USER->id);
            redirect($CFG->wwwroot . '/mod/qcreate/view.php?id=' . $cm->id);
开发者ID:hmatulis,项目名称:RTL-BIDI-Hebrew-Moodle-Plugins,代码行数:31,代码来源:view.php

示例9: question_edit_setup

/**
 * Common setup for all pages for editing questions.
 * @param string $baseurl the name of the script calling this funciton. For examle 'qusetion/edit.php'.
 * @param string $edittab code for this edit tab
 * @param bool $requirecmid require cmid? default false
 * @param bool $requirecourseid require courseid, if cmid is not given? default true
 * @return array $thispageurl, $contexts, $cmid, $cm, $module, $pagevars
 */
function question_edit_setup($edittab, $baseurl, $requirecmid = false, $requirecourseid = true)
{
    global $DB, $PAGE;
    $thispageurl = new moodle_url($baseurl);
    $thispageurl->remove_all_params();
    // We are going to explicity add back everything important - this avoids unwanted params from being retained.
    if ($requirecmid) {
        $cmid = required_param('cmid', PARAM_INT);
    } else {
        $cmid = optional_param('cmid', 0, PARAM_INT);
    }
    if ($cmid) {
        list($module, $cm) = get_module_from_cmid($cmid);
        $courseid = $cm->course;
        $thispageurl->params(compact('cmid'));
        require_login($courseid, false, $cm);
        $thiscontext = context_module::instance($cmid);
    } else {
        $module = null;
        $cm = null;
        if ($requirecourseid) {
            $courseid = required_param('courseid', PARAM_INT);
        } else {
            $courseid = optional_param('courseid', 0, PARAM_INT);
        }
        if ($courseid) {
            $thispageurl->params(compact('courseid'));
            require_login($courseid, false);
            $thiscontext = context_course::instance($courseid);
        } else {
            $thiscontext = null;
        }
    }
    if ($thiscontext) {
        $contexts = new question_edit_contexts($thiscontext);
        $contexts->require_one_edit_tab_cap($edittab);
    } else {
        $contexts = null;
    }
    $PAGE->set_pagelayout('admin');
    $pagevars['qpage'] = optional_param('qpage', -1, PARAM_INT);
    //pass 'cat' from page to page and when 'category' comes from a drop down menu
    //then we also reset the qpage so we go to page 1 of
    //a new cat.
    $pagevars['cat'] = optional_param('cat', 0, PARAM_SEQUENCE);
    // if empty will be set up later
    if ($category = optional_param('category', 0, PARAM_SEQUENCE)) {
        if ($pagevars['cat'] != $category) {
            // is this a move to a new category?
            $pagevars['cat'] = $category;
            $pagevars['qpage'] = 0;
        }
    }
    if ($pagevars['cat']) {
        $thispageurl->param('cat', $pagevars['cat']);
    }
    if (strpos($baseurl, '/question/') === 0) {
        navigation_node::override_active_url($thispageurl);
    }
    if ($pagevars['qpage'] > -1) {
        $thispageurl->param('qpage', $pagevars['qpage']);
    } else {
        $pagevars['qpage'] = 0;
    }
    $pagevars['qperpage'] = question_get_display_preference('qperpage', DEFAULT_QUESTIONS_PER_PAGE, PARAM_INT, $thispageurl);
    for ($i = 1; $i <= question_bank_view::MAX_SORTS; $i++) {
        $param = 'qbs' . $i;
        if (!($sort = optional_param($param, '', PARAM_TEXT))) {
            break;
        }
        $thispageurl->param($param, $sort);
    }
    $defaultcategory = question_make_default_categories($contexts->all());
    $contextlistarr = array();
    foreach ($contexts->having_one_edit_tab_cap($edittab) as $context) {
        $contextlistarr[] = "'{$context->id}'";
    }
    $contextlist = join($contextlistarr, ' ,');
    if (!empty($pagevars['cat'])) {
        $catparts = explode(',', $pagevars['cat']);
        if (!$catparts[0] || false !== array_search($catparts[1], $contextlistarr) || !$DB->count_records_select("question_categories", "id = ? AND contextid = ?", array($catparts[0], $catparts[1]))) {
            print_error('invalidcategory', 'question');
        }
    } else {
        $category = $defaultcategory;
        $pagevars['cat'] = "{$category->id},{$category->contextid}";
    }
    // Display options.
    $pagevars['recurse'] = question_get_display_preference('recurse', 1, PARAM_BOOL, $thispageurl);
    $pagevars['showhidden'] = question_get_display_preference('showhidden', 0, PARAM_BOOL, $thispageurl);
    $pagevars['qbshowtext'] = question_get_display_preference('qbshowtext', 0, PARAM_BOOL, $thispageurl);
    // Category list page.
//.........这里部分代码省略.........
开发者ID:janaece,项目名称:globalclassroom4_clean,代码行数:101,代码来源:editlib.php

示例10: make_default_question_category

 /**
  * Questions need to have a category. WE just make one.
  */
 public function make_default_question_category($courseid)
 {
     $context = context_course::instance_by_id($courseid);
     $defaultcategory = question_make_default_categories(array($context));
     return $defaultcategory->id;
 }
开发者ID:nadavkav,项目名称:moodle-block_ajax_marking,代码行数:9,代码来源:block_ajax_marking_mod_quiz_generator.class.php

示例11: get_default_category

 protected function get_default_category($cid)
 {
     $context = context_course::instance($cid);
     $result = question_get_default_category($context->id);
     $result = $result ? $result : question_make_default_categories(array($context));
     return $result;
 }
开发者ID:jmvedrine,项目名称:moodle-qformat_imsqti21,代码行数:7,代码来源:qti_import.class.php

示例12: question_edit_setup

/**
 * Common setup for all pages for editing questions.
 * @param string $baseurl the name of the script calling this funciton. For examle 'qusetion/edit.php'.
 * @param string $edittab code for this edit tab
 * @param bool $requirecmid require cmid? default false
 * @param bool $requirecourseid require courseid, if cmid is not given? default true
 * @return array $thispageurl, $contexts, $cmid, $cm, $module, $pagevars
 */
function question_edit_setup($edittab, $baseurl, $requirecmid = false, $requirecourseid = true)
{
    global $DB, $PAGE;
    $thispageurl = new moodle_url($baseurl);
    $thispageurl->remove_all_params();
    // We are going to explicity add back everything important - this avoids unwanted params from being retained.
    if ($requirecmid) {
        $cmid = required_param('cmid', PARAM_INT);
    } else {
        $cmid = optional_param('cmid', 0, PARAM_INT);
    }
    if ($cmid) {
        list($module, $cm) = get_module_from_cmid($cmid);
        $courseid = $cm->course;
        $thispageurl->params(compact('cmid'));
        require_login($courseid, false, $cm);
        $thiscontext = get_context_instance(CONTEXT_MODULE, $cmid);
    } else {
        $module = null;
        $cm = null;
        if ($requirecourseid) {
            $courseid = required_param('courseid', PARAM_INT);
        } else {
            $courseid = optional_param('courseid', 0, PARAM_INT);
        }
        if ($courseid) {
            $thispageurl->params(compact('courseid'));
            require_login($courseid, false);
            $thiscontext = get_context_instance(CONTEXT_COURSE, $courseid);
        } else {
            $thiscontext = null;
        }
    }
    if ($thiscontext) {
        $contexts = new question_edit_contexts($thiscontext);
        $contexts->require_one_edit_tab_cap($edittab);
    } else {
        $contexts = null;
    }
    $PAGE->set_pagelayout('admin');
    $pagevars['qpage'] = optional_param('qpage', -1, PARAM_INT);
    //pass 'cat' from page to page and when 'category' comes from a drop down menu
    //then we also reset the qpage so we go to page 1 of
    //a new cat.
    $pagevars['cat'] = optional_param('cat', 0, PARAM_SEQUENCE);
    // if empty will be set up later
    if ($category = optional_param('category', 0, PARAM_SEQUENCE)) {
        if ($pagevars['cat'] != $category) {
            // is this a move to a new category?
            $pagevars['cat'] = $category;
            $pagevars['qpage'] = 0;
        }
    }
    if ($pagevars['cat']) {
        $thispageurl->param('cat', $pagevars['cat']);
    }
    if (strpos($baseurl, '/question/') === 0) {
        navigation_node::override_active_url($thispageurl);
    }
    if ($pagevars['qpage'] > -1) {
        $thispageurl->param('qpage', $pagevars['qpage']);
    } else {
        $pagevars['qpage'] = 0;
    }
    $pagevars['qperpage'] = optional_param('qperpage', -1, PARAM_INT);
    if ($pagevars['qperpage'] > -1) {
        $thispageurl->param('qperpage', $pagevars['qperpage']);
    } else {
        $pagevars['qperpage'] = DEFAULT_QUESTIONS_PER_PAGE;
    }
    $sortoptions = array('alpha' => 'name, qtype ASC', 'typealpha' => 'qtype, name ASC', 'age' => 'id ASC');
    if ($sortorder = optional_param('qsortorder', '', PARAM_ALPHA)) {
        $pagevars['qsortorderdecoded'] = $sortoptions[$sortorder];
        $pagevars['qsortorder'] = $sortorder;
        $thispageurl->param('qsortorder', $sortorder);
    } else {
        $pagevars['qsortorderdecoded'] = $sortoptions['typealpha'];
        $pagevars['qsortorder'] = 'typealpha';
    }
    $defaultcategory = question_make_default_categories($contexts->all());
    $contextlistarr = array();
    foreach ($contexts->having_one_edit_tab_cap($edittab) as $context) {
        $contextlistarr[] = "'{$context->id}'";
    }
    $contextlist = join($contextlistarr, ' ,');
    if (!empty($pagevars['cat'])) {
        $catparts = explode(',', $pagevars['cat']);
        if (!$catparts[0] || false !== array_search($catparts[1], $contextlistarr) || !$DB->count_records_select("question_categories", "id = ? AND contextid = ?", array($catparts[0], $catparts[1]))) {
            print_error('invalidcategory', 'question');
        }
    } else {
        $category = $defaultcategory;
//.........这里部分代码省略.........
开发者ID:sebastiansanio,项目名称:tallerdeprogramacion2fiuba,代码行数:101,代码来源:editlib.php

示例13: test_version1importdeletecoursedeletesassociations


//.........这里部分代码省略.........
     $completion->timemodified = time();
     $DB->insert_record('course_modules_completion', $completion);
     // Set up a completion condition.
     $forum->id = $cmid;
     $ci = new condition_info($forum, CONDITION_MISSING_EVERYTHING, false);
     $ci->add_completion_condition($cmid, COMPLETION_ENABLED);
     // Set the blocks position.
     $instances = $DB->get_records('block_instances', array('parentcontextid' => $coursecontext->id));
     $page = new stdClass();
     $page->context = $coursecontext;
     $page->pagetype = 'course-view-*';
     $page->subpage = false;
     foreach ($instances as $instance) {
         blocks_set_visibility($instance, $page, 1);
     }
     // Create a group.
     $group = new stdClass();
     $group->name = 'testgroup';
     $group->courseid = $courseid;
     $groupid = groups_create_group($group);
     // Add the user to the group.
     groups_add_member($groupid, $userid);
     // Create a grouping containing our group.
     $grouping = new stdClass();
     $grouping->name = 'testgrouping';
     $grouping->courseid = $courseid;
     $groupingid = groups_create_grouping($grouping);
     groups_assign_grouping($groupingid, $groupid);
     // Set up a user tag.
     tag_set('course', $courseid, array('testtag'));
     // Add a course-level log.
     add_to_log($courseid, 'bogus', 'bogus');
     // Set up the default course question category.
     $newcategory = question_make_default_categories(array($coursecontext));
     // Create a test question.
     $question = new stdClass();
     $question->qtype = 'truefalse';
     $form = new stdClass();
     $form->category = $newcategory->id;
     $form->name = 'testquestion';
     $form->correctanswer = 1;
     $form->feedbacktrue = array('text' => 'bogustext', 'format' => FORMAT_HTML);
     $form->feedbackfalse = array('text' => 'bogustext', 'format' => FORMAT_HTML);
     $question = question_bank::get_qtype('truefalse')->save_question($question, $form);
     if (function_exists('course_set_display')) {
         // Set a "course display" setting.
         course_set_display($courseid, 1);
     }
     // Make a bogus backup record.
     $backupcourse = new stdClass();
     $backupcourse->courseid = $courseid;
     $DB->insert_record('backup_courses', $backupcourse);
     // Add a user lastaccess record.
     $lastaccess = new stdClass();
     $lastaccess->userid = $userid;
     $lastaccess->courseid = $courseid;
     $DB->insert_record('user_lastaccess', $lastaccess);
     // Make a bogus backup log record.
     $log = new stdClass();
     $log->backupid = $courseid;
     $log->timecreated = time();
     $log->loglevel = 1;
     $log->message = 'bogus';
     $DB->insert_record('backup_logs', $log);
     // Get initial counts.
     $initialnumcourse = $DB->count_records('course');
开发者ID:jamesmcq,项目名称:elis,代码行数:67,代码来源:version1_course_import_test.php


注:本文中的question_make_default_categories函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。