MDL-47494 ddimageortext: NOBUG removing 'correct answer is' textual feedback to student as it is

unintelligible and improving summarising of response. Fixed random guess
score in statistics that was showing zero. Fixed statistics for question
parts.
This commit is contained in:
Jamie Pratt
2011-08-21 20:57:29 +07:00
parent da102a7fe4
commit 8bfaad3b5b
4 changed files with 97 additions and 20 deletions
@@ -53,5 +53,9 @@ $string['previewarea'] = 'Preview area -';
$string['previewareaheader'] = 'Preview';
$string['previewareamessage'] = '<ul><li>Select a background image file.</li><li>Select draggable images.</li><li>And define drop zones by selecting an image that the student must drag to the drop zone and drag it to where the student should drag it too.</li></ul>';
$string['shuffleimages'] = 'Shuffle Draggable Images';
$string['summarisechoice'] = '{$a->no}. {$a->text}';
$string['summariseplace'] = '{$a->no}. {$a->text}';
$string['summarisechoiceno'] = 'Image {$a}';
$string['summariseplaceno'] = 'Drop zone {$a}';
$string['xleft'] = 'Left';
$string['ytop'] = 'Top';
+57 -4
View File
@@ -59,9 +59,25 @@ class qtype_ddimagetoimage_question extends qtype_gapselect_question_base {
$allblank = true;
foreach ($this->places as $placeno => $place) {
if (array_key_exists($this->field($placeno), $response) &&
$response[$this->field($placeno)]) {
$choices[] = '{' . html_to_text($this->get_selected_choice(
$place->group, $response[$this->field($placeno)])->text, 0, false) . '}';
$response[$this->field($placeno)]) {
$selected = $this->get_selected_choice($place->group,
$response[$this->field($placeno)]);
if (trim($selected->text) !='') {
$summarisechoice =
get_string('summarisechoice', 'qtype_ddimagetoimage', $selected);
} else {
$summarisechoice =
get_string('summarisechoiceno', 'qtype_ddimagetoimage', $selected->no);
}
$place->no = $placeno;
if (trim($place->text) !='') {
$summariseplace =
get_string('summariseplace', 'qtype_ddimagetoimage', $place);
} else {
$summariseplace =
get_string('summariseplaceno', 'qtype_ddimagetoimage', $place->no);
}
$choices[] = "$summariseplace -> {{$summarisechoice}}";
$allblank = false;
} else {
$choices[] = '{}';
@@ -105,6 +121,43 @@ class qtype_ddimagetoimage_question extends qtype_gapselect_question_base {
}
return get_string('pleasedraganimagetoeachdropregion', 'qtype_ddimagetoimage');
}
public function classify_response(array $response) {
$parts = array();
foreach ($this->places as $placeno => $place) {
$group = $place->group;
if (!array_key_exists($this->field($placeno), $response) ||
!$response[$this->field($placeno)]) {
$parts[$placeno] = question_classified_response::no_response();
continue;
}
$fieldname = $this->field($placeno);
$choiceno = $this->choiceorder[$group][$response[$fieldname]];
$choice = $this->choices[$group][$choiceno];
if (trim($choice->text) !='') {
$summarisechoice =
get_string('summarisechoice', 'qtype_ddimagetoimage', $choice);
} else {
$summarisechoice =
get_string('summarisechoiceno', 'qtype_ddimagetoimage', $choice->no);
}
$correct = $this->get_right_choice_for($placeno) == $response[$fieldname];
$parts[$placeno] = new question_classified_response(
$choiceno, $summarisechoice, $correct?1:0);
}
return $parts;
}
public function get_random_guess_score() {
$accum = 0;
foreach ($this->places as $place) {
$accum += 1 / count($this->choices[$place->group]);
}
return $accum / count($this->places);
}
}
@@ -116,7 +169,7 @@ class qtype_ddimagetoimage_question extends qtype_gapselect_question_base {
*/
class qtype_ddimagetoimage_drag_item {
public $id;
public $alttextlabel;
public $text;
public $no;
public $group;
public $isinfinite;
@@ -416,4 +416,39 @@ class qtype_ddimagetoimage extends question_type {
}
return $string;
}
public function get_possible_responses($questiondata) {
$question = $this->make_question($questiondata);
$parts = array();
foreach ($question->places as $placeno => $place) {
$group = $place->group;
$choices = array();
foreach ($question->choices[$group] as $i => $choice) {
if (trim($choice->text) !='') {
$summarisechoice =
get_string('summarisechoice', 'qtype_ddimagetoimage', $choice);
} else {
$summarisechoice =
get_string('summarisechoiceno', 'qtype_ddimagetoimage', $choice->no);
}
$correct = $question->rightchoices[$placeno] == $i;
$choices[$choice->no] = new question_possible_response(
$summarisechoice,
$correct?1:0);
}
$choices[null] = question_possible_response::no_response();
$parts[$placeno] = $choices;
}
return $parts;
}
public function get_random_guess_score($questiondata) {
$question = $this->make_question($questiondata);
return $question->get_random_guess_score();
}
}
+1 -16
View File
@@ -165,21 +165,6 @@ class qtype_ddimagetoimage_renderer extends qtype_with_combined_feedback_rendere
}
public function correct_response(question_attempt $qa) {
$question = $qa->get_question();
$correctanswer = '';
foreach ($question->places as $i => $place) {
$choice = $question->choices[$place->group][$question->rightchoices[$i]];
if ($choice->text != '') {
$text = $choice->text;
} else {
$text = get_string('nolabel', 'qtype_ddimagetoimage');
}
$correctanswer .= '[' . str_replace('-', '&#x2011;', $text) . ']';
}
if (!empty($correctanswer)) {
return get_string('correctansweris', 'qtype_gapselect', $correctanswer);
}
return '';
}
}