diff --git a/question/questiontypes/description/question.html b/question/questiontypes/description/question.html new file mode 100644 index 00000000000..e805ffa68df --- /dev/null +++ b/question/questiontypes/description/question.html @@ -0,0 +1,14 @@ +
+
+ +
+
+
+ +
+ + + + +
+
diff --git a/question/questiontypes/description/questiontype.php b/question/questiontypes/description/questiontype.php index 58443b82bd0..5e2bba129ee 100644 --- a/question/questiontypes/description/questiontype.php +++ b/question/questiontypes/description/questiontype.php @@ -28,18 +28,22 @@ class quiz_description_qtype extends quiz_default_questiontype { } function print_question(&$question, &$state, $number, $cmoptions, $options) { - print_simple_box_start('center', '90%'); - echo format_text($question->questiontext, + global $CFG; + + // For editing teachers print a link to an editing popup window + $editlink = ''; + if (isteacheredit($cmoptions->course)) { + $stredit = get_string('edit'); + $linktext = ''.$stredit.''; + $editlink = link_to_popup_window('/question/question.php?id='.$question->id, $stredit, $linktext, 450, 550, $stredit, '', true); + } + + $questiontext = format_text($question->questiontext, $question->questiontextformat, NULL, $cmoptions->course); - quiz_print_possible_question_image($question, $cmoptions->course); - if (isteacher($cmoptions->course)) { - echo ''; - link_to_popup_window ('/question/question.php?id=' . $question->id, - 'editquestion', get_string('edit'), 450, 550, get_string('edit')); - echo ''; - } - print_simple_box_end('center', '90%'); + $image = get_question_image($question, $cmoptions->course); + + include "$CFG->dirroot/question/questiontypes/description/question.html"; } function actual_number_of_questions($question) { diff --git a/question/questiontypes/essay/questiontype.php b/question/questiontypes/essay/questiontype.php index 66f3d9a8bbd..08cc69718df 100644 --- a/question/questiontypes/essay/questiontype.php +++ b/question/questiontypes/essay/questiontype.php @@ -91,7 +91,7 @@ class quiz_essay_qtype extends quiz_default_questiontype { $question->questiontextformat, NULL, $cmoptions->course); - quiz_print_possible_question_image($question, $cmoptions->course); + echo get_question_image($question, $cmoptions->course); /// Print input controls $stranswer = get_string("answer", "quiz"); diff --git a/question/questiontypes/match/display.html b/question/questiontypes/match/display.html new file mode 100644 index 00000000000..56d443e2b99 --- /dev/null +++ b/question/questiontypes/match/display.html @@ -0,0 +1,29 @@ +
+ +
+ + + + + +
+ + + + + + + + + +
+ text; ?> + + control; ?> +
+ print_question_submit_buttons($question, $state, $cmoptions, $options); ?> +
diff --git a/question/questiontypes/match/questiontype.php b/question/questiontypes/match/questiontype.php index 1725cac7126..6444c39eaa8 100644 --- a/question/questiontypes/match/questiontype.php +++ b/question/questiontypes/match/questiontype.php @@ -211,6 +211,7 @@ class quiz_match_qtype extends quiz_default_questiontype { } function print_question_formulation_and_controls(&$question, &$state, $cmoptions, $options) { + global $CFG; $subquestions = $state->options->subquestions; $correctanswers = $this->get_correct_responses($question, $state); $nameprefix = $question->name_prefix; @@ -227,22 +228,19 @@ class quiz_match_qtype extends quiz_default_questiontype { // Shuffle the answers $answers = draw_rand_array($answers, count($answers)); - // Print question text and possible image - if (!empty($question->questiontext)) { - echo format_text($question->questiontext, - $question->questiontextformat, - NULL, $cmoptions->course); - } - quiz_print_possible_question_image($question, $cmoptions->course); + // Print formulation + $questiontext = format_text($question->questiontext, + $question->questiontextformat, + NULL, $cmoptions->course); + $image = get_question_image($question, $cmoptions->course); ///// Print the input controls ////// echo ''; foreach ($subquestions as $key => $subquestion) { + /// Subquestion text: - echo ''; /// Drop-down list: $menuname = $nameprefix.$subquestion->id; @@ -252,14 +250,13 @@ class quiz_match_qtype extends quiz_default_questiontype { and $options->correct_responses and isset($correctanswers[$subquestion->id]) and ($correctanswers[$subquestion->id] == $response)) { - $class = ' class="highlight" '; + $a->class = ' class="highlight" '; } else { - $class = ''; + $a->class = ''; } - echo "'; + + $anss[] = clone($a); } - echo '
'; - echo format_text($subquestion->questiontext, + $a->text = format_text($subquestion->questiontext, $question->questiontextformat, NULL, $cmoptions->course); - echo '"; - - choose_from_menu($answers, $menuname, $response, 'choose', '', 0, - false, $options->readonly); + + $a->control = choose_from_menu($answers, $menuname, $response, 'choose', '', 0, + true, $options->readonly); // Neither the editing interface or the database allow to provide // fedback for this question type. @@ -270,9 +267,10 @@ class quiz_match_qtype extends quiz_default_questiontype { // && !empty($subquestion->options->answers[$responses[$key]]->feedback)) { // quiz_print_comment($subquestion->options->answers[$responses[$key]]->feedback); //} - echo '
'; + include("$CFG->dirroot/question/questiontypes/match/display.html"); } function grade_responses(&$question, &$state, $cmoptions) { diff --git a/question/questiontypes/numerical/questiontype.php b/question/questiontypes/numerical/questiontype.php index f02d45fbbb9..48662dd4aae 100644 --- a/question/questiontypes/numerical/questiontype.php +++ b/question/questiontypes/numerical/questiontype.php @@ -273,54 +273,6 @@ class quiz_numerical_qtype extends quiz_shortanswer_qtype { return false; } - function print_question_formulation_and_controls(&$question, &$state, $cmoptions, $options) { - /// This implementation is very similar to the code used by question type SHORTANSWER - - $answers = &$question->options->answers; - $correctanswers = $this->get_correct_responses($question, $state); - $readonly = empty($options->readonly) ? '' : 'readonly="readonly"'; - $nameprefix = $question->name_prefix; - - /// Print question text and media - - echo format_text($question->questiontext, - $question->questiontextformat, - NULL, $cmoptions->course); - quiz_print_possible_question_image($question, $cmoptions->course); - - /// Print input controls - - $stranswer = get_string("answer", "quiz"); - if (isset($state->responses[''])) { - $value = ' value="'.htmlSpecialChars($state->responses['']).'" '; - } else { - $value = ' value="" '; - } - $inputname = ' name="'.$nameprefix.'" '; - echo "

$stranswer:

"; - - if ($options->feedback) { - foreach($answers as $answer) { - if($this->test_response($question, $state, $answer)) { - quiz_print_comment($answer->feedback); - break; - } - } - } - - if ($options->readonly && $options->correct_responses) { - $delimiter = ''; - $correct = ''; - if ($correctanswers) { - foreach ($correctanswers as $correctanswer) { - $correct .= $delimiter.$correctanswer; - $delimiter = ', '; - } - } - quiz_print_correctanswer($correct); - } - } - function grade_responses(&$question, &$state, $cmoptions) { $answers = &$question->options->answers; $state->raw_grade = 0; diff --git a/question/questiontypes/questiontype.php b/question/questiontypes/questiontype.php index 7d1a34fa47b..d1b6713d4c6 100644 --- a/question/questiontypes/questiontype.php +++ b/question/questiontypes/questiontype.php @@ -444,14 +444,7 @@ class quiz_default_questiontype { function print_question(&$question, &$state, $number, $cmoptions, $options) { /* The default implementation should work for most question types provided the member functions it calls are overridden where required. - The question number is printed in the first cell of a table. - - The main content is printed below in the top row of the second column - using {@link print_question_formulation_and_controls}. - The grading details are printed in the second row in the second column - using {@print_question_grading_details}. - The {@link print_question_submit_buttons} member is invoked to add a third - row containing the submit button(s) when $options->readonly is false. */ + The layout is determined by the template question.html */ global $CFG; // For editing teachers print a link to an editing popup window @@ -728,6 +721,18 @@ class quiz_default_questiontype { return $state->responses == $teststate->responses; } + /** + * Checks whether a response matches a given answer + * + * This method only applies to questions that use teacher-defined answers + * + * @return boolean + */ + function test_response(&$question, &$state, $answer) { + $response = isset($state->responses['']) ? $state->responses[''] : ''; + return ($response == $answer->answer); + } + /** * Performs response processing and grading * diff --git a/question/questiontypes/rqp/questiontype.php b/question/questiontypes/rqp/questiontype.php index c035cd04714..5681e4f291a 100644 --- a/question/questiontypes/rqp/questiontype.php +++ b/question/questiontypes/rqp/questiontype.php @@ -327,6 +327,7 @@ class quiz_rqp_qtype extends quiz_default_questiontype { // them yet. // Remove the render output created during grading (if any) unset($state->options->renderoutput); + $this->print_question_submit_buttons($question, $state, $cmoptions, $options); } /** diff --git a/question/questiontypes/shortanswer/questiontype.php b/question/questiontypes/shortanswer/questiontype.php index be50d633364..6481f8b161a 100644 --- a/question/questiontypes/shortanswer/questiontype.php +++ b/question/questiontypes/shortanswer/questiontype.php @@ -144,11 +144,8 @@ class quiz_shortanswer_qtype extends quiz_default_questiontype { $feedback = ''; if ($options->feedback) { - $testedstate = clone($state); - $teststate = clone($state); foreach($answers as $answer) { - $teststate->responses[''] = trim($answer->answer); - if($answer->feedback and $this->compare_responses($question, $testedstate, $teststate)) { + if($answer->feedback and $this->test_response($question, $state, $answer)) { $feedback = format_text($answer->feedback, true, false); break; }