From: jamiesensei Date: Fri, 28 Nov 2008 10:14:19 +0000 (+0000) Subject: MDL-12418 "Item Analysis shows duplicate responses for Multiple Choice questions... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=2280e147c56230ea221f60921ae54bfe81283caa;p=moodle.git MDL-12418 "Item Analysis shows duplicate responses for Multiple Choice questions with LaTeX in answers" This problem was caused by the formatting of questions in get_actual_responses. Now formatting is done in response_summary rather than get_actual_response which returns an array of unformatted strings. Have fixed the formatting in responses report and in statistics report to use the correct formatting for the question type. Created new functions format_responses and format_response. format_responses works on an array and normally just walks through the array calling format_response. --- diff --git a/mod/quiz/report/responses/responses_table.php b/mod/quiz/report/responses/responses_table.php index cded6554a8..640a6a9155 100644 --- a/mod/quiz/report/responses/responses_table.php +++ b/mod/quiz/report/responses/responses_table.php @@ -137,6 +137,7 @@ class quiz_report_responses_table extends table_sql { } } function other_cols($colname, $attempt){ + global $QTYPES; static $states =array(); if (preg_match('/^qsanswer([0-9]+)$/', $colname, $matches)){ if ($attempt->uniqueid == 0) { @@ -152,41 +153,37 @@ class quiz_report_responses_table extends table_sql { $question = $this->questions[$questionid]; restore_question_state($question, $stateforqinattempt); - if ($responses = get_question_actual_response($question, $stateforqinattempt)){ - $response = (!empty($responses)? implode('; ',$responses) : '-'); + if (!$this->is_downloading() || $this->is_downloading() == 'xhtml'){ + $formathtml = true; } else { - $response = ''; + $formathtml = false; } + + $summary = $QTYPES[$question->qtype]->response_summary($question, $stateforqinattempt, + QUIZ_REPORT_RESPONSES_MAX_LEN_TO_DISPLAY, $formathtml); if (!$this->is_downloading()) { - if ($response){ - $format_options = new stdClass; - $format_options->para = false; - $format_options->newlines = false; - $response = format_text($response, FORMAT_MOODLE, $format_options); - if (strlen($response) > QUIZ_REPORT_RESPONSES_MAX_LEN_TO_DISPLAY){ - $response = shorten_text($response, QUIZ_REPORT_RESPONSES_MAX_LEN_TO_DISPLAY); - } - $response = link_to_popup_window('/mod/quiz/reviewquestion.php?attempt=' . + if ($summary){ + $summary = link_to_popup_window('/mod/quiz/reviewquestion.php?attempt=' . $attempt->attempt . '&question=' . $question->id, - 'reviewquestion', $response, 450, 650, get_string('reviewresponse', 'quiz'), + 'reviewquestion', $summary, 450, 650, get_string('reviewresponse', 'quiz'), 'none', true); if (question_state_is_graded($stateforqinattempt) - && ($this->questions[$questionid]->maxgrade != 0)){ + && ($question->maxgrade != 0)){ $grade = $stateforqinattempt->grade - / $this->questions[$questionid]->maxgrade; + / $question->maxgrade; $qclass = question_get_feedback_class($grade); $feedbackimg = question_get_feedback_image($grade); $questionclass = "que"; - return "".$response."$feedbackimg"; + return "".$summary."$feedbackimg"; } else { - return $response; + return $summary; } } else { return ''; } } else { - return $this->format_text($response); + return $summary; } } else { return NULL; diff --git a/mod/quiz/report/statistics/report.php b/mod/quiz/report/statistics/report.php index 5e2322223e..7d1ddfa58e 100644 --- a/mod/quiz/report/statistics/report.php +++ b/mod/quiz/report/statistics/report.php @@ -228,7 +228,7 @@ class quiz_statistics_report extends quiz_default_report { print_heading(get_string('questioninformation', 'quiz_statistics')); print_table($questioninfotable); - print_box(format_text($question->questiontext).$actions, 'boxaligncenter generalbox boxwidthnormal mdl-align'); + print_box(format_text($question->questiontext, $question->questiontextformat).$actions, 'boxaligncenter generalbox boxwidthnormal mdl-align'); print_heading(get_string('questionstatistics', 'quiz_statistics')); print_table($questionstatstable); diff --git a/mod/quiz/report/statistics/statistics_question_table.php b/mod/quiz/report/statistics/statistics_question_table.php index aeb3cc39bc..90e2474f41 100644 --- a/mod/quiz/report/statistics/statistics_question_table.php +++ b/mod/quiz/report/statistics/statistics_question_table.php @@ -57,6 +57,15 @@ class quiz_report_statistics_question_table extends flexible_table { parent::setup(); } + function col_response($response){ + global $QTYPES; + if (!$this->is_downloading() || $this->is_downloading() == 'xhtml'){ + return $QTYPES[$this->question->qtype]->format_response($response->response, $this->question->questiontextformat); + } else { + return $response->response; + } + } + function col_subq($response){ return $response->subq; } diff --git a/question/type/calculated/questiontype.php b/question/type/calculated/questiontype.php index 5c330b9ff6..2a91bf8a72 100644 --- a/question/type/calculated/questiontype.php +++ b/question/type/calculated/questiontype.php @@ -695,7 +695,7 @@ class question_calculated_qtype extends default_questiontype { return $virtualqtype->grade_responses($numericalquestion, $state, $cmoptions) ; } - function response_summary($question, $state, $length=80) { + function response_summary($question, $state, $length=80, $formatting=true) { // The actual response is the bit after the hyphen return substr($state->answer, strpos($state->answer, '-')+1, $length); } diff --git a/question/type/essay/questiontype.php b/question/type/essay/questiontype.php index 5fe289e710..ac0c0d4335 100644 --- a/question/type/essay/questiontype.php +++ b/question/type/essay/questiontype.php @@ -116,11 +116,6 @@ class question_essay_qtype extends default_questiontype { return true; } - function response_summary($question, $state, $length = 80) { - $responses = $this->get_actual_response($question, $state); - $response = reset($responses); - return shorten_text($response, $length); - } /** * Backup the extra information specific to an essay question - over and above diff --git a/question/type/match/questiontype.php b/question/type/match/questiontype.php index b5d62c89aa..c03874adff 100644 --- a/question/type/match/questiontype.php +++ b/question/type/match/questiontype.php @@ -465,10 +465,7 @@ class question_match_qtype extends default_questiontype { } return $responsedetails; } - - function response_summary($question, $state, $length=80) { - return shorten_text(implode(', ', $this->get_actual_response($question, $state)), $length); - } + /** * @param object $question diff --git a/question/type/multianswer/questiontype.php b/question/type/multianswer/questiontype.php index 0842b5261d..e9ac4e03c3 100644 --- a/question/type/multianswer/questiontype.php +++ b/question/type/multianswer/questiontype.php @@ -653,9 +653,7 @@ class embedded_cloze_qtype extends default_questiontype { $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); + $responses[$key] = implode(';', $correct); } return $responses; } diff --git a/question/type/multichoice/questiontype.php b/question/type/multichoice/questiontype.php index 6e64dd86d9..c09044109c 100644 --- a/question/type/multichoice/questiontype.php +++ b/question/type/multichoice/questiontype.php @@ -387,7 +387,7 @@ class question_multichoice_qtype extends default_questiontype { if (!empty($state->responses)) { foreach ($state->responses as $aid =>$rid){ if (!empty($answers[$rid])) { - $responses[] = $this->format_text($answers[$rid]->answer, $question->questiontextformat); + $responses[] = $answers[$rid]->answer; } } } else { @@ -396,8 +396,9 @@ class question_multichoice_qtype extends default_questiontype { return $responses; } - function response_summary($question, $state, $length = 80) { - return implode(',', $this->get_actual_response($question, $state)); + + function format_response($response, $format){ + return $this->format_text($response, $format); } /** * @param object $question diff --git a/question/type/questiontype.php b/question/type/questiontype.php index 6015120879..8b5f11e7dd 100644 --- a/question/type/questiontype.php +++ b/question/type/questiontype.php @@ -725,9 +725,9 @@ class default_questiontype { function get_random_guess_score($question) { return 0; } - /** + /** * Return the actual response to the question in a given state - * for the question. + * for the question. Text is not yet formatted for output. * * @return mixed An array containing the response or reponses (multiple answer, match) * given by the user in a particular attempt. @@ -1233,25 +1233,40 @@ class default_questiontype { * * This function returns a short string of no more than a given length that * summarizes the student's response in the given $state. This is used for - * example in the response history table. This string should already be, - * for output. + * example in the response history table. This string should already be + * formatted for output. * @return string The summary of the student response * @param object $question * @param object $state The state whose responses are to be summarized * @param int $length The maximum length of the returned string */ - function response_summary($question, $state, $length=80) { + function response_summary($question, $state, $length=80, $formatting=true) { // This should almost certainly be overridden $responses = $this->get_actual_response($question, $state); - if (empty($responses) || !is_array($responses)) { - $responses = array(); - } - if (is_array($responses)) { - $responses = implode(',', array_map('s', $responses)); + if ($formatting){ + $responses = $this->format_responses($responses, $question->questiontextformat); } + $responses = implode(';', $responses); return shorten_text($responses, $length); } - + /** + * @param array responses is an array of responses. + * @return formatted responses + */ + function format_responses($responses, $format){ + $toreturn = array(); + foreach ($responses as $response){ + $toreturn[] = $this->format_response($response, $format); + } + return $toreturn; + } + /** + * @param string response is a response. + * @return formatted response + */ + function format_response($response, $format){ + return s($response); + } /** * Renders the question for printing and returns the LaTeX source produced * diff --git a/question/type/truefalse/questiontype.php b/question/type/truefalse/questiontype.php index 305dc1ad5e..7d1a7b6664 100644 --- a/question/type/truefalse/questiontype.php +++ b/question/type/truefalse/questiontype.php @@ -228,15 +228,6 @@ class question_truefalse_qtype extends default_questiontype { return true; } - function response_summary($question, $state, $length=80) { - if (isset($question->options->answers[$state->answer])) { - $responses = $question->options->answers[$state->answer]->answer; - } else { - $responses = ''; - } - return $responses; - } - function get_actual_response($question, $state) { if (isset($question->options->answers[$state->responses['']])) { $responses[] = $question->options->answers[$state->responses['']]->answer;