• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP question_usage_by_activity类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: __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


示例2: test_question

 /**
  * Run this test against a particular question.
  * @param question_usage_by_activity $quba the useage to use when running the test.
  * @param qtype_stack_question $question the question to test.
  * @param int $seed the random seed to use.
  * @return stack_question_test_result the test results.
  */
 public function test_question(question_usage_by_activity $quba, qtype_stack_question $question, $seed)
 {
     $slot = $quba->add_question($question, $question->defaultmark);
     $quba->start_question($slot, $seed);
     $response = self::compute_response($question, $this->inputs);
     $quba->process_action($slot, $response);
     $results = new stack_question_test_result($this);
     foreach ($this->inputs as $inputname => $notused) {
         $inputstate = $question->get_input_state($inputname, $response);
         // The _val below is a hack.  Not all inputnames exist explicitly in
         // the response, but the _val does. Some inputs, e.g. matrices have
         // many entries in the response so none match $response[$inputname].
         if (array_key_exists($inputname, $response)) {
             $inputresponse = $response[$inputname];
         } else {
             $inputresponse = $response[$inputname . '_val'];
         }
         $results->set_input_state($inputname, $inputresponse, $inputstate->contentsdisplayed, $inputstate->status, $inputstate->errors);
     }
     foreach ($this->expectedresults as $prtname => $expectedresult) {
         $result = $question->get_prt_result($prtname, $response, false);
         $results->set_prt_result($prtname, $result);
     }
     return $results;
 }
开发者ID:sowirepo,项目名称:moodle-qtype_stack,代码行数:32,代码来源:questiontest.php


示例3: save_questions_usage_by_activity

 /**
  * Save a {@link question_usage_by_activity} to the database. This works either
  * if the usage was newly created by {@link make_questions_usage_by_activity()}
  * or loaded from the database using {@link load_questions_usage_by_activity()}
  * @param question_usage_by_activity the usage to save.
  */
 public static function save_questions_usage_by_activity(question_usage_by_activity $quba)
 {
     $dm = new question_engine_data_mapper();
     $observer = $quba->get_observer();
     if ($observer instanceof question_engine_unit_of_work) {
         $observer->save($dm);
     } else {
         $dm->insert_questions_usage_by_activity($quba);
     }
 }
开发者ID:sebastiansanio,项目名称:tallerdeprogramacion2fiuba,代码行数:16,代码来源:lib.php


示例4: setup_initial_test_state

 protected function setup_initial_test_state($testdata)
 {
     $records = new question_test_recordset($testdata);
     $this->quba = question_usage_by_activity::load_from_records($records, 1);
     $this->slot = 1;
     $this->observer = new testable_question_engine_unit_of_work($this->quba);
     $this->quba->set_observer($this->observer);
 }
开发者ID:alanaipe2015,项目名称:moodle,代码行数:8,代码来源:unitofwork_test.php


示例5: update_questions_usage_by_activity

 /**
  * Update a question_usages row to refect any changes in a usage (but not
  * any of its question_attempts.
  * @param question_usage_by_activity $quba the usage that has changed.
  */
 public function update_questions_usage_by_activity(question_usage_by_activity $quba)
 {
     $record = new stdClass();
     $record->id = $quba->get_id();
     $record->contextid = $quba->get_owning_context()->id;
     $record->component = $quba->get_owning_component();
     $record->preferredbehaviour = $quba->get_preferred_behaviour();
     $this->db->update_record('question_usages', $record);
 }
开发者ID:covex-nn,项目名称:moodle,代码行数:14,代码来源:datalib.php


示例6: __construct

 /**
  * To create an instance of this class, use
  * {@link question_usage_by_activity::get_attempt_iterator()}.
  * @param $quba the usage to iterate over.
  */
 public function __construct(question_usage_by_activity $quba) {
     $this->quba = $quba;
     $this->slots = $quba->get_slots();
     $this->rewind();
 }
开发者ID:Jtgadbois,项目名称:Pedadida,代码行数:10,代码来源:questionusage.php


示例7: prepare_forced_choices_array

 /**
  * Helper method for preparing the $forcedchoices array.
  * @param array                      $variantsbyslot slot number => variant to select.
  * @param question_usage_by_activity $quba           the question usage we need a strategy for.
  * @throws coding_exception when variant cannot be forced as doesn't work.
  * @return array that can be passed to the constructor as $forcedchoices.
  */
 public static function prepare_forced_choices_array(array $variantsbyslot, question_usage_by_activity $quba)
 {
     $forcedchoices = array();
     foreach ($variantsbyslot as $slot => $varianttochoose) {
         $question = $quba->get_question($slot);
         $seed = $question->get_variants_selection_seed();
         if (array_key_exists($seed, $forcedchoices) && $forcedchoices[$seed] != $varianttochoose) {
             throw new coding_exception('Inconsistent forced variant detected at slot ' . $slot);
         }
         if ($varianttochoose > $question->get_num_variants()) {
             throw new coding_exception('Forced variant out of range at slot ' . $slot);
         }
         $forcedchoices[$seed] = $varianttochoose;
     }
     return $forcedchoices;
 }
开发者ID:mongo0se,项目名称:moodle,代码行数:23,代码来源:lib.php


示例8: test_load

    public function test_load() {
        $records = new question_test_recordset(array(
        array('qubaid', 'contextid', 'component', 'preferredbehaviour',
                                               'questionattemptid', 'contextid', 'questionusageid', 'slot',
                                                              'behaviour', 'questionid', 'variant', 'maxmark', 'minfraction', 'flagged',
                                                                                                             'questionsummary', 'rightanswer', 'responsesummary', 'timemodified',
                                                                                                                                     'attemptstepid', 'sequencenumber', 'state', 'fraction',
                                                                                                                                                                     'timecreated', 'userid', 'name', 'value'),
        array(1, 1, 'unit_test', 'interactive', 1, 123, 1, 1, 'interactive', -1, 1, 2.0000000, 0.0000000, 0, '', '', '', 1256233790, 1, 0, 'todo',             null, 1256233700, 1,       null, null),
        array(1, 1, 'unit_test', 'interactive', 1, 123, 1, 1, 'interactive', -1, 1, 2.0000000, 0.0000000, 0, '', '', '', 1256233790, 2, 1, 'todo',             null, 1256233705, 1,   'answer',  '1'),
        array(1, 1, 'unit_test', 'interactive', 1, 123, 1, 1, 'interactive', -1, 1, 2.0000000, 0.0000000, 0, '', '', '', 1256233790, 5, 2, 'gradedright', 1.0000000, 1256233720, 1,  '-finish',  '1'),
        ));

        $question = test_question_maker::make_question('truefalse', 'true');
        $question->id = -1;

        question_bank::start_unit_test();
        question_bank::load_test_question_data($question);
        $quba = question_usage_by_activity::load_from_records($records, 1);
        question_bank::end_unit_test();

        $this->assertEquals('unit_test', $quba->get_owning_component());
        $this->assertEquals(1, $quba->get_id());
        $this->assertInstanceOf('question_engine_unit_of_work', $quba->get_observer());
        $this->assertEquals('interactive', $quba->get_preferred_behaviour());

        $qa = $quba->get_question_attempt(1);

        $this->assertEquals($question->questiontext, $qa->get_question()->questiontext);

        $this->assertEquals(3, $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(), $step->get_all_data());

        $step = $qa->get_step(1);
        $this->assertEquals(question_state::$todo, $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::$gradedright, $step->get_state());
        $this->assertEquals(1, $step->get_fraction());
        $this->assertEquals(1256233720, $step->get_timecreated());
        $this->assertEquals(1, $step->get_user_id());
        $this->assertEquals(array('-finish' => '1'), $step->get_all_data());
    }
开发者ID:numbas,项目名称:moodle,代码行数:53,代码来源:questionusagebyactivity_test.php


示例9: quiz_start_attempt_built_on_last

/**
 * Start a subsequent new attempt, in each attempt builds on last mode.
 *
 * @param question_usage_by_activity    $quba         this question usage
 * @param object                        $attempt      this attempt
 * @param object                        $lastattempt  last attempt
 * @return object                       modified attempt object
 *
 */
function quiz_start_attempt_built_on_last($quba, $attempt, $lastattempt) {
    $oldquba = question_engine::load_questions_usage_by_activity($lastattempt->uniqueid);

    $oldnumberstonew = array();
    foreach ($oldquba->get_attempt_iterator() as $oldslot => $oldqa) {
        $newslot = $quba->add_question($oldqa->get_question(), $oldqa->get_max_mark());

        $quba->start_question_based_on($newslot, $oldqa);

        $oldnumberstonew[$oldslot] = $newslot;
    }

    // Update attempt layout.
    $newlayout = array();
    foreach (explode(',', $lastattempt->layout) as $oldslot) {
        if ($oldslot != 0) {
            $newlayout[] = $oldnumberstonew[$oldslot];
        } else {
            $newlayout[] = 0;
        }
    }
    $attempt->layout = implode(',', $newlayout);
    return $attempt;
}
开发者ID:rwijaya,项目名称:moodle,代码行数:33,代码来源:locallib.php


示例10: offlinequiz_count_multichoice_questions

/**
 * Counts the multichoice question in a questionusage.
 *
 * @param question_usage_by_activity $questionusage
 * @return number
 */
function offlinequiz_count_multichoice_questions(question_usage_by_activity $questionusage)
{
    $count = 0;
    $slots = $questionusage->get_slots();
    foreach ($slots as $slot) {
        $question = $questionusage->get_question($slot);
        if ($question->qtype->name() == 'multichoice' || $question->qtype->name() == 'multichoiceset') {
            $count++;
        }
    }
    return $count;
}
开发者ID:frankkoch,项目名称:moodle-mod_offlinequiz,代码行数:18,代码来源:locallib.php


示例11: add_questions_to_quba

 /**
  * add the questions to the question usage
  * This is called by the question_attmept class on construct of a new attempt
  *
  * @param \question_usage_by_activity $quba
  *
  * @return array
  */
 public function add_questions_to_quba(\question_usage_by_activity $quba)
 {
     // we need the questionids of our questions
     $questionids = array();
     foreach ($this->qbankOrderedQuestions as $qbankquestion) {
         /** @var activequiz_question $qbankquestion */
         if (!in_array($qbankquestion->getQuestion()->id, $questionids)) {
             $questionids[] = $qbankquestion->getQuestion()->id;
         }
     }
     $questions = question_load_questions($questionids);
     // loop through the ordered question bank questions and add them to the quba
     // object
     $attemptlayout = array();
     foreach ($this->qbankOrderedQuestions as $qbankquestion) {
         $questionid = $qbankquestion->getQuestion()->id;
         $q = \question_bank::make_question($questions[$questionid]);
         $attemptlayout[$qbankquestion->getId()] = $quba->add_question($q, $qbankquestion->getPoints());
     }
     // start the questions in the quba
     $quba->start_all_questions();
     /**
      * return the attempt layout which is a set of ids that are the slot ids from the question engine usage by activity instance
      * these are what are used during an actual attempt rather than the questionid themselves, since the question engine will handle
      * the translation
      */
     return $attemptlayout;
 }
开发者ID:agarnav,项目名称:moodle-mod_activequiz,代码行数:36,代码来源:questionmanager.php


示例12: test_load_data_no_qas

    public function test_load_data_no_qas() {
        // The code had a bug where if a question_usage had no question_attempts,
        // load_from_records got stuck in an infinite loop. This test is to
        // verify that no longer happens.
        $scid = context_system::instance()->id;
        $records = new question_test_recordset(array(
        array('qubaid', 'contextid', 'component', 'preferredbehaviour',
                                                   'questionattemptid', 'questionusageid', 'slot',
                                                                        'behaviour', 'questionid', 'variant', 'maxmark', 'minfraction', 'flagged',
                                                                                                               'questionsummary', 'rightanswer', 'responsesummary', 'timemodified',
                                                                                                                                         'attemptstepid', 'sequencenumber', 'state', 'fraction',
                                                                                                                                                                   'timecreated', 'userid', 'name', 'value'),
        array(1, $scid, 'unit_test', 'interactive', null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null),
        ));

        question_bank::start_unit_test();
        $quba = question_usage_by_activity::load_from_records($records, 1);
        question_bank::end_unit_test();

        $this->assertEquals('unit_test', $quba->get_owning_component());
        $this->assertEquals(1, $quba->get_id());
        $this->assertInstanceOf('question_engine_unit_of_work', $quba->get_observer());
        $this->assertEquals('interactive', $quba->get_preferred_behaviour());

        $this->assertEquals(array(), $quba->get_slots());
    }
开发者ID:JP-Git,项目名称:moodle,代码行数:26,代码来源:questionusagebyactivity_test.php


示例13: offlinequiz_create_latex_question

/**
 * Generates the LaTeX question form for an offlinequiz group.
 *
 * @param question_usage_by_activity $templateusage the template question  usage for this offline group
 * @param object $offlinequiz The offlinequiz object
 * @param object $group the offline group object
 * @param int $courseid the ID of the Moodle course
 * @param object $context the context of the offline quiz.
 * @param boolean correction if true the correction form is generated.
 * @return stored_file instance, the generated PDF file.
 */
function offlinequiz_create_latex_question(question_usage_by_activity $templateusage, $offlinequiz, $group, $courseid, $context, $correction = false)
{
    global $CFG, $DB, $OUTPUT;
    $letterstr = 'abcdefghijklmnopqrstuvwxyz';
    $groupletter = strtoupper($letterstr[$group->number - 1]);
    $coursecontext = context_course::instance($courseid);
    $course = $DB->get_record('course', array('id' => $courseid));
    $title = format_text($offlinequiz->name, FORMAT_HTML);
    $title .= ",  " . get_string('group') . $groupletter;
    // Load all the questions needed for this offline quiz group.
    $sql = "SELECT q.*, c.contextid, ogq.page, ogq.slot, ogq.maxmark\n              FROM {offlinequiz_group_questions} ogq,\n                   {question} q,\n                   {question_categories} c\n             WHERE ogq.offlinequizid = :offlinequizid\n               AND ogq.offlinegroupid = :offlinegroupid\n               AND q.id = ogq.questionid\n               AND q.category = c.id\n          ORDER BY ogq.slot ASC ";
    $params = array('offlinequizid' => $offlinequiz->id, 'offlinegroupid' => $group->id);
    // Load the questions.
    $questions = $DB->get_records_sql($sql, $params);
    if (!$questions) {
        echo $OUTPUT->box_start();
        echo $OUTPUT->error_text(get_string('noquestionsfound', 'offlinequiz', $groupletter));
        echo $OUTPUT->box_end();
        return;
    }
    // Load the question type specific information.
    if (!get_question_options($questions)) {
        print_error('Could not load question options');
    }
    $number = 1;
    // We need a mapping from question IDs to slots, assuming that each question occurs only once.
    $slots = $templateusage->get_slots();
    $latexforquestions = '\\begin{enumerate}' . "\n";
    // If shufflequestions has been activated we go through the questions in the order determined by
    // the template question usage.
    if ($offlinequiz->shufflequestions) {
        foreach ($slots as $slot) {
            $slotquestion = $templateusage->get_question($slot);
            $currentquestionid = $slotquestion->id;
            $question = $questions[$currentquestionid];
            $questiontext = offlinequiz_convert_html_to_latex($question->questiontext);
            $latexforquestions .= '\\item ' . $questiontext . "\n";
            if ($question->qtype == 'multichoice' || $question->qtype == 'multichoiceset') {
                // There is only a slot for multichoice questions.
                $attempt = $templateusage->get_question_attempt($slot);
                $order = $slotquestion->get_order($attempt);
                // Order of the answers.
                $latexforquestions .= '\\begin{enumerate}' . " \n";
                foreach ($order as $key => $answer) {
                    $latexforquestions .= offlinequiz_get_answer_latex($question, $answer);
                }
                $latexforquestions .= '\\end{enumerate}' . "\n";
                $infostr = offlinequiz_get_question_infostring($offlinequiz, $question);
                if ($infostr) {
                    $latexforquestions .= $infostr . "\n";
                }
            }
        }
        $latexforquestions .= '\\end{enumerate}' . "\n";
    } else {
        // No shufflequestions, so go through the questions as they have been added to the offlinequiz group.
        // We also have to show description questions that are not in the template.
        // First, compute mapping  questionid -> slotnumber.
        $questionslots = array();
        foreach ($slots as $slot) {
            $questionslots[$templateusage->get_question($slot)->id] = $slot;
        }
        foreach ($questions as $question) {
            $currentquestionid = $question->id;
            $questiontext = $question->questiontext;
            $questiontext = offlinequiz_convert_html_to_latex($question->questiontext);
            if ($question->qtype == 'description') {
                $latexforquestions .= "\n" . '\\ ' . $questiontext . "\n";
            } else {
                $latexforquestions .= '\\item ' . $questiontext . "\n";
            }
            if ($question->qtype == 'multichoice' || $question->qtype == 'multichoiceset') {
                $slot = $questionslots[$currentquestionid];
                // There is only a slot for multichoice questions.
                $slotquestion = $templateusage->get_question($slot);
                $attempt = $templateusage->get_question_attempt($slot);
                $order = $slotquestion->get_order($attempt);
                // Order of the answers.
                $latexforquestions .= '\\begin{enumerate}' . " \n";
                foreach ($order as $key => $answer) {
                    $latexforquestions .= offlinequiz_get_answer_latex($question, $answer);
                }
                $latexforquestions .= '\\end{enumerate}' . "\n";
                $infostr = offlinequiz_get_question_infostring($offlinequiz, $question);
                if ($infostr) {
                    $latexforquestions .= $infostr . "\n";
                }
            }
        }
//.........这里部分代码省略.........
开发者ID:pauloangelo,项目名称:moodle-mod_offlinequiz,代码行数:101,代码来源:latexlib.php


示例14: offlinequiz_create_pdf_question

/**
 * Generates the PDF question/correction form for an offlinequiz group.
 *
 * @param question_usage_by_activity $templateusage the template question  usage for this offline group
 * @param object $offlinequiz The offlinequiz object
 * @param object $group the offline group object
 * @param int $courseid the ID of the Moodle course
 * @param object $context the context of the offline quiz.
 * @param boolean correction if true the correction form is generated.
 * @return stored_file instance, the generated PDF file.
 */
function offlinequiz_create_pdf_question(question_usage_by_activity $templateusage, $offlinequiz, $group, $courseid, $context, $correction = false)
{
    global $CFG, $DB, $OUTPUT;
    $letterstr = 'abcdefghijklmnopqrstuvwxyz';
    $groupletter = strtoupper($letterstr[$group->number - 1]);
    $coursecontext = context_course::instance($courseid);
    $pdf = new offlinequiz_question_pdf('P', 'mm', 'A4');
    $trans = new offlinequiz_html_translator();
    $title = offlinequiz_str_html_pdf($offlinequiz->name);
    if (!empty($offlinequiz->time)) {
        $title .= ": " . offlinequiz_str_html_pdf(userdate($offlinequiz->time));
    }
    $title .= ",  " . offlinequiz_str_html_pdf(get_string('group') . " {$groupletter}");
    $pdf->set_title($title);
    $pdf->SetMargins(15, 28, 15);
    $pdf->SetAutoPageBreak(false, 25);
    $pdf->AddPage();
    // Print title page.
    $pdf->SetFont('FreeSans', 'B', 14);
    $pdf->Ln(4);
    if (!$correction) {
        $pdf->Cell(0, 4, offlinequiz_str_html_pdf(get_string('questionsheet', 'offlinequiz')), 0, 0, 'C');
        $pdf->Rect(34, 46, 137, 53, 'D');
        $pdf->SetFont('FreeSans', '', 10);
        // Line breaks to position name string etc. properly.
        $pdf->Ln(20);
        $pdf->Cell(58, 10, offlinequiz_str_html_pdf(get_string('name')) . ":", 0, 0, 'R');
        $pdf->Rect(76, 60, 80, 0.3, 'F');
        $pdf->Ln(10);
        $pdf->Cell(58, 10, offlinequiz_str_html_pdf(get_string('idnumber', 'offlinequiz')) . ":", 0, 0, 'R');
        $pdf->Rect(76, 70, 80, 0.3, 'F');
        $pdf->Ln(10);
        $pdf->Cell(58, 10, offlinequiz_str_html_pdf(get_string('studycode', 'offlinequiz')) . ":", 0, 0, 'R');
        $pdf->Rect(76, 80, 80, 0.3, 'F');
        $pdf->Ln(10);
        $pdf->Cell(58, 10, offlinequiz_str_html_pdf(get_string('signature', 'offlinequiz')) . ":", 0, 0, 'R');
        $pdf->Rect(76, 90, 80, 0.3, 'F');
        $pdf->Ln(33);
        $pdf->SetFont('FreeSans', '', $offlinequiz->fontsize);
        $pdf->SetFontSize($offlinequiz->fontsize);
        // The PDF intro text can be arbitrarily long so we have to catch page overflows.
        if (!empty($offlinequiz->pdfintro)) {
            $oldx = $pdf->GetX();
            $oldy = $pdf->GetY();
            $pdf->checkpoint();
            $pdf->writeHTMLCell(165, round($offlinequiz->fontsize / 2), $pdf->GetX(), $pdf->GetY(), $offlinequiz->pdfintro);
            $pdf->Ln();
            if ($pdf->is_overflowing()) {
                $pdf->backtrack();
                $pdf->SetX($oldx);
                $pdf->SetY($oldy);
                $paragraphs = preg_split('/<p>/', $offlinequiz->pdfintro);
                foreach ($paragraphs as $paragraph) {
                    if (!empty($paragraph)) {
                        $sentences = preg_split('/<br\\s*\\/>/', $paragraph);
                        foreach ($sentences as $sentence) {
                            $pdf->checkpoint();
                            $pdf->writeHTMLCell(165, round($offlinequiz->fontsize / 2), $pdf->GetX(), $pdf->GetY(), $sentence . '<br/>');
                            $pdf->Ln();
                            if ($pdf->is_overflowing()) {
                                $pdf->backtrack();
                                $pdf->AddPage();
                                $pdf->Ln(14);
                                $pdf->writeHTMLCell(165, round($offlinequiz->fontsize / 2), $pdf->GetX(), $pdf->GetY(), $sentence);
                                $pdf->Ln();
                            }
                        }
                    }
                }
            }
        }
        $pdf->AddPage();
        $pdf->Ln(2);
    }
    $pdf->SetMargins(15, 15, 15);
    // Load all the questions needed for this offline quiz group.
    $sql = "SELECT q.*, c.contextid, ogq.page, ogq.slot, ogq.maxmark \n              FROM {offlinequiz_group_questions} ogq,\n                   {question} q,\n                   {question_categories} c\n             WHERE ogq.offlinequizid = :offlinequizid\n               AND ogq.offlinegroupid = :offlinegroupid\n               AND q.id = ogq.questionid\n               AND q.category = c.id\n          ORDER BY ogq.slot ASC ";
    $params = array('offlinequizid' => $offlinequiz->id, 'offlinegroupid' => $group->id);
    // Load the questions.
    $questions = $DB->get_records_sql($sql, $params);
    if (!$questions) {
        echo $OUTPUT->box_start();
        echo $OUTPUT->error_text(get_string('noquestionsfound', 'offlinequiz', $groupletter));
        echo $OUTPUT->box_end();
        return;
    }
    // Load the question type specific information.
    if (!get_question_options($questions)) {
        print_error('Could not load question options');
//.........这里部分代码省略.........
开发者ID:frankkoch,项目名称:moodle-mod_offlinequiz,代码行数:101,代码来源:pdflib.php


示例15: offlinequiz_create_docx_question

/**
 * Generates the DOCX question/correction form for an offlinequiz group.
 *
 * @param question_usage_by_activity $templateusage the template question  usage for this offline group
 * @param object $offlinequiz The offlinequiz object
 * @param object $group the offline group object
 * @param int $courseid the ID of the Moodle course
 * @param object $context the context of the offline quiz.
 * @param boolean correction if true the correction form is generated.
 * @return stored_file instance, the generated DOCX file.
 */
function offlinequiz_create_docx_question(question_usage_by_activity $templateusage, $offlinequiz, $group, $courseid, $context, $correction = false)
{
    global $CFG, $DB, $OUTPUT;
    $letterstr = 'abcdefghijklmnopqrstuvwxyz';
    $groupletter = strtoupper($letterstr[$group->number - 1]);
    $coursecontext = context_course::instance($courseid);
    PHPWord_Media::resetMedia();
    $docx = new PHPWord();
    $trans = new offlinequiz_html_translator();
    // Define cell style arrays.
    $cellstyle = array('valign' => 'center');
    // Add text styles.
    // Normal style.
    $docx->addFontStyle('nStyle', array('size' => $offlinequiz->fontsize));
    // Italic style.
    $docx->addFontStyle('iStyle', array('italic' => true, 'size' => $offlinequiz->fontsize));
    // Bold style.
    $docx->addFontStyle('bStyle', array('bold' => true, 'size' => $offlinequiz->fontsize));
    $docx->addFontStyle('brStyle', array('bold' => true, 'align' => 'right', 'size' => $offlinequiz->fontsize));
    // Underline style.
    $docx->addFontStyle('uStyle', array('underline' => PHPWord_Style_Font::UNDERLINE_SINGLE, 'size' => $offlinequiz->fontsize));
    $docx->addFontStyle('ibStyle', array('italic' => true, 'bold' => true, 'size' => $offlinequiz->fontsize));
    $docx->addFontStyle('iuStyle', array('italic' => true, 'underline' => PHPWord_Style_Font::UNDERLINE_SINGLE, 'size' => $offlinequiz->fontsize));
    $docx->addFontStyle('buStyle', array('bold' => true, 'underline' => PHPWord_Style_Font::UNDERLINE_SINGLE, 'size' => $offlinequiz->fontsize));
    $docx->addFontStyle('ibuStyle', array('italic' => true, 'bold' => true, 'underline' => PHPWord_Style_Font::UNDERLINE_SINGLE, 'size' => $offlinequiz->fontsize));
    // Header style.
    $docx->addFontStyle('hStyle', array('bold' => true, 'size' => $offlinequiz->fontsize + 4));
    // Center style.
    $docx->addParagraphStyle('cStyle', array('align' => 'center', 'spaceAfter' => 100));
    $docx->addParagraphStyle('cStyle', array('align' => 'center', 'spaceAfter' => 100));
    $docx->addParagraphStyle('questionTab', array('tabs' => array(new PHPWord_Style_Tab("left", 360))));
    // Define table style arrays.
    $tablestyle = array('borderSize' => 0, 'borderColor' => 'FFFFFF', 'cellMargin' => 20, 'align' => 'center');
    $firstrowstyle = array('borderBottomSize' => 0, 'borderBottomColor' => 'FFFFFF', 'bgColor' => 'FFFFFF');
    $docx->addTableStyle('tableStyle', $tablestyle, $firstrowstyle);
    $boldfont = new PHPWord_Style_Font();
    $boldfont->setBold(true);
    $boldfont->setSize($offlinequiz->fontsize);
    $normalfont = new PHPWord_Style_Font();
    $normalfont->setSize($offlinequiz->fontsize);
    // Define custom list item style for question answers.
    $level1 = new PHPWord_Style_Paragraph();
    $level1->setTabs(new PHPWord_Style_Tabs(array(new PHPWord_Style_Tab('clear', 720), new PHPWord_Style_Tab('num', 360))));
    $level1->setIndentions(new PHPWord_Style_Indentation(array('left' => 360, 'hanging' => 360)));
    $level2 = new PHPWord_Style_Paragraph();
    $level2->setTabs(new PHPWord_Style_Tabs(array(new PHPWord_Style_Tab('left', 720), new PHPWord_Style_Tab('num', 720))));
    $level2->setIndentions(new PHPWord_Style_Indentation(array('left' => 720, 'hanging' => 360)));
    // Create the section that will be used for all outputs.
    $section = $docx->createSection();
    $title = offlinequiz_str_html_docx($offlinequiz->name);
    if (!empty($offlinequiz->time)) {
        if (strlen($title) > 35) {
            $title = substr($title, 0, 33) . ' ...';
        }
        $title .= ": " . offlinequiz_str_html_docx(userdate($offlinequiz->time));
    } else {
        if (strlen($title) > 40) {
            $title = substr($title, 0, 37) . ' ...';
        }
    }
    $title .= ",  " . offlinequiz_str_html_docx(get_string('group') . " {$groupletter}");
    // Add a header.
    $header = $section->createHeader();
    $header->addText($title, array('size' => 10), 'cStyle');
    $header->addImage($CFG->dirroot . '/mod/offlinequiz/pix/line.png', array('width' => 600, 'height' => 5, 'align' => 'center'));
    // Add a footer.
    $footer = $section->createFooter();
    $footer->addImage($CFG->dirroot . '/mod/offlinequiz/pix/line.png', array('width' => 600, 'height' => 5, 'align' => 'center'));
    $footer->addPreserveText($title . '  |  ' . get_string('page') . ' ' . '{PAGE} / {NUMPAGES}', null, array('align' => 'left'));
    // Print title page.
    if (!$correction) {
        $section->addText(offlinequiz_str_html_docx(get_string('questionsheet', 'offlinequiz') . ' - ' . get_string('group') . " {$groupletter}"), 'hStyle', 'cStyle');
        $section->addTextBreak(2);
        $table = $section->addTable('tableStyle');
        $table->addRow();
        $cell = $table->addCell(200, $cellstyle)->addText(offlinequiz_str_html_docx(get_string('name')) . ':  ', 'brStyle');
        $table->addRow();
        $cell = $table->addCell(200, $cellstyle)->addText(offlinequiz_str_html_docx(get_string('idnumber', 'offlinequiz')) . ':  ', 'brStyle');
        $table->addRow();
        $cell = $table->addCell(200, $cellstyle)->addText(offlinequiz_str_html_docx(get_string('studycode', 'offlinequiz')) . ':  ', 'brStyle');
        $table->addRow();
        $cell = $table->addCell(200, $cellstyle)->addText(offlinequiz_str_html_docx(get_string('signature', 'offlinequiz')) . ':  ', 'brStyle');
        $section->addTextBreak(2);
        // The DOCX intro text can be arbitrarily long so we have to catch page overflows.
        if (!empty($offlinequiz->pdfintro)) {
            $blocks = offlinequiz_convert_image_docx($offlinequiz->pdfintro);
            offlinequiz_print_blocks_docx($section, $blocks);
        }
        $section->addPageBreak();
//.........这里部分代码省略.........
开发者ID:frankkoch,项目名称:moodle-mod_offlinequiz,代码行数:101,代码来源:docxlib.php


示例16: close_attempt

 /**
  * Closes the attempt
  *
  * @param \mod_activequiz\activequiz $rtq
  *
  * @return bool Weather or not it was successful
  */
 public function close_attempt($rtq)
 {
     $this->quba->finish_all_questions(time());
     $this->attempt->status = self::FINISHED;
     $this->attempt->timefinish = time();
     $this->save();
     $params = array('objectid' => $this->attempt->id, 'context' => $rtq->getContext(), 'relateduserid' => $this->attempt->userid);
     $event = \mod_activequiz\event\attempt_ended::create($params);
     $event->add_record_snapshot('activequiz_attempts', $this->attempt);
     $event->trigger();
     return true;
 }
开发者ID:agarnav,项目名称:moodle-mod_activequiz,代码行数:19,代码来源:activequiz_attempt.php


示例17: get_contains_select_expectation

 protected function get_contains_select_expectation($name, $choices, $selected = null, $enabled = null)
 {
     $fullname = $this->quba->get_field_prefix($this->slot) . $name;
     return new question_contains_select_expectation($fullname, $choices, $selected, $enabled);
 }
开发者ID:gabrielrosset,项目名称:moodle,代码行数:5,代码来源:helpers.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP question_utils类代码示例发布时间:2022-05-23
下一篇:
PHP question_type类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap