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


PHP question_engine类代码示例

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


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

示例1: test_core_question_update_flag

 /**
  * Test update question flag
  */
 public function test_core_question_update_flag()
 {
     $questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question');
     // Create a question category.
     $cat = $questiongenerator->create_question_category();
     $quba = question_engine::make_questions_usage_by_activity('core_question_update_flag', context_system::instance());
     $quba->set_preferred_behaviour('deferredfeedback');
     $questiondata = $questiongenerator->create_question('numerical', null, array('category' => $cat->id));
     $question = question_bank::load_question($questiondata->id);
     $slot = $quba->add_question($question);
     $qa = $quba->get_question_attempt($slot);
     self::setUser($this->student);
     $quba->start_all_questions();
     question_engine::save_questions_usage_by_activity($quba);
     $qubaid = $quba->get_id();
     $questionid = $question->id;
     $qaid = $qa->get_database_id();
     $checksum = md5($qubaid . "_" . $this->student->secret . "_" . $questionid . "_" . $qaid . "_" . $slot);
     $flag = core_question_external::update_flag($qubaid, $questionid, $qaid, $slot, $checksum, true);
     $this->assertTrue($flag['status']);
     // Test invalid checksum.
     try {
         // Using random_string to force failing.
         $checksum = md5($qubaid . "_" . random_string(11) . "_" . $questionid . "_" . $qaid . "_" . $slot);
         core_question_external::update_flag($qubaid, $questionid, $qaid, $slot, $checksum, true);
         $this->fail('Exception expected due to invalid checksum.');
     } catch (moodle_exception $e) {
         $this->assertEquals('errorsavingflags', $e->errorcode);
     }
 }
开发者ID:evltuma,项目名称:moodle,代码行数:33,代码来源:externallib_test.php

示例2: prepare_quiz_data

 protected function prepare_quiz_data()
 {
     $this->resetAfterTest(true);
     // Create a course
     $course = $this->getDataGenerator()->create_course();
     // Make a quiz.
     $quizgenerator = $this->getDataGenerator()->get_plugin_generator('mod_quiz');
     $quiz = $quizgenerator->create_instance(array('course' => $course->id, 'questionsperpage' => 0, 'grade' => 100.0, 'sumgrades' => 2));
     $cm = get_coursemodule_from_instance('quiz', $quiz->id, $course->id);
     // Create a couple of questions.
     $questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question');
     $cat = $questiongenerator->create_question_category();
     $saq = $questiongenerator->create_question('shortanswer', null, array('category' => $cat->id));
     $numq = $questiongenerator->create_question('numerical', null, array('category' => $cat->id));
     // Add them to the quiz.
     quiz_add_quiz_question($saq->id, $quiz);
     quiz_add_quiz_question($numq->id, $quiz);
     // Make a user to do the quiz.
     $user1 = $this->getDataGenerator()->create_user();
     $this->setUser($user1);
     $quizobj = quiz::create($quiz->id, $user1->id);
     // Start the attempt.
     $quba = question_engine::make_questions_usage_by_activity('mod_quiz', $quizobj->get_context());
     $quba->set_preferred_behaviour($quizobj->get_quiz()->preferredbehaviour);
     $timenow = time();
     $attempt = quiz_create_attempt($quizobj, 1, false, $timenow);
     quiz_start_new_attempt($quizobj, $quba, $attempt, 1, $timenow);
     quiz_attempt_save_started($quizobj, $quba, $attempt);
     return array($quizobj, $quba, $attempt);
 }
开发者ID:EmmanuelYupit,项目名称:educursos,代码行数:30,代码来源:events_test.php

示例3: definition

 public function definition()
 {
     $mform = $this->_form;
     $hiddenofvisible = array(question_display_options::HIDDEN => get_string('notshown', 'question'), question_display_options::VISIBLE => get_string('shown', 'question'));
     $mform->addElement('header', 'optionsheader', get_string('changeoptions', 'question'));
     $behaviours = question_engine::get_behaviour_options($this->_customdata['quba']->get_preferred_behaviour());
     $mform->addElement('select', 'behaviour', get_string('howquestionsbehave', 'question'), $behaviours);
     $mform->addHelpButton('behaviour', 'howquestionsbehave', 'question');
     $mform->addElement('text', 'maxmark', get_string('markedoutof', 'question'), array('size' => '5'));
     $mform->setType('maxmark', PARAM_NUMBER);
     if ($this->_customdata['maxvariant'] > 1) {
         $variants = range(1, $this->_customdata['maxvariant']);
         $mform->addElement('select', 'variant', get_string('questionvariant', 'question'), array_combine($variants, $variants));
     }
     $mform->setType('maxmark', PARAM_INT);
     $mform->addElement('select', 'correctness', get_string('whethercorrect', 'question'), $hiddenofvisible);
     $marksoptions = array(question_display_options::HIDDEN => get_string('notshown', 'question'), question_display_options::MAX_ONLY => get_string('showmaxmarkonly', 'question'), question_display_options::MARK_AND_MAX => get_string('showmarkandmax', 'question'));
     $mform->addElement('select', 'marks', get_string('marks', 'question'), $marksoptions);
     $mform->addElement('select', 'markdp', get_string('decimalplacesingrades', 'question'), question_engine::get_dp_options());
     $mform->addElement('select', 'feedback', get_string('specificfeedback', 'question'), $hiddenofvisible);
     $mform->addElement('select', 'generalfeedback', get_string('generalfeedback', 'question'), $hiddenofvisible);
     $mform->addElement('select', 'rightanswer', get_string('rightanswer', 'question'), $hiddenofvisible);
     $mform->addElement('select', 'history', get_string('responsehistory', 'question'), $hiddenofvisible);
     $mform->addElement('submit', 'submit', get_string('restartwiththeseoptions', 'question'), $hiddenofvisible);
 }
开发者ID:sebastiansanio,项目名称:tallerdeprogramacion2fiuba,代码行数:25,代码来源:previewlib.php

示例4: is_compatible_behaviour

 /**
  * Given the quiz "How questions behave" setting, can the fault-tolerant mode work
  * with that behaviour?
  * @param string $behaviour the internal name (e.g. 'interactive') of an archetypal behaviour.
  * @return boolean whether fault-tolerant mode can be used.
  */
 public static function is_compatible_behaviour($behaviour)
 {
     $unusedoptions = question_engine::get_behaviour_unused_display_options($behaviour);
     // Sorry, double negative here. The heuristic is that:
     // The behaviour is compatible if we don't need to show specific feedback during the attempt.
     return in_array('specificfeedback', $unusedoptions);
 }
开发者ID:gurujiathome,项目名称:moodle-quizaccess_offlinemode,代码行数:13,代码来源:rule.php

示例5: xmldb_qbehaviour_manualgraded_upgrade

/**
 * Manual graded question behaviour upgrade code.
 */
function xmldb_qbehaviour_manualgraded_upgrade($oldversion)
{
    global $CFG, $DB;
    $dbman = $DB->get_manager();
    // Moodle v2.4.0 release upgrade line
    // Put any upgrade step following this
    if ($oldversion < 2013050200) {
        // Hide the manualgraded behaviour from the list of behaviours that users
        // can select in the user-interface. If a user accidentally chooses manual
        // graded behaviour for a quiz, there is no way to get the questions automatically
        // graded after the student has answered them. If teachers really want to do
        // this they can ask their admin to enable it on the manage behaviours
        // screen in the UI.
        $disabledbehaviours = get_config('question', 'disabledbehaviours');
        if (!empty($disabledbehaviours)) {
            $disabledbehaviours = explode(',', $disabledbehaviours);
        } else {
            $disabledbehaviours = array();
        }
        if (array_search('manualgraded', $disabledbehaviours) === false) {
            $disabledbehaviours[] = 'manualgraded';
            set_config('disabledbehaviours', implode(',', $disabledbehaviours), 'question');
        }
        // Manual graded question behaviour savepoint reached.
        upgrade_plugin_savepoint(true, 2013050200, 'qbehaviour', 'manualgraded');
    }
    if ($oldversion < 2013050800) {
        // Also, fix any other admin settings that currently select manualgraded behaviour.
        // Work out a sensible default alternative to manualgraded.
        require_once $CFG->libdir . '/questionlib.php';
        $behaviours = question_engine::get_behaviour_options('');
        if (array_key_exists('deferredfeedback', $behaviours)) {
            $defaultbehaviour = 'deferredfeedback';
        } else {
            reset($behaviours);
            $defaultbehaviour = key($behaviours);
        }
        // Fix the question preview default.
        if (get_config('question_preview', 'behaviour') == 'manualgraded') {
            set_config('behaviour', $defaultbehaviour, 'question_preview');
        }
        // Fix the quiz settings default.
        if (get_config('quiz', 'preferredbehaviour') == 'manualgraded') {
            set_config('preferredbehaviour', $defaultbehaviour, 'quiz');
        }
        // Manual graded question behaviour savepoint reached.
        upgrade_plugin_savepoint(true, 2013050800, 'qbehaviour', 'manualgraded');
    }
    // Moodle v2.5.0 release upgrade line.
    // Put any upgrade step following this.
    // Moodle v2.6.0 release upgrade line.
    // Put any upgrade step following this.
    // Moodle v2.7.0 release upgrade line.
    // Put any upgrade step following this.
    // Moodle v2.8.0 release upgrade line.
    // Put any upgrade step following this.
    // Moodle v2.9.0 release upgrade line.
    // Put any upgrade step following this.
    return true;
}
开发者ID:nadavkav,项目名称:moodle-accessibility,代码行数:63,代码来源:upgrade.php

示例6: __construct

 /**
  * Constructor.
  * @param question_usage_by_activity $quba the question usage we will be picking variants for.
  * @param qubaid_condition $qubaids ids of the usages to consider when counting previous uses of each variant.
  */
 public function __construct(\question_usage_by_activity $quba, \qubaid_condition $qubaids)
 {
     $questionidtoseed = array();
     foreach ($quba->get_attempt_iterator() as $qa) {
         $question = $qa->get_question();
         if ($question->get_num_variants() > 1) {
             $questionidtoseed[$question->id] = $question->get_variants_selection_seed();
         }
     }
     if (empty($questionidtoseed)) {
         return;
     }
     $this->variantsusecounts = array_fill_keys($questionidtoseed, array());
     $variantsused = \question_engine::load_used_variants(array_keys($questionidtoseed), $qubaids);
     foreach ($variantsused as $questionid => $usagecounts) {
         $seed = $questionidtoseed[$questionid];
         foreach ($usagecounts as $variant => $count) {
             if (isset($this->variantsusecounts[$seed][$variant])) {
                 $this->variantsusecounts[$seed][$variant] += $count;
             } else {
                 $this->variantsusecounts[$seed][$variant] = $count;
             }
         }
     }
 }
开发者ID:evltuma,项目名称:moodle,代码行数:30,代码来源:least_used_strategy.php

示例7: setUp

 public function setUp()
 {
     $this->quba = question_engine::make_questions_usage_by_activity('unit_test', get_context_instance(CONTEXT_SYSTEM));
     $this->quba->set_preferred_behaviour('deferredfeedback');
     $slot = $this->quba->add_question(test_question_maker::make_a_description_question());
     $this->qas[$slot] = $this->quba->get_question_attempt($slot);
     $slot = $this->quba->add_question(test_question_maker::make_a_description_question());
     $this->qas[$slot] = $this->quba->get_question_attempt($slot);
     $this->iterator = $this->quba->get_attempt_iterator();
 }
开发者ID:sebastiansanio,项目名称:tallerdeprogramacion2fiuba,代码行数:10,代码来源:testquestionattemptiterator.php

示例8: setUp

 protected function setUp()
 {
     $this->quba = question_engine::make_questions_usage_by_activity('unit_test', context_system::instance());
     $this->quba->set_preferred_behaviour('deferredfeedback');
     $slot = $this->quba->add_question(test_question_maker::make_question('description'));
     $this->qas[$slot] = $this->quba->get_question_attempt($slot);
     $slot = $this->quba->add_question(test_question_maker::make_question('description'));
     $this->qas[$slot] = $this->quba->get_question_attempt($slot);
     $this->iterator = $this->quba->get_attempt_iterator();
 }
开发者ID:alanaipe2015,项目名称:moodle,代码行数:10,代码来源:questionattemptiterator_test.php

示例9: test_reporting_queries

 /**
  * Test the various methods that load data for reporting.
  *
  * Since these methods need an expensive set-up, and then only do read-only
  * operations on the data, we use a single method to do the set-up, which
  * calls diffents methods to test each query.
  */
 public function test_reporting_queries()
 {
     // We create two usages, each with two questions, a short-answer marked
     // out of 5, and and essay marked out of 10.
     //
     // In the first usage, the student answers the short-answer
     // question correctly, and enters something in the essay.
     //
     // In the second useage, the student answers the short-answer question
     // wrongly, and leaves the essay blank.
     $this->resetAfterTest();
     $generator = $this->getDataGenerator()->get_plugin_generator('core_question');
     $cat = $generator->create_question_category();
     $this->sa = $generator->create_question('shortanswer', null, array('category' => $cat->id));
     $this->essay = $generator->create_question('essay', null, array('category' => $cat->id));
     $this->usageids = array();
     // Create the first usage.
     $q = question_bank::load_question($this->sa->id);
     $this->start_attempt_at_question($q, 'interactive', 5);
     $this->allslots[] = $this->slot;
     $this->process_submission(array('answer' => 'cat'));
     $this->process_submission(array('answer' => 'frog', '-submit' => 1));
     $q = question_bank::load_question($this->essay->id);
     $this->start_attempt_at_question($q, 'interactive', 10);
     $this->allslots[] = $this->slot;
     $this->process_submission(array('answer' => '<p>The cat sat on the mat.</p>', 'answerformat' => FORMAT_HTML));
     $this->finish();
     $this->save_quba();
     $this->usageids[] = $this->quba->get_id();
     // Create the second usage.
     $this->quba = question_engine::make_questions_usage_by_activity('unit_test', context_system::instance());
     $q = question_bank::load_question($this->sa->id);
     $this->start_attempt_at_question($q, 'interactive', 5);
     $this->process_submission(array('answer' => 'fish'));
     $q = question_bank::load_question($this->essay->id);
     $this->start_attempt_at_question($q, 'interactive', 10);
     $this->finish();
     $this->save_quba();
     $this->usageids[] = $this->quba->get_id();
     // Set up some things the tests will need.
     $this->dm = new question_engine_data_mapper();
     $this->bothusages = new qubaid_list($this->usageids);
     // Now test the various queries.
     $this->dotest_load_questions_usages_latest_steps();
     $this->dotest_load_questions_usages_question_state_summary();
     $this->dotest_load_questions_usages_where_question_in_state();
     $this->dotest_load_average_marks();
     $this->dotest_sum_usage_marks_subquery();
     $this->dotest_question_attempt_latest_state_view();
 }
开发者ID:gabrielrosset,项目名称:moodle,代码行数:57,代码来源:datalib_reporting_queries_test.php

示例10: test_sort_behaviours

 public function test_sort_behaviours()
 {
     $in = array('b1' => 'Behave 1', 'b2' => 'Behave 2', 'b3' => 'Behave 3', 'b4' => 'Behave 4', 'b5' => 'Behave 5', 'b6' => 'Behave 6');
     $out = array('b1' => 'Behave 1', 'b2' => 'Behave 2', 'b3' => 'Behave 3', 'b4' => 'Behave 4', 'b5' => 'Behave 5', 'b6' => 'Behave 6');
     $this->assertIdentical($out, question_engine::sort_behaviours($in, '', '', ''));
     $this->assertIdentical($out, question_engine::sort_behaviours($in, '', 'b4', 'b4'));
     $out = array('b4' => 'Behave 4', 'b5' => 'Behave 5', 'b6' => 'Behave 6');
     $this->assertIdentical($out, question_engine::sort_behaviours($in, '', 'b1,b2,b3,b4', 'b4'));
     $out = array('b6' => 'Behave 6', 'b1' => 'Behave 1', 'b4' => 'Behave 4');
     $this->assertIdentical($out, question_engine::sort_behaviours($in, 'b6,b1,b4', 'b2,b3,b4,b5', 'b4'));
     $out = array('b6' => 'Behave 6', 'b5' => 'Behave 5', 'b4' => 'Behave 4');
     $this->assertIdentical($out, question_engine::sort_behaviours($in, 'b6,b5,b4', 'b1,b2,b3', 'b4'));
     $out = array('b6' => 'Behave 6', 'b5' => 'Behave 5', 'b4' => 'Behave 4');
     $this->assertIdentical($out, question_engine::sort_behaviours($in, 'b1,b6,b5', 'b1,b2,b3,b4', 'b4'));
     $out = array('b2' => 'Behave 2', 'b4' => 'Behave 4', 'b6' => 'Behave 6');
     $this->assertIdentical($out, question_engine::sort_behaviours($in, 'b2,b4,b6', 'b1,b3,b5', 'b2'));
     // Ignore unknown input in the order argument.
     $this->assertIdentical($in, question_engine::sort_behaviours($in, 'unknown', '', ''));
     // Ignore unknown input in the disabled argument.
     $this->assertIdentical($in, question_engine::sort_behaviours($in, '', 'unknown', ''));
 }
开发者ID:sebastiansanio,项目名称:tallerdeprogramacion2fiuba,代码行数:21,代码来源:testquestionengine.php

示例11: foreach

    $archetypal[$behaviour] = question_engine::is_behaviour_archetypal($behaviour);
}
foreach ($counts as $behaviour => $count) {
    if (!array_key_exists($behaviour, $behaviours)) {
        $counts['missing'] += $count;
    }
}
$needed['missing'] = true;
// Work of the correct sort order.
$config = get_config('question');
$sortedbehaviours = array();
foreach ($behaviours as $behaviour => $notused) {
    $sortedbehaviours[$behaviour] = question_engine::get_behaviour_name($behaviour);
}
if (!empty($config->behavioursortorder)) {
    $sortedbehaviours = question_engine::sort_behaviours($sortedbehaviours, $config->behavioursortorder, '');
}
if (!empty($config->disabledbehaviours)) {
    $disabledbehaviours = explode(',', $config->disabledbehaviours);
} else {
    $disabledbehaviours = array();
}
// Process actions ============================================================
// Disable.
if (($disable = optional_param('disable', '', PARAM_PLUGIN)) && confirm_sesskey()) {
    if (!isset($behaviours[$disable])) {
        print_error('unknownbehaviour', 'question', $thispageurl, $disable);
    }
    if (array_search($disable, $disabledbehaviours) === false) {
        $disabledbehaviours[] = $disable;
        set_config('disabledbehaviours', implode(',', $disabledbehaviours), 'question');
开发者ID:Jtgadbois,项目名称:Pedadida,代码行数:31,代码来源:qbehaviours.php

示例12: after_execute

 protected function after_execute()
 {
     parent::after_execute();
     // Restore any files belonging to responses.
     foreach (question_engine::get_all_response_file_areas() as $filearea) {
         $this->add_related_files('question', $filearea, 'question_attempt_step');
     }
 }
开发者ID:Jinelle,项目名称:moodle,代码行数:8,代码来源:restore_stepslib.php

示例13: search

 /**
  * Search question behaviours for the specified string
  *
  * @param string $query The string to search for in question behaviours
  * @return array
  */
 public function search($query)
 {
     global $CFG;
     if ($result = parent::search($query)) {
         return $result;
     }
     $found = false;
     $textlib = textlib_get_instance();
     require_once $CFG->dirroot . '/question/engine/lib.php';
     foreach (get_plugin_list('qbehaviour') as $behaviour => $notused) {
         if (strpos($textlib->strtolower(question_engine::get_behaviour_name($behaviour)), $query) !== false) {
             $found = true;
             break;
         }
     }
     if ($found) {
         $result = new stdClass();
         $result->page = $this;
         $result->settings = array();
         return array($this->name => $result);
     } else {
         return array();
     }
 }
开发者ID:raymondAntonio,项目名称:moodle,代码行数:30,代码来源:adminlib.php

示例14: add_question_usages

 /**
  * Attach to $element (usually attempts) the needed backup structures
  * for question_usages and all the associated data.
  */
 protected function add_question_usages($element, $usageidname)
 {
     global $CFG;
     require_once $CFG->dirroot . '/question/engine/lib.php';
     // Check $element is one nested_backup_element
     if (!$element instanceof backup_nested_element) {
         throw new backup_step_exception('question_states_bad_parent_element', $element);
     }
     if (!$element->get_final_element($usageidname)) {
         throw new backup_step_exception('question_states_bad_question_attempt_element', $usageidname);
     }
     $quba = new backup_nested_element('question_usage', array('id'), array('component', 'preferredbehaviour'));
     $qas = new backup_nested_element('question_attempts');
     $qa = new backup_nested_element('question_attempt', array('id'), array('slot', 'behaviour', 'questionid', 'maxmark', 'minfraction', 'flagged', 'questionsummary', 'rightanswer', 'responsesummary', 'timemodified'));
     $steps = new backup_nested_element('steps');
     $step = new backup_nested_element('step', array('id'), array('sequencenumber', 'state', 'fraction', 'timecreated', 'userid'));
     $response = new backup_nested_element('response');
     $variable = new backup_nested_element('variable', null, array('name', 'value'));
     // Build the tree
     $element->add_child($quba);
     $quba->add_child($qas);
     $qas->add_child($qa);
     $qa->add_child($steps);
     $steps->add_child($step);
     $step->add_child($response);
     $response->add_child($variable);
     // Set the sources
     $quba->set_source_table('question_usages', array('id' => '../' . $usageidname));
     $qa->set_source_sql('
             SELECT *
             FROM {question_attempts}
             WHERE questionusageid = :questionusageid
             ORDER BY slot', array('questionusageid' => backup::VAR_PARENTID));
     $step->set_source_sql('
             SELECT *
             FROM {question_attempt_steps}
             WHERE questionattemptid = :questionattemptid
             ORDER BY sequencenumber', array('questionattemptid' => backup::VAR_PARENTID));
     $variable->set_source_table('question_attempt_step_data', array('attemptstepid' => backup::VAR_PARENTID));
     // Annotate ids
     $qa->annotate_ids('question', 'questionid');
     $step->annotate_ids('user', 'userid');
     // Annotate files
     $fileareas = question_engine::get_all_response_file_areas();
     foreach ($fileareas as $filearea) {
         $step->annotate_files('question', $filearea, 'id');
     }
 }
开发者ID:nutanrajmalanai,项目名称:moodle,代码行数:52,代码来源:backup_stepslib.php

示例15: test_access_out_of_sequence_throws_exception

    public function test_access_out_of_sequence_throws_exception() {
        // Start a deferred feedback attempt with CBM and add the question to it.
        $tf = test_question_maker::make_question('truefalse', 'true');
        $quba = question_engine::make_questions_usage_by_activity('unit_test',
                context_system::instance());
        $quba->set_preferred_behaviour('deferredcbm');
        $slot = $quba->add_question($tf);
        $quba->start_all_questions();

        // Prepare data to be submitted
        $prefix = $quba->get_field_prefix($slot);
        $answername = $prefix . 'answer';
        $certaintyname = $prefix . '-certainty';
        $postdata = array(
            $answername => 1,
            $certaintyname => 3,
            $prefix . ':sequencecheck' => 1,
            'irrelevant' => 'should be ignored',
        );

        // Exercise SUT - no exception yet.
        $quba->process_all_actions($slot, $postdata);

        $postdata = array(
            $answername => 1,
            $certaintyname => 3,
            $prefix . ':sequencecheck' => 3,
            'irrelevant' => 'should be ignored',
        );

        // Exercise SUT - now it should fail.
        $this->setExpectedException('question_out_of_sequence_exception');
        $quba->process_all_actions($slot, $postdata);
    }
开发者ID:JP-Git,项目名称:moodle,代码行数:34,代码来源:questionusagebyactivity_test.php


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