⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 questiontype.php

📁 很棒的在线教学系统
💻 PHP
📖 第 1 页 / 共 3 页
字号:
                            $chosenanswer = clone($answers[$response]);                        }                        break;                    default:                        break;                }                // Set up a default chosenanswer so that all non-empty wrong                // answers are highlighted red                if (empty($chosenanswer) && !empty($response)) {                    $chosenanswer = new stdClass;                    $chosenanswer->fraction = 0.0;                }                if (!empty($chosenanswer->feedback)) {                    $feedback = s(str_replace(array("\\", "'"), array("\\\\", "\\'"), $feedback.$chosenanswer->feedback));                    if  ($options->readonly && $options->correct_responses) {                        $strfeedbackwrapped = get_string('correctanswerandfeedback', 'qtype_multianswer');                    }else {                        $strfeedbackwrapped = get_string('feedback', 'quiz');                    }                    $popup = " onmouseover=\"return overlib('$feedback', STICKY, MOUSEOFF, CAPTION, '$strfeedbackwrapped', FGCOLOR, '#FFFFFF');\" ".                             " onmouseout=\"return nd();\" ";                }                /// Determine style                if ($options->feedback && $response != '') {                    $style = 'class = "'.question_get_feedback_class($chosenanswer->fraction).'"';                    $feedbackimg = question_get_feedback_image($chosenanswer->fraction);                } else {                    $style = '';                    $feedbackimg = '';                }            }            if ($feedback !='' && $popup == ''){                $strfeedbackwrapped = get_string('correctanswer', 'qtype_multianswer');                    $feedback = s(str_replace(array("\\", "'"), array("\\\\", "\\'"), $feedback));                    $popup = " onmouseover=\"return overlib('$feedback', STICKY, MOUSEOFF, CAPTION, '$strfeedbackwrapped', FGCOLOR, '#FFFFFF');\" ".                             " onmouseout=\"return nd();\" ";            }            // Print the input control            switch ($wrapped->qtype) {                case 'shortanswer':                case 'numerical':                    $size = 1 ;                    foreach ($answers as $answer) {                        if (strlen(trim($answer->answer)) > $size ){                            $size = strlen(trim($answer->answer));                        }                    }                    if (strlen(trim($response))> $size ){                            $size = strlen(trim($response))+1;                    }                    $size = $size + rand(0,$size*0.15);                    $size > 60 ? $size = 60 : $size = $size;                    $styleinfo = "size=\"$size\"";                    /**                    * Uncomment the following lines if you want to limit for small sizes.                    * Results may vary with browsers see MDL-3274                    */                    /*                    if ($size < 2) {                        $styleinfo = 'style="width: 1.1em;"';                    }                    if ($size == 2) {                        $styleinfo = 'style="width: 1.9em;"';                    }                    if ($size == 3) {                        $styleinfo = 'style="width: 2.3em;"';                    }                    if ($size == 4) {                        $styleinfo = 'style="width: 2.8em;"';                    }                    */                    echo "<input $style $readonly $popup name=\"$inputname\"";                    echo "  type=\"text\" value=\"".s($response, true)."\" ".$styleinfo." /> ";                    if (!empty($feedback) && !empty($USER->screenreader)) {                        echo "<img src=\"$CFG->pixpath/i/feedback.gif\" alt=\"$feedback\" />";                    }                    echo $feedbackimg;                    break;                case 'multichoice':                 if ($wrapped->options->layout == 0 ){                    $outputoptions = '<option></option>'; // Default empty option                    foreach ($answers as $mcanswer) {                        $selected = '';                        if ($response == $mcanswer->id) {                            $selected = ' selected="selected"';                        }                        $outputoptions .= "<option value=\"$mcanswer->id\"$selected>" .                                s($mcanswer->answer, true) . '</option>';                    }                    // In the next line, $readonly is invalid HTML, but it works in                    // all browsers. $disabled would be valid, but then the JS for                    // displaying the feedback does not work. Of course, we should                    // not be relying on JS (for accessibility reasons), but that is                    // a bigger problem.                    //                    // The span is used for safari, which does not allow styling of                    // selects.                    echo "<span $style><select $popup $readonly $style name=\"$inputname\">";                    echo $outputoptions;                    echo '</select></span>';                    if (!empty($feedback) && !empty($USER->screenreader)) {                        echo "<img src=\"$CFG->pixpath/i/feedback.gif\" alt=\"$feedback\" />";                    }                    echo $feedbackimg;                    }else if ($wrapped->options->layout == 1 || $wrapped->options->layout == 2){                        $ordernumber=0;                        $anss =  Array();                        foreach ($answers as $mcanswer) {                            $ordernumber++;                            $checked = '';                            $chosen = false;                            $type = 'type="radio"';                            $name   = "name=\"{$inputname}\"";                            if ($response == $mcanswer->id) {                                $checked = 'checked="checked"';                                $chosen = true;                            }                            $a = new stdClass;                            $a->id   = $question->name_prefix . $mcanswer->id;                            $a->class = '';                            $a->feedbackimg = '';                            // Print the control                    $a->control = "<input $readonly id=\"$a->id\" $name $checked $type value=\"$mcanswer->id\" />";                if ($options->correct_responses && $mcanswer->fraction > 0) {                    $a->class = question_get_feedback_class(1);                }                if (($options->feedback && $chosen) || $options->correct_responses) {                    if ($type == ' type="checkbox" ') {                        $a->feedbackimg = question_get_feedback_image($mcanswer->fraction > 0 ? 1 : 0, $chosen && $options->feedback);                    } else {                        $a->feedbackimg = question_get_feedback_image($mcanswer->fraction, $chosen && $options->feedback);                    }                }                    // Print the answer text: no automatic numbering                $a->text =format_text($mcanswer->answer, FORMAT_MOODLE, $formatoptions, $cmoptions->course);                    // Print feedback if feedback is on                if (($options->feedback || $options->correct_responses) && ($checked )) { //|| $options->readonly                    $a->feedback = format_text($mcanswer->feedback, true, $formatoptions, $cmoptions->course);                } else {                    $a->feedback = '';                }                        $anss[] = clone($a);                }                ?>            <?php    if ($wrapped->options->layout == 1 ){            ?>                  <table class="answer">                    <?php $row = 1; foreach ($anss as $answer) { ?>                      <tr class="<?php echo 'r'.$row = $row ? 0 : 1; ?>">                        <td class="c0 control">                          <?php echo $answer->control; ?>                        </td>                        <td class="c1 text <?php echo $answer->class ?>">                          <label for="<?php echo $answer->id ?>">                            <?php echo $answer->text; ?>                            <?php echo $answer->feedbackimg; ?>                          </label>                        </td>                        <td class="c0 feedback">                          <?php echo $answer->feedback; ?>                        </td>                      </tr>                    <?php } ?>                  </table>                  <?php }else  if ($wrapped->options->layout == 2 ){                    ?>                             <table class="answer">                      <tr class="<?php echo 'r'.$row = $row ? 0 : 1; ?>">                    <?php $row = 1; foreach ($anss as $answer) { ?>                        <td class="c0 control">                          <?php echo $answer->control; ?>                        </td>                        <td class="c1 text <?php echo $answer->class ?>">                          <label for="<?php echo $answer->id ?>">                            <?php echo $answer->text; ?>                            <?php echo $answer->feedbackimg; ?>                          </label>                        </td>                        <td class="c0 feedback">                          <?php echo $answer->feedback; ?>                        </td>                    <?php } ?>                      </tr>                  </table>                  <?php }                                              }else {                        echo "no valid layout";                    }                                        break;                default:                    $a = new stdClass;                    $a->type = $wrapped->qtype ;                     $a->sub = $positionkey;                    print_error('unknownquestiontypeofsubquestion', 'qtype_multianswer','',$a);                    break;           }           echo "</label>"; // MDL-7497        }        else {            if(!  isset($question->options->questions[$positionkey])){                echo $regs[0]."</label>";            }else {                echo '</label><div class="error" >'.get_string('questionnotfound','qtype_multianswer',$positionkey).'</div>';            }       }    }        // Print the final piece of question text:        echo $qtextremaining;        $this->print_question_submit_buttons($question, $state, $cmoptions, $options);        echo '</div>';    }    function grade_responses(&$question, &$state, $cmoptions) {        global $QTYPES;        $teststate = clone($state);        $state->raw_grade = 0;        foreach($question->options->questions as $key => $wrapped) {            if (!empty($wrapped)){            $state->responses[$key] = $state->responses[$key];            $teststate->responses = array('' => $state->responses[$key]);            $teststate->raw_grade = 0;            if (false === $QTYPES[$wrapped->qtype]             ->grade_responses($wrapped, $teststate, $cmoptions)) {                return false;            }            $state->raw_grade += $teststate->raw_grade;        }        }        $state->raw_grade /= $question->defaultgrade;        $state->raw_grade = min(max((float) $state->raw_grade, 0.0), 1.0)         * $question->maxgrade;        if (empty($state->raw_grade)) {            $state->raw_grade = 0.0;        }        $state->penalty = $question->penalty * $question->maxgrade;        // mark the state as graded        $state->event = ($state->event ==  QUESTION_EVENTCLOSE) ? QUESTION_EVENTCLOSEANDGRADE : QUESTION_EVENTGRADE;        return true;    }    function get_actual_response($question, $state) {        global $QTYPES;        $teststate = clone($state);        foreach($question->options->questions as $key => $wrapped) {            $state->responses[$key] = html_entity_decode($state->responses[$key]);            $teststate->responses = array('' => $state->responses[$key]);            $correct = $QTYPES[$wrapped->qtype]             ->get_actual_response($wrapped, $teststate);            // change separator here if you want            $responsesseparator = ',';            $responses[$key] = implode($responsesseparator, $correct);        }        return $responses;    }/// BACKUP FUNCTIONS ////////////////////////////    /*     * Backup the data in the question     *     * This is used in question/backuplib.php     */    function backup($bf,$preferences,$question,$level=6) {        $status = true;        $multianswers = get_records("question_multianswer","question",$question,"id");        //If there are multianswers        if ($multianswers) {            //Print multianswers header            $status = fwrite ($bf,start_tag("MULTIANSWERS",$level,true));            //Iterate over each multianswer            foreach ($multianswers as $multianswer) {                $status = fwrite ($bf,start_tag("MULTIANSWER",$level+1,true));                //Print multianswer contents                fwrite ($bf,full_tag("ID",$level+2,false,$multianswer->id));                fwrite ($bf,full_tag("QUESTION",$level+2,false,$multianswer->question));                fwrite ($bf,full_tag("SEQUENCE",$level+2,false,$multianswer->sequence));                $status = fwrite ($bf,end_tag("MULTIANSWER",$level+1,true));            }            //Print multianswers footer            $status = fwrite ($bf,end_tag("MULTIANSWERS",$level,true));            //Now print question_answers            $status = question_backup_answers($bf,$preferences,$question);        }        return $status;    }/// RESTORE FUNCTIONS /////////////////    /*     * Restores the data in the question     *     * This is used in question/restorelib.php     */    function restore($old_question_id,$new_question_id,$info,$restore) {        $status = true;        //Get the multianswers array        $multianswers = $info['#']['MULTIANSWERS']['0']['#']['MULTIANSWER'];        //Iterate over multianswers        for($i = 0; $i < sizeof($multianswers); $i++) {            $mul_info = $multianswers[$i];            //We need this later            $oldid = backup_todb($mul_info['#']['ID']['0']['#']);            //Now, build the question_multianswer record structure            $multianswer = new stdClass;            $multianswer->question = $new_question_id;            $multianswer->sequence = backup_todb($mul_info['#']['SEQUENCE']['0']['#']);            //We have to recode the sequence field (a list of question ids)            //Extracts question id from sequence            $sequence_field = "";            $in_first = true;            $tok = strtok($multianswer->sequence,",");            while ($tok) {                //Get the answer from backup_ids                $question = backup_getid($restore->backup_unique_code,"question",$tok);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -