From 597a696a4a351029b86e292b7f137d8c71d40c8f Mon Sep 17 00:00:00 2001 From: Jamie Pratt Date: Fri, 18 Nov 2011 12:34:00 +0700 Subject: [PATCH 1/4] MDL-47494 ddmarker: NOBUG fixed some problems with response summaries --- question/type/ddmarker/question.php | 49 ++++++++++++++++++------- question/type/ddmarker/questiontype.php | 33 +++++++++++++++++ 2 files changed, 69 insertions(+), 13 deletions(-) diff --git a/question/type/ddmarker/question.php b/question/type/ddmarker/question.php index 139ec5b3a42..20cca84915e 100644 --- a/question/type/ddmarker/question.php +++ b/question/type/ddmarker/question.php @@ -299,20 +299,18 @@ class qtype_ddmarker_question extends qtype_ddtoimage_question_base { public function classify_response(array $response) { $parts = array(); - foreach ($this->places as $place => $group) { - if (!array_key_exists($this->field($place), $response) || - !$response[$this->field($place)]) { - $parts[$place] = question_classified_response::no_response(); - continue; + $hits = $this->choose_hits($response); + foreach ($this->places as $placeno => $place) { + if (isset($hits[$placeno])) { + $shuffledchoiceno = $this->get_right_choice_for($placeno); + $choiceno = $this->get_selected_choice(1, $shuffledchoiceno); + $parts[$placeno] = new question_classified_response( + $choiceno, + $this->choices[$choiceno]->summarise(), + 1 / count($this->places)); + } else { + $parts[$placeno] = question_classified_response::no_response(); } - - $fieldname = $this->field($place); - $choiceno = $this->choiceorder[$group][$response[$fieldname]]; - $choice = $this->choices[$group][$choiceno]; - $parts[$place] = new question_classified_response( - $choiceno, html_to_text($choice->text, 0, false), - ($this->get_right_choice_for($place) == $response[$fieldname]) - / count($this->places)); } return $parts; } @@ -338,6 +336,31 @@ class qtype_ddmarker_question extends qtype_ddtoimage_question_base { } return $response; } + + public function get_right_answer_summary() { + $placesummaries = array(); + foreach ($this->places as $placeno => $place) { + $shuffledchoiceno = $this->get_right_choice_for($placeno); + $choice = $this->get_selected_choice(1, $shuffledchoiceno); + $placesummaries[] = '{'.$place->summarise().' -> '.$choice->summarise().'}'; + } + return join(', ', $placesummaries); + } + + public function summarise_response(array $response) { + $hits = $this->choose_hits($response); + $goodhits = array(); + foreach ($this->places as $placeno => $place) { + if (isset($hits[$placeno])) { + $choice = $this->choices[$this->get_right_choice_for($placeno)]; + $goodhits[] = "{".$place->summarise()." -> ". $choice->summarise(). "}"; + } + } + if (count($goodhits)) { + return null; + } + return implode(', ', $goodhits); + } } /** diff --git a/question/type/ddmarker/questiontype.php b/question/type/ddmarker/questiontype.php index 932ad490d74..baabc417938 100644 --- a/question/type/ddmarker/questiontype.php +++ b/question/type/ddmarker/questiontype.php @@ -245,4 +245,37 @@ class qtype_ddmarker extends qtype_ddtoimage_base { $question->showmisplaced = $questiondata->options->showmisplaced; } + public function move_files($questionid, $oldcontextid, $newcontextid) { + global $DB; + $fs = get_file_storage(); + + parent::move_files($questionid, $oldcontextid, $newcontextid); + $fs->move_area_files_to_new_context($oldcontextid, + $newcontextid, 'qtype_ddmarker', 'bgimage', $questionid); + + + $this->move_files_in_combined_feedback($questionid, $oldcontextid, $newcontextid); + } + + /** + * Delete all the files belonging to this question. + * @param int $questionid the question being deleted. + * @param int $contextid the context the question is in. + */ + + protected function delete_files($questionid, $contextid) { + global $DB; + $fs = get_file_storage(); + + parent::delete_files($questionid, $contextid); + + $dragids = $DB->get_records_menu('qtype_ddimageortext_drags', + array('questionid' => $questionid), 'id', 'id,1'); + foreach ($dragids as $dragid => $notused) { + $fs->delete_area_files($contextid, 'qtype_ddimageortext', 'dragimage', $dragid); + } + + $this->delete_files_in_combined_feedback($questionid, $contextid); + } + } From 6d6cda8902692b8e064315b5e6e34ab6b3d21384 Mon Sep 17 00:00:00 2001 From: Jamie Pratt Date: Fri, 18 Nov 2011 13:12:48 +0700 Subject: [PATCH 2/4] MDL-47494 ddmarker: NOBUG fix for notices seen when pressing 'fill in correct response' in preview --- question/type/ddmarker/question.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/question/type/ddmarker/question.php b/question/type/ddmarker/question.php index 20cca84915e..0b6eb5fc82f 100644 --- a/question/type/ddmarker/question.php +++ b/question/type/ddmarker/question.php @@ -71,8 +71,9 @@ class qtype_ddmarker_question extends qtype_ddtoimage_question_base { return $vars; } public function is_complete_response(array $response) { - foreach ($this->choices[1] as $choice => $notused) { - if ('' != trim($response[$this->choice($choice)])) { + foreach ($this->choices[1] as $choiceno => $notused) { + if (isset($response[$this->choice($choiceno)]) + && '' != trim($response[$this->choice($choiceno)])) { return true; } } @@ -352,7 +353,8 @@ class qtype_ddmarker_question extends qtype_ddtoimage_question_base { $goodhits = array(); foreach ($this->places as $placeno => $place) { if (isset($hits[$placeno])) { - $choice = $this->choices[$this->get_right_choice_for($placeno)]; + $shuffledchoiceno = $this->get_right_choice_for($placeno); + $choice = $this->get_selected_choice(1, $shuffledchoiceno); $goodhits[] = "{".$place->summarise()." -> ". $choice->summarise(). "}"; } } From 6f6d6e2fbed319a8ba1ee5d894158cffb9d74561 Mon Sep 17 00:00:00 2001 From: Jamie Pratt Date: Fri, 18 Nov 2011 13:17:27 +0700 Subject: [PATCH 3/4] MDL-47494 ddmarker: NOBUG fixed notice when hints are displayed --- question/type/ddmarker/renderer.php | 1 + 1 file changed, 1 insertion(+) diff --git a/question/type/ddmarker/renderer.php b/question/type/ddmarker/renderer.php index 56e35804426..d2b3d4e9413 100644 --- a/question/type/ddmarker/renderer.php +++ b/question/type/ddmarker/renderer.php @@ -131,6 +131,7 @@ class qtype_ddmarker_renderer extends qtype_ddtoimage_renderer_base { } protected function hint(question_attempt $qa, question_hint $hint) { + $output = ''; $question = $qa->get_question(); $response = $qa->get_last_qt_data(); if ($hint->statewhichincorrect) { From 8ed8434c6364fa8ab6ffe94f80a27d86ec35360f Mon Sep 17 00:00:00 2001 From: Jamie Pratt Date: Fri, 18 Nov 2011 13:19:33 +0700 Subject: [PATCH 4/4] MDL-47494 ddmarker: NOBUG string change --- question/type/ddmarker/lang/en/qtype_ddmarker.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/question/type/ddmarker/lang/en/qtype_ddmarker.php b/question/type/ddmarker/lang/en/qtype_ddmarker.php index 4ed2e888a61..8bf6b42f6da 100644 --- a/question/type/ddmarker/lang/en/qtype_ddmarker.php +++ b/question/type/ddmarker/lang/en/qtype_ddmarker.php @@ -42,7 +42,7 @@ $string['dropzone'] = 'Drop zone {$a}'; $string['dropzoneheader'] = 'Drop zones'; $string['editingddmarker'] = 'Editing drag and drop markers'; $string['followingarewrong'] = 'The following markers have been placed in the wrong area : {$a}.'; -$string['followingarewrongandhighlighted'] = 'The following markers need to be placed in the correct area : {$a}. The areas they should have been placed in are shown above.
Click on the markers above to see the areas they should have been placed in highlighted.'; +$string['followingarewrongandhighlighted'] = 'The following markers were not placed in the correct area : {$a}. The areas they should have been placed in are shown above.
Click on the markers above to see the areas they should have been placed in highlighted.'; $string['formerror_nobgimage'] = 'You need to select an image to use as the background for the drag and drop area.'; $string['formerror_noitemselected'] = 'You have specified a drop zone but not chosen a marker that must be dragged to the zone'; $string['formerror_nosemicolons'] = 'There are no semicolons in your coordinates string. Your coordinates for a {$a->shape} should be expressed as - {$a->coordsstring}.';