📄 format.php
字号:
foreach($quest->feedback as $fback) { if (isset($fback->ident)) { if ($fback->ident == 'correct' || $fback->ident == 'incorrect') { $feedback[$fback->ident] = $fback->text; } } } foreach($quest->responses as $response) { if(isset($response->title)) { if (isset($response->ident[0]['varequal'][0]['#'])) { //for BB Fill in the Blank, only interested in correct answers if ($response->feedback = 'correct') { $answers[] = addslashes($response->ident[0]['varequal'][0]['#']); $fractions[] = 1; if (isset($feedback['correct'])) { $feedbacks[] = addslashes($feedback['correct']); } else { $feedbacks[] = ''; } } } } } //Adding catchall to so that students can see feedback for incorrect answers when they enter something the //instructor did not enter $answers[] = '*'; $fractions[] = 0; if (isset($feedback['incorrect'])) { $feedbacks[] = addslashes($feedback['incorrect']); } else { $feedbacks[] = ''; } $question->answer = $answers; $question->fraction = $fractions; $question->feedback = $feedbacks; // Changed to assign $feedbacks to $question->feedback instead of if (!empty($question)) { $questions[] = $question; }}//----------------------------------------// Process Multiple Choice Questions//----------------------------------------function process_mc($quest, &$questions) { $question = $this->process_common( $quest ); $question->qtype = MULTICHOICE; $question->single = 1; $feedback = array(); foreach($quest->feedback as $fback) { $feedback[$fback->ident] = addslashes($fback->text); } foreach($quest->responses as $response) { if (isset($response->title)) { if ($response->title == 'correct') { // only one answer possible for this qtype so first index is correct answer $correct = $response->ident[0]['varequal'][0]['#']; } } else { // fallback method for when the title is not set if ($response->feedback == 'correct') { // only one answer possible for this qtype so first index is correct answer $correct = $response->ident[0]['varequal'][0]['#']; // added [0]['varequal'][0]['#'] to $response->ident - CT 8/9/06 } } } $i = 0; foreach($quest->RESPONSE_BLOCK->choices as $response) { $question->answer[$i] = addslashes($response->text); if ($correct == $response->ident) { $question->fraction[$i] = 1; // this is a bit of a hack to catch the feedback... first we see if a 'correct' feedback exists // then specific feedback for this question (maybe this should be switched?, but from my example // question pools I have not seen response specific feedback, only correct or incorrect feedback if (!empty($feedback['correct'])) { $question->feedback[$i] = $feedback['correct']; } elseif (!empty($feedback[$i])) { $question->feedback[$i] = $feedback[$i]; } else { // failsafe feedback (should be '' instead?) $question->feedback[$i] = "correct"; } } else { $question->fraction[$i] = 0; if (!empty($feedback['incorrect'])) { $question->feedback[$i] = $feedback['incorrect']; } elseif (!empty($feedback[$i])) { $question->feedback[$i] = $feedback[$i]; } else { // failsafe feedback (should be '' instead?) $question->feedback[$i] = 'incorrect'; } } $i++; } if (!empty($question)) { $questions[] = $question; }}//----------------------------------------// Process Multiple Choice Questions With Multiple Answers//----------------------------------------function process_ma($quest, &$questions) { $question = $this->process_common( $quest ); // copied this from process_mc $question->qtype = MULTICHOICE; $question->single = 0; // More than one answer allowed $answers = $quest->responses; $correct_answers = array(); foreach($answers as $answer) { if($answer->title == 'correct') { $answerset = $answer->ident[0]['and'][0]['#']['varequal']; foreach($answerset as $ans) { $correct_answers[] = $ans['#']; } } } foreach ($quest->feedback as $fb) { $feedback->{$fb->ident} = addslashes(trim($fb->text)); } $correct_answer_count = count($correct_answers); $choiceset = $quest->RESPONSE_BLOCK->choices; $i = 0; foreach($choiceset as $choice) { $question->answer[$i] = addslashes(trim($choice->text)); if (in_array($choice->ident, $correct_answers)) { // correct answer $question->fraction[$i] = floor(100000/$correct_answer_count)/100000; // strange behavior if we have more than 5 decimal places $question->feedback[$i] = $feedback->correct; } else { // wrong answer $question->fraction[$i] = 0; $question->feedback[$i] = $feedback->incorrect; } $i++; } $questions[] = $question;}//----------------------------------------// Process Essay Questions//----------------------------------------function process_essay($quest, &$questions) {// this should be rewritten to accomodate moodle 1.6 essay question type eventually if (defined("ESSAY")) { // treat as short answer $question = $this->process_common( $quest ); // copied this from process_mc $question->qtype = ESSAY; $question->feedback = array(); // not sure where to get the correct answer from foreach($quest->feedback as $feedback) { // Added this code to put the possible solution that the // instructor gives as the Moodle answer for an essay question if ($feedback->ident == 'solution') { $question->feedback = addslashes($feedback->text); } } //Added because essay/questiontype.php:save_question_option is expecting a //fraction property - CT 8/10/06 $question->fraction[] = 1; if (!empty($question)) { $questions[]=$question; } } else { print "Essay question types are not handled because the quiz question type 'Essay' does not exist in this installation of Moodle<br/>"; print " Omitted Question: ".$quest->QUESTION_BLOCK->text.'<br/><br/>'; }}//----------------------------------------// Process Matching Questions//----------------------------------------function process_matching($quest, &$questions) { global $QTYPES; // renderedmatch is an optional plugin, so we need to check if it is defined if (array_key_exists('renderedmatch', $QTYPES)) { $question = $this->process_common( $quest ); $question->valid = true; $question->qtype = 'renderedmatch'; foreach($quest->RESPONSE_BLOCK->subquestions as $qid => $subq) { foreach($quest->responses as $rid => $resp) { if ($resp->ident == $subq->ident) { $correct = addslashes($resp->correct); $feedback = addslashes($resp->feedback); } } foreach($subq->choices as $cid => $choice) { if ($choice == $correct) { $question->subquestions[] = addslashes($subq->text); $question->subanswers[] = addslashes($quest->RIGHT_MATCH_BLOCK->matching_answerset[$cid]->text); } } } // check format $status = true; if ( count($quest->RESPONSE_BLOCK->subquestions) > count($quest->RIGHT_MATCH_BLOCK->matching_answerset) || count($question->subquestions) < 2) { $status = false; } else { // need to redo to make sure that no two questions have the same answer (rudimentary now) foreach($question->subanswers as $qstn) { if(isset($previous)) { if ($qstn == $previous) { $status = false; } } $previous = $qstn; if ($qstn == '') { $status = false; } } } if ($status) { $questions[] = $question; } else { global $COURSE, $CFG; print '<table class="boxaligncenter" border="1">'; print '<tr><td colspan="2" style="background-color:#FF8888;">This matching question is malformed. Please ensure there are no blank answers, no two questions have the same answer, and/or there are correct answers for each question. There must be at least as many subanswers as subquestions, and at least one subquestion.</td></tr>'; print "<tr><td>Question:</td><td>".$quest->QUESTION_BLOCK->text; if (isset($quest->QUESTION_BLOCK->file)) { print '<br/><font color="red">There is a subfile contained in the zipfile that has been copied to course files: bb_import/'.basename($quest->QUESTION_BLOCK->file).'</font>'; if (preg_match('/(gif|jpg|jpeg|png)$/i', $quest->QUESTION_BLOCK->file)) { print '<img src="'.$CFG->wwwroot.'/file.php/'.$COURSE->id.'/bb_import/'.basename($quest->QUESTION_BLOCK->file).'" />'; } } print "</td></tr>"; print "<tr><td>Subquestions:</td><td><ul>"; foreach($quest->responses as $rs) { $correct_responses->{$rs->ident} = $rs->correct; } foreach($quest->RESPONSE_BLOCK->subquestions as $subq) { print '<li>'.$subq->text.'<ul>'; foreach($subq->choices as $id=>$choice) { print '<li>'; if ($choice == $correct_responses->{$subq->ident}) { print '<font color="green">'; } else { print '<font color="red">'; } print $quest->RIGHT_MATCH_BLOCK->matching_answerset[$id]->text.'</font></li>'; } print '</ul>'; } print '</ul></td></tr>'; print '<tr><td>Feedback:</td><td><ul>'; foreach($quest->feedback as $fb) { print '<li>'.$fb->ident.': '.$fb->text.'</li>'; } print '</ul></td></tr></table>'; } } else { print "Matching question types are not handled because the quiz question type 'Rendered Matching' does not exist in this installation of Moodle<br/>"; print " Omitted Question: ".$quest->QUESTION_BLOCK->text.'<br/><br/>'; }}function strip_applet_tags_get_mathml($string) { if(stristr($string, '</APPLET>') === FALSE) { return $string; } else { // strip all applet tags keeping stuff before/after and inbetween (if mathml) them while (stristr($string, '</APPLET>') !== FALSE) { preg_match("/(.*)\<applet.*value=\"(\<math\>.*\<\/math\>)\".*\<\/applet\>(.*)/i",$string, $mathmls); $string = $mathmls[1].$mathmls[2].$mathmls[3]; } return $string; }}} // close object?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -