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


PHP question_attempt::load_from_records方法代码示例

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


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

示例1: test_render_missing

 public function test_render_missing()
 {
     $records = new question_test_recordset(array(array('questionattemptid', 'contextid', 'questionusageid', 'slot', 'behaviour', 'questionid', 'variant', 'maxmark', 'minfraction', 'maxfraction', 'flagged', 'questionsummary', 'rightanswer', 'responsesummary', 'timemodified', 'attemptstepid', 'sequencenumber', 'state', 'fraction', 'timecreated', 'userid', 'name', 'value'), array(1, 123, 1, 1, 'strangeunknown', -1, 1, 2.0, 0.0, 1.0, 0, '', '', '', 1256233790, 1, 0, 'todo', null, 1256233700, 1, '_order', '1,2,3'), array(1, 123, 1, 1, 'strangeunknown', -1, 1, 2.0, 0.0, 1.0, 0, '', '', '', 1256233790, 2, 1, 'complete', 0.5, 1256233705, 1, '-submit', '1'), array(1, 123, 1, 1, 'strangeunknown', -1, 1, 2.0, 0.0, 1.0, 0, '', '', '', 1256233790, 2, 1, 'complete', 0.5, 1256233705, 1, 'choice0', '1')));
     $question = test_question_maker::make_question('truefalse', 'true');
     $question->id = -1;
     question_bank::start_unit_test();
     question_bank::load_test_question_data($question);
     $qa = question_attempt::load_from_records($records, 1, new question_usage_null_observer(), 'deferredfeedback');
     question_bank::end_unit_test();
     $this->assertEquals(2, $qa->get_num_steps());
     $step = $qa->get_step(0);
     $this->assertEquals(question_state::$todo, $step->get_state());
     $this->assertNull($step->get_fraction());
     $this->assertEquals(1256233700, $step->get_timecreated());
     $this->assertEquals(1, $step->get_user_id());
     $this->assertEquals(array('_order' => '1,2,3'), $step->get_all_data());
     $step = $qa->get_step(1);
     $this->assertEquals(question_state::$complete, $step->get_state());
     $this->assertEquals(0.5, $step->get_fraction());
     $this->assertEquals(1256233705, $step->get_timecreated());
     $this->assertEquals(1, $step->get_user_id());
     $this->assertEquals(array('-submit' => '1', 'choice0' => '1'), $step->get_all_data());
     $output = $qa->render(new question_display_options(), '1');
     $this->assertRegExp('/' . preg_quote($qa->get_question()->questiontext, '/') . '/', $output);
     $this->assertRegExp('/' . preg_quote(get_string('questionusedunknownmodel', 'qbehaviour_missing'), '/') . '/', $output);
     $this->assertTag(array('tag' => 'div', 'attributes' => array('class' => 'warning')), $output);
 }
开发者ID:evltuma,项目名称:moodle,代码行数:27,代码来源:missingbehaviour_test.php

示例2: test_load_with_unnecessary_autosaved_data

 public function test_load_with_unnecessary_autosaved_data()
 {
     // The point here is that the somehow (probably due to two things
     // happening concurrently, we have autosaved data in the database that
     // has already been superceded by real data, so it should be ignored.
     // There is also a second lot of redundant data to delete.
     $records = new question_test_recordset(array(array('questionattemptid', 'contextid', 'questionusageid', 'slot', 'behaviour', 'questionid', 'variant', 'maxmark', 'minfraction', 'maxfraction', 'flagged', 'questionsummary', 'rightanswer', 'responsesummary', 'timemodified', 'attemptstepid', 'sequencenumber', 'state', 'fraction', 'timecreated', 'userid', 'name', 'value'), array(1, 123, 1, 1, 'deferredfeedback', -1, 1, 2.0, 0.0, 1.0, 0, '', '', '', 1256233790, 5, -2, 'complete', null, 1256233715, 1, 'answer', '0'), array(1, 123, 1, 1, 'deferredfeedback', -1, 1, 2.0, 0.0, 1.0, 0, '', '', '', 1256233790, 4, -1, 'complete', null, 1256233715, 1, 'answer', '0'), array(1, 123, 1, 1, 'deferredfeedback', -1, 1, 2.0, 0.0, 1.0, 0, '', '', '', 1256233790, 1, 0, 'todo', null, 1256233700, 1, null, null), array(1, 123, 1, 1, 'deferredfeedback', -1, 1, 2.0, 0.0, 1.0, 0, '', '', '', 1256233790, 2, 1, 'complete', null, 1256233705, 1, 'answer', '1'), array(1, 123, 1, 1, 'deferredfeedback', -1, 1, 2.0, 0.0, 1.0, 1, '', '', '', 1256233790, 3, 2, 'complete', null, 1256233710, 1, 'answer', '0')));
     $question = test_question_maker::make_question('truefalse', 'true');
     $question->id = -1;
     question_bank::start_unit_test();
     question_bank::load_test_question_data($question);
     $observer = new testable_question_engine_unit_of_work(question_engine::make_questions_usage_by_activity('unit_test', context_system::instance()));
     $qa = question_attempt::load_from_records($records, 1, $observer, 'deferredfeedback');
     question_bank::end_unit_test();
     $this->assertEquals($question->questiontext, $qa->get_question()->questiontext);
     $this->assertEquals(3, $qa->get_num_steps());
     $this->assertFalse($qa->has_autosaved_step());
     $step = $qa->get_step(0);
     $this->assertEquals(question_state::$todo, $step->get_state());
     $this->assertNull($step->get_fraction());
     $this->assertEquals(1256233700, $step->get_timecreated());
     $this->assertEquals(1, $step->get_user_id());
     $this->assertEquals(array(), $step->get_all_data());
     $step = $qa->get_step(1);
     $this->assertEquals(question_state::$complete, $step->get_state());
     $this->assertNull($step->get_fraction());
     $this->assertEquals(1256233705, $step->get_timecreated());
     $this->assertEquals(1, $step->get_user_id());
     $this->assertEquals(array('answer' => '1'), $step->get_all_data());
     $step = $qa->get_step(2);
     $this->assertEquals(question_state::$complete, $step->get_state());
     $this->assertNull($step->get_fraction());
     $this->assertEquals(1256233710, $step->get_timecreated());
     $this->assertEquals(1, $step->get_user_id());
     $this->assertEquals(array('answer' => '0'), $step->get_all_data());
     $this->assertEquals(2, count($observer->get_steps_deleted()));
 }
开发者ID:gabrielrosset,项目名称:moodle,代码行数:37,代码来源:questionattempt_db_test.php

示例3: load_attempts_at_question

 /**
  * Load a {@link question_attempt} from the database, including all its
  * steps.
  * @param int $questionid the question to load all the attempts fors.
  * @param qubaid_condition $qubaids used to restrict which usages are included
  * in the query. See {@link qubaid_condition}.
  * @return array of question_attempts.
  */
 public function load_attempts_at_question($questionid, qubaid_condition $qubaids)
 {
     $params = $qubaids->from_where_params();
     $params['questionid'] = $questionid;
     $records = $this->db->get_recordset_sql("\nSELECT\n    quba.contextid,\n    quba.preferredbehaviour,\n    qa.id AS questionattemptid,\n    qa.questionusageid,\n    qa.slot,\n    qa.behaviour,\n    qa.questionid,\n    qa.variant,\n    qa.maxmark,\n    qa.minfraction,\n    qa.maxfraction,\n    qa.flagged,\n    qa.questionsummary,\n    qa.rightanswer,\n    qa.responsesummary,\n    qa.timemodified,\n    qas.id AS attemptstepid,\n    qas.sequencenumber,\n    qas.state,\n    qas.fraction,\n    qas.timecreated,\n    qas.userid,\n    qasd.name,\n    qasd.value\n\nFROM {$qubaids->from_question_attempts('qa')}\nJOIN {question_usages} quba ON quba.id = qa.questionusageid\nLEFT JOIN {question_attempt_steps} qas ON qas.questionattemptid = qa.id\nLEFT JOIN {question_attempt_step_data} qasd ON qasd.attemptstepid = qas.id\n\nWHERE\n    {$qubaids->where()} AND\n    qa.questionid = :questionid\n\nORDER BY\n    quba.id,\n    qa.id,\n    qas.sequencenumber\n        ", $params);
     $questionattempts = array();
     while ($records->valid()) {
         $record = $records->current();
         $questionattempts[$record->questionattemptid] = question_attempt::load_from_records($records, $record->questionattemptid, new question_usage_null_observer(), $record->preferredbehaviour);
     }
     $records->close();
     return $questionattempts;
 }
开发者ID:covex-nn,项目名称:moodle,代码行数:21,代码来源:datalib.php

