📄 format.php
字号:
$qo->tolerance[] = $this->getpath( $answer, array('#','tolerance',0,'#'), 0 ); // fraction as a tag is deprecated $fraction = $this->getpath( $answer, array('@','fraction'), 0 ) / 100; $qo->fraction[] = $this->getpath( $answer, array('#','fraction',0,'#'), $fraction ); // deprecated } // get units array $qo->unit = array(); $units = $this->getpath( $question, array('#','units',0,'#','unit'), array() ); if (!empty($units)) { $qo->multiplier = array(); foreach ($units as $unit) { $qo->multiplier[] = $this->getpath( $unit, array('#','multiplier',0,'#'), 1 ); $qo->unit[] = $this->getpath( $unit, array('#','unit_name',0,'#'), '', true ); } } return $qo; } /** * import matching type question * @param array question question array from xml tree * @return object question object */ function import_matching( $question ) { // get common parts $qo = $this->import_headers( $question ); // header parts particular to matching $qo->qtype = MATCH; $qo->shuffleanswers = $this->getpath( $question, array( '#','shuffleanswers',0,'#' ), 1 ); // get subquestions $subquestions = $question['#']['subquestion']; $qo->subquestions = array(); $qo->subanswers = array(); // run through subquestions foreach ($subquestions as $subquestion) { $qo->subquestions[] = $this->getpath( $subquestion, array('#','text',0,'#'), '', true ); $qo->subanswers[] = $this->getpath( $subquestion, array('#','answer',0,'#','text',0,'#'), '', true); } return $qo; } /** * import essay type question * @param array question question array from xml tree * @return object question object */ function import_essay( $question ) { // get common parts $qo = $this->import_headers( $question ); // header parts particular to essay $qo->qtype = ESSAY; // get feedback $qo->feedback = $this->getpath( $question, array('#','answer',0,'#','feedback',0,'#','text',0,'#'), '', true ); // get fraction - <fraction> tag is deprecated $qo->fraction = $this->getpath( $question, array('@','fraction'), 0 ) / 100; $q0->fraction = $this->getpath( $question, array('#','fraction',0,'#'), $qo->fraction ); return $qo; } function import_calculated( $question ) { // import numerical question // get common parts $qo = $this->import_headers( $question ); // header parts particular to numerical $qo->qtype = CALCULATED ;//CALCULATED; // get answers array // echo "<pre> question";print_r($question);echo "</pre>"; $answers = $question['#']['answer']; $qo->answers = array(); $qo->feedback = array(); $qo->fraction = array(); $qo->tolerance = array(); $qo->tolerancetype = array(); $qo->correctanswerformat = array(); $qo->correctanswerlength = array(); $qo->feedback = array(); foreach ($answers as $answer) { // answer outside of <text> is deprecated if (!empty( $answer['#']['text'] )) { $answertext = $this->import_text( $answer['#']['text'] ); } else { $answertext = trim($answer['#'][0]); } if ($answertext == '') { $qo->answers[] = '*'; } else { $qo->answers[] = $answertext; } $qo->feedback[] = $this->import_text( $answer['#']['feedback'][0]['#']['text'] ); $qo->tolerance[] = $answer['#']['tolerance'][0]['#']; // fraction as a tag is deprecated if (!empty($answer['#']['fraction'][0]['#'])) { $qo->fraction[] = $answer['#']['fraction'][0]['#']; } else { $qo->fraction[] = $answer['@']['fraction'] / 100; } $qo->tolerancetype[] = $answer['#']['tolerancetype'][0]['#']; $qo->correctanswerformat[] = $answer['#']['correctanswerformat'][0]['#']; $qo->correctanswerlength[] = $answer['#']['correctanswerlength'][0]['#']; } // get units array $qo->unit = array(); if (isset($question['#']['units'][0]['#']['unit'])) { $units = $question['#']['units'][0]['#']['unit']; $qo->multiplier = array(); foreach ($units as $unit) { $qo->multiplier[] = $unit['#']['multiplier'][0]['#']; $qo->unit[] = $unit['#']['unit_name'][0]['#']; } } $datasets = $question['#']['dataset_definitions'][0]['#']['dataset_definition']; $qo->dataset = array(); $qo->datasetindex= 0 ; foreach ($datasets as $dataset) { $qo->datasetindex++; $qo->dataset[$qo->datasetindex] = new stdClass(); $qo->dataset[$qo->datasetindex]->status = $this->import_text( $dataset['#']['status'][0]['#']['text']); $qo->dataset[$qo->datasetindex]->name = $this->import_text( $dataset['#']['name'][0]['#']['text']); $qo->dataset[$qo->datasetindex]->type = $dataset['#']['type'][0]['#']; $qo->dataset[$qo->datasetindex]->distribution = $this->import_text( $dataset['#']['distribution'][0]['#']['text']); $qo->dataset[$qo->datasetindex]->max = $this->import_text( $dataset['#']['maximum'][0]['#']['text']); $qo->dataset[$qo->datasetindex]->min = $this->import_text( $dataset['#']['minimum'][0]['#']['text']); $qo->dataset[$qo->datasetindex]->length = $this->import_text( $dataset['#']['decimals'][0]['#']['text']); $qo->dataset[$qo->datasetindex]->distribution = $this->import_text( $dataset['#']['distribution'][0]['#']['text']); $qo->dataset[$qo->datasetindex]->itemcount = $dataset['#']['itemcount'][0]['#']; $qo->dataset[$qo->datasetindex]->datasetitem = array(); $qo->dataset[$qo->datasetindex]->itemindex = 0; $qo->dataset[$qo->datasetindex]->number_of_items=$dataset['#']['number_of_items'][0]['#']; $datasetitems = $dataset['#']['dataset_items'][0]['#']['dataset_item']; foreach ($datasetitems as $datasetitem) { $qo->dataset[$qo->datasetindex]->itemindex++; $qo->dataset[$qo->datasetindex]->datasetitem[$qo->dataset[$qo->datasetindex]->itemindex] = new stdClass(); $qo->dataset[$qo->datasetindex]->datasetitem[$qo->dataset[$qo->datasetindex]->itemindex]->itemnumber = $datasetitem['#']['number'][0]['#']; //[0]['#']['number'][0]['#'] ; // [0]['numberitems'] ;//['#']['number'][0]['#'];// $datasetitems['#']['number'][0]['#']; $qo->dataset[$qo->datasetindex]->datasetitem[$qo->dataset[$qo->datasetindex]->itemindex]->value = $datasetitem['#']['value'][0]['#'] ;//$datasetitem['#']['value'][0]['#']; } } // echo "<pre>loaded qo";print_r($qo);echo "</pre>"; return $qo; } /** * this is not a real question type. It's a dummy type used * to specify the import category * format is: * <question type="category"> * <category>tom/dick/harry</category> * </question> */ function import_category( $question ) { $qo = new stdClass; $qo->qtype = 'category'; $qo->category = $this->import_text($question['#']['category'][0]['#']['text']); return $qo; } /** * parse the array of lines into an array of questions * this *could* burn memory - but it won't happen that much * so fingers crossed! * @param array lines array of lines from the input file * @return array (of objects) question objects */ function readquestions($lines) { // we just need it as one big string $text = implode($lines, " "); unset( $lines ); // this converts xml to big nasty data structure // the 0 means keep white space as it is (important for markdown format) // print_r it if you want to see what it looks like! $xml = xmlize( $text, 0 ); // set up array to hold all our questions $questions = array(); // iterate through questions foreach ($xml['quiz']['#']['question'] as $question) { $question_type = $question['@']['type']; $questiontype = get_string( 'questiontype','quiz',$question_type ); if ($question_type=='multichoice') { $qo = $this->import_multichoice( $question ); } elseif ($question_type=='truefalse') { $qo = $this->import_truefalse( $question ); } elseif ($question_type=='shortanswer') { $qo = $this->import_shortanswer( $question ); } elseif ($question_type=='numerical') { $qo = $this->import_numerical( $question ); } elseif ($question_type=='description') { $qo = $this->import_description( $question ); } elseif ($question_type=='matching') { $qo = $this->import_matching( $question ); } elseif ($question_type=='cloze') { $qo = $this->import_multianswer( $question ); } elseif ($question_type=='essay') { $qo = $this->import_essay( $question ); } elseif ($question_type=='calculated') { $qo = $this->import_calculated( $question ); } elseif ($question_type=='category') { $qo = $this->import_category( $question ); } else { // try for plugin support // no default question, as the plugin can call // import_headers() itself if it wants to if (!$qo=$this->try_importing_using_qtypes( $question )) { $notsupported = get_string( 'xmltypeunsupported','quiz',$question_type ); $this->error( $notsupported ); $qo = null; } } // stick the result in the $questions array if ($qo) { $questions[] = $qo; } } return $questions; } // EXPORT FUNCTIONS START HERE function export_file_extension() { // override default type so extension is .xml return ".xml"; } /** * Turn the internal question code into a human readable form * (The code used to be numeric, but this remains as some of * the names don't match the new internal format) * @param mixed type_id Internal code * @return string question type string */ function get_qtype( $type_id ) { switch( $type_id ) { case TRUEFALSE: $name = 'truefalse'; break; case MULTICHOICE: $name = 'multichoice'; break; case SHORTANSWER: $name = 'shortanswer'; break; case NUMERICAL: $name = 'numerical'; break; case MATCH: $name = 'matching'; break; case DESCRIPTION: $name = 'description'; break; case MULTIANSWER: $name = 'cloze'; break; case ESSAY: $name = 'essay'; break; case CALCULATED: $name = 'calculated'; break; default: $name = false; } return $name; } /** * Convert internal Moodle text format code into * human readable form * @param int id internal code * @return string format text */ function get_format( $id ) { switch( $id ) { case 0: $name = "moodle_auto_format"; break; case 1: $name = "html"; break; case 2: $name = "plain_text"; break; case 3: $name = "wiki_like"; break; case 4: $name = "markdown"; break; default: $name = "unknown"; } return $name; } /** * Convert internal single question code into * human readable form * @param int id single question code * @return string single question string */ function get_single( $id ) { switch( $id ) { case 0: $name = "false"; break; case 1: $name = "true"; break; default:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -