format.php

来自「很棒的在线教学系统」· PHP 代码 · 共 801 行 · 第 1/3 页

PHP
801
字号
            // there is usually only one exercise in a file            if (method_exists($this, 'defaultquestion')) {                $question = $this->defaultquestion();            } else {                $question = new stdClass();                $question->usecase = 0; // Ignore case                $question->image = "";  // No images with this format            }            $question->qtype = MATCH;            $question->name = $this->hotpot_get_title($xml, $x);            $question->questiontext = $this->hotpot_get_reading($xml);            $question->questiontext .= $this->hotpot_get_instructions($xml);            $question->subquestions = array();            $question->subanswers = array();            $p = 0;            while (($pair = $exercise."['pair'][$p]['#']") && $xml->xml_value($tags, $pair)) {                $left = $xml->xml_value($tags, $pair."['left-item'][0]['#']['text'][0]['#']");                $right = $xml->xml_value($tags, $pair."['right-item'][0]['#']['text'][0]['#']");                if ($left && $right) {                    $match_count++;                    $question->subquestions[$p] = $this->hotpot_prepare_str($left);                    $question->subanswers[$p] = $this->hotpot_prepare_str($right);                }                $p++;            }            $question->defaultgrade = $match_count * $defaultgrade;            $questions[] = $question;            $x++;        }    }    function process_jmix(&$xml, &$questions) {        // define default grade (per segment)        $defaultgrade = 1;        $segment_count = 0;        // xml tags to the start of the jumbled order exercise        $tags = 'data,jumbled-order-exercise';        $x = 0;        while (($exercise = "[$x]['#']") && $xml->xml_value($tags, $exercise)) {            // there is usually only one exercise in a file            if (method_exists($this, 'defaultquestion')) {                $question = $this->defaultquestion();            } else {                $question = new stdClass();                $question->usecase = 0; // Ignore case                $question->image = "";  // No images with this format            }            $question->qtype = SHORTANSWER;            $question->name = $this->hotpot_get_title($xml, $x);            $question->answer = array();            $question->fraction = array();            $question->feedback = array();            $i = 0;            $segments = array();            while ($segment = $xml->xml_value($tags, $exercise."['main-order'][0]['#']['segment'][$i]['#']")) {                $segments[] = $this->hotpot_prepare_str($segment);                $segment_count++;                $i++;            }            $answer = implode(' ', $segments);            $this->hotpot_seed_RNG();            shuffle($segments);            $question->questiontext = $this->hotpot_get_reading($xml);            $question->questiontext .= $this->hotpot_get_instructions($xml);            $question->questiontext .= ' &nbsp; <NOBR><B>[ &nbsp; '.implode(' &nbsp; ', $segments).' &nbsp; ]</B></NOBR>';            $a = 0;            while (!empty($answer)) {                $question->answer[$a] = $answer;                $question->fraction[$a] = 1;                $question->feedback[$a] = '';                $answer = $this->hotpot_prepare_str($xml->xml_value($tags, $exercise."['alternate'][$a]['#']"));                $a++;            }            $question->defaultgrade = $segment_count * $defaultgrade;            $questions[] = $question;            $x++;        }    }    function process_jquiz(&$xml, &$questions) {        // define default grade (per question)        $defaultgrade = 1;        // xml tags to the start of the questions        $tags = 'data,questions';        $x = 0;        while (($exercise = "[$x]['#']") && $xml->xml_value($tags, $exercise)) {            // there is usually only one 'questions' object in a single exercise            $q = 0;            while (($question_record = $exercise."['question-record'][$q]['#']") && $xml->xml_value($tags, $question_record)) {                if (method_exists($this, 'defaultquestion')) {                    $question = $this->defaultquestion();                } else {                    $question = new stdClass();                    $question->usecase = 0; // Ignore case                    $question->image = "";  // No images with this format                }                $question->defaultgrade = $defaultgrade;                $question->name = $this->hotpot_get_title($xml, $q, true);                $text = $xml->xml_value($tags, $question_record."['question'][0]['#']");                $question->questiontext = $this->hotpot_prepare_str($text);                if ($xml->xml_value($tags, $question_record."['answers']")) {                    // HP6 JQuiz                    $answers = $question_record."['answers'][0]['#']";                } else {                    // HP5 JBC or JQuiz                    $answers = $question_record;                }                if($xml->xml_value($tags, $question_record."['question-type']")) {                    // HP6 JQuiz                    $type = $xml->xml_value($tags, $question_record."['question-type'][0]['#']");                    //  1 : multiple choice                    //  2 : short-answer                    //  3 : hybrid                    //  4 : multiple select                } else {                    // HP5                    switch ($xml->quiztype) {                        case 'jbc':                            $must_select_all = $xml->xml_value($tags, $question_record."['must-select-all'][0]['#']");                            if (empty($must_select_all)) {                                $type = 1; // multichoice                            } else {                                $type = 4; // multiselect                            }                            break;                        case 'jquiz':                            $type = 2; // shortanswer                            break;                        default:                            $type = 0; // unknown                    }                }                $question->qtype = ($type==2 ? SHORTANSWER : MULTICHOICE);                $question->single = ($type==4 ? 0 : 1);                // workaround required to calculate scores for multiple select answers                $no_of_correct_answers = 0;                if ($type==4) {                    $a = 0;                    while (($answer = $answers."['answer'][$a]['#']") && $xml->xml_value($tags, $answer)) {                        $correct = $xml->xml_value($tags, $answer."['correct'][0]['#']");                        if (empty($correct)) {                            // do nothing                        } else {                            $no_of_correct_answers++;                        }                        $a++;                    }                }                $a = 0;                $question->answer = array();                $question->fraction = array();                $question->feedback = array();                $aa = 0;                $correct_answers = array();                $correct_answers_all_zero = true;                while (($answer = $answers."['answer'][$a]['#']") && $xml->xml_value($tags, $answer)) {                    $correct = $xml->xml_value($tags, $answer."['correct'][0]['#']");                    if (empty($correct)) {                        $fraction = 0;                    } else if ($type==4) { // multiple select                        // strange behavior if the $fraction isn't exact to 5 decimal places                        $fraction = round(1/$no_of_correct_answers, 5);                    } else {                        if ($xml->xml_value($tags, $answer."['percent-correct']")) {                            // HP6 JQuiz                            $percent = $xml->xml_value($tags, $answer."['percent-correct'][0]['#']");                            $fraction = $percent/100;                        } else {                            // HP5 JBC or JQuiz                            $fraction = 1;                        }                    }                    $answertext = $this->hotpot_prepare_str($xml->xml_value($tags, $answer."['text'][0]['#']"));                    if ($answertext!='') {                        $question->answer[$aa] = $answertext;                        $question->fraction[$aa] = $fraction;                        $question->feedback[$aa] = $this->hotpot_prepare_str($xml->xml_value($tags, $answer."['feedback'][0]['#']"));                        if ($correct) {                            if ($fraction) {                                $correct_answers_all_zero = false;                            }                            $correct_answers[] = $aa;                        }                        $aa++;                    }                    $a++;                }                if ($correct_answers_all_zero) {                    // correct answers all have score of 0%,                     // so reset score for correct answers 100%                    foreach ($correct_answers as $aa) {                        $question->fraction[$aa] = 1;                    }                }                // add a sanity check for empty questions, see MDL-17779                if (!empty($question->questiontext)) {                    $questions[] = $question;                }                $q++;            }            $x++;        }    }    function hotpot_seed_RNG() {        // seed the random number generator        static $HOTPOT_SEEDED_RNG = FALSE;        if (!$HOTPOT_SEEDED_RNG) {            srand((double) microtime() * 1000000);            $HOTPOT_SEEDED_RNG = TRUE;        }    }    function hotpot_get_title(&$xml, $x, $flag=false) {        $title = $xml->xml_value('data,title');        if ($x || $flag) {            $title .= ' ('.($x+1).')';        }        return $this->hotpot_prepare_str($title);    }    function hotpot_get_instructions(&$xml) {        $text = $xml->xml_value('hotpot-config-file,instructions');        if (empty($text)) {            $text = "Hot Potatoes $xml->quiztype";        }        return $this->hotpot_prepare_str($text);    }    function hotpot_get_reading(&$xml) {        $str = '';        $tags = 'data,reading';        if ($xml->xml_value("$tags,include-reading")) {            if ($title = $xml->xml_value("$tags,reading-title")) {                $str .= "<H3>$title</H3>";            }            if ($text = $xml->xml_value("$tags,reading-text")) {                $str .= "<P>$text</P>";            }        }        return $this->hotpot_prepare_str($str);    }    function hotpot_prepare_str($str) {        // convert html entities to unicode and add slashes        $str = preg_replace('/&#x([0-9a-f]+);/ie', "hotpot_charcode_to_utf8(hexdec('\\1'))", $str);        $str = preg_replace('/&#([0-9]+);/e', "hotpot_charcode_to_utf8(\\1)", $str);        return addslashes($str);    }} // end class// get the standard XML parser supplied with Moodlerequire_once("$CFG->libdir/xmlize.php");

⌨️ 快捷键说明

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