示例4: load_from_records

    /**
     * Create a question_usage_by_activity from records loaded from the database.
     *
     * For internal use only.
     *
     * @param Iterator $records Raw records loaded from the database.
     * @param int $questionattemptid The id of the question_attempt to extract.
     * @return question_usage_by_activity The newly constructed usage.
     */
    public static function load_from_records($records, $qubaid) {
        $record = $records->current();
        while ($record->qubaid != $qubaid) {
            $records->next();
            if (!$records->valid()) {
                throw new coding_exception("Question usage $qubaid not found in the database.");
            }
            $record = $records->current();
        }

        $quba = new question_usage_by_activity($record->component,
            context::instance_by_id($record->contextid, IGNORE_MISSING));
        $quba->set_id_from_database($record->qubaid);
        $quba->set_preferred_behaviour($record->preferredbehaviour);

        $quba->observer = new question_engine_unit_of_work($quba);

        // If slot is null then the current pointer in $records will not be
        // advanced in the while loop below, and we get stuck in an infinite loop,
        // since this method is supposed to always consume at least one record.
        // Therefore, in this case, advance the record here.
        if (is_null($record->slot)) {
            $records->next();
        }

        while ($record && $record->qubaid == $qubaid && !is_null($record->slot)) {
            $quba->questionattempts[$record->slot] =
                    question_attempt::load_from_records($records,
                    $record->questionattemptid, $quba->observer,
                    $quba->get_preferred_behaviour());
            if ($records->valid()) {
                $record = $records->current();
            } else {
                $record = false;
            }
        }

        return $quba;
    }
开发者ID:Jtgadbois,项目名称:Pedadida,代码行数:48,代码来源:questionusage.php

示例5: test_load_missing_question

 public function test_load_missing_question()
 {
     $records = new test_recordset(array(array('questionattemptid', 'contextid', 'questionusageid', 'slot', 'behaviour', 'questionid', 'variant', 'maxmark', 'minfraction', 'flagged', 'questionsummary', 'rightanswer', 'responsesummary', 'timemodified', 'attemptstepid', 'sequencenumber', 'state', 'fraction', 'timecreated', 'userid', 'name', 'value'), array(1, 123, 1, 1, 'deferredfeedback', -1, 1, 2.0, 0.0, 0, '', '', '', 1256233790, 1, 0, 'todo', null, 1256233700, 1, null, null)));
     question_bank::start_unit_test();
     $qa = question_attempt::load_from_records($records, 1, new question_usage_null_observer(), 'deferredfeedback');
     question_bank::end_unit_test();
     $missingq = question_bank::get_qtype('missingtype')->make_deleted_instance(-1, 2);
     $this->assertEqual($missingq, $qa->get_question());
     $this->assertEqual(1, $qa->get_num_steps());
     $step = $qa->get_step(0);
     $this->assertEqual(question_state::$todo, $step->get_state());
     $this->assertNull($step->get_fraction());
     $this->assertEqual(1256233700, $step->get_timecreated());
     $this->assertEqual(1, $step->get_user_id());
     $this->assertEqual(array(), $step->get_all_data());
 }
开发者ID:hatone,项目名称:moodle,代码行数:16,代码来源:testquestionattempt.php

示例6: load_from_records

 /**
  * Create a question_usage_by_activity from records loaded from the database.
  *
  * For internal use only.
  *
  * @param Iterator $records Raw records loaded from the database.
  * @param int $questionattemptid The id of the question_attempt to extract.
  * @return question_usage_by_activity The newly constructed usage.
  */
 public static function load_from_records($records, $qubaid)
 {
     $record = $records->current();
     while ($record->qubaid != $qubaid) {
         $records->next();
         if (!$records->valid()) {
             throw new coding_exception("Question usage {$qubaid} not found in the database.");
         }
         $record = $records->current();
     }
     $quba = new offlinequiz_question_usage_by_activity($record->component, context::instance_by_id($record->contextid));
     $quba->set_id_from_database($record->qubaid);
     $quba->set_preferred_behaviour($record->preferredbehaviour);
     $quba->observer = new question_engine_unit_of_work($quba);
     while ($record && $record->qubaid == $qubaid && !is_null($record->slot)) {
         $quba->questionattempts[$record->slot] = question_attempt::load_from_records($records, $record->questionattemptid, $quba->observer, $quba->get_preferred_behaviour());
         if ($records->valid()) {
             $record = $records->current();
         } else {
             $record = false;
         }
     }
     return $quba;
 }
开发者ID:frankkoch,项目名称:moodle-mod_offlinequiz,代码行数:33,代码来源:locallib.php


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