Skip to content

Commit

Permalink
MDL-47494 ddmarker: NOBUG implemented highlighting of incorrectly dra…
Browse files Browse the repository at this point in the history
…gged drag items.
  • Loading branch information
jamiepratt committed Nov 17, 2011
1 parent 4396425 commit 70c434e
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 16 deletions.
3 changes: 2 additions & 1 deletion question/type/ddmarker/lang/en/qtype_ddmarker.php
Expand Up @@ -41,7 +41,8 @@
$string['dropzone'] = 'Drop zone {$a}';
$string['dropzoneheader'] = 'Drop zones';
$string['editingddmarker'] = 'Editing drag and drop markers';
$string['followingarewrong'] = 'The following markers have not been dragged to the correct drop zone : {$a}. The drop zones they should have been dragged to are shown above.<br />Click on the markers above to see the drop zones they should have been dropped in highlighted.';
$string['followingarewrong'] = 'The following markers have been dragged to the wrong position : {$a}.';
$string['followingarewrongandhighlighted'] = 'The following markers need to be dragged to the correct drop zone : {$a}. The drop zones they should have been dragged to are shown above.<br />Click on the markers above to see the drop zones they should have been dropped 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}.';
Expand Down
29 changes: 18 additions & 11 deletions question/type/ddmarker/question.php
Expand Up @@ -262,6 +262,24 @@ public function clear_wrong_from_response(array $response) {
}
return $cleanedresponse;
}
public function get_wrong_drags(array $response) {
$hits = $this->choose_hits($response);
$wrong = array();
foreach ($response as $choicekey => $coords) {
$choice = (int)substr($choicekey, 1);
if ($coords != '') {
$coordparts = explode(';', $coords);
foreach ($coordparts as $itemno => $coord) {
if (!in_array("$choice $itemno", $hits)) {
$wrong[] = $this->get_selected_choice(1, $choice)->text;
}
}
}
}
return $wrong;
}


public function get_drop_zones_without_hit(array $response) {
$hits = $this->choose_hits($response);

Expand All @@ -278,18 +296,7 @@ public function get_drop_zones_without_hit(array $response) {
}
return $nohits;
}
public function wrong_parts(array $response) {
$hits = $this->choose_hits($response);

$wrong = array();
foreach ($this->places as $placeno => $place) {
$choice = $this->get_right_choice_for($placeno);
if (!isset($hits[$placeno])) {
$wrong[] = $this->choices[1][$choice]->text;
}
}
return $wrong;
}
public function classify_response(array $response) {
$parts = array();
foreach ($this->places as $place => $group) {
Expand Down
26 changes: 22 additions & 4 deletions question/type/ddmarker/renderer.php
Expand Up @@ -106,16 +106,17 @@ public function formulation_and_controls(question_attempt $qa,
}

if ($question->showmisplaced && $qa->get_state()->is_finished()) {
$wrongparts = $question->wrong_parts($response);
$wrongparts = $question->get_drop_zones_without_hit($response);
$wrongpartsstring = '';
foreach($wrongparts as $wrongpart) {
$wrongpartsstring .= html_writer::nonempty_tag('span',
$wrongpart, array('class' => 'wrongpart'));
$wrongpart->markertext, array('class' => 'wrongpart'));
}
$output .= html_writer::nonempty_tag('span',
get_string('followingarewrong', 'qtype_ddmarker', $wrongpartsstring),
array('class' => 'wrongparts'));
get_string('followingarewrongandhighlighted', 'qtype_ddmarker', $wrongpartsstring),
array('class' => 'wrongparts'));
}

$output .= html_writer::tag('div', $hiddenfields, array('class'=>'ddform'));
return $output;
}
Expand All @@ -128,4 +129,21 @@ protected function hidden_field_choice(question_attempt $qa, $choiceno, $infinit
list(,$html) = $this->hidden_field_for_qt_var($qa, $varname, null, $classes);
return $html;
}

protected function hint(question_attempt $qa, question_hint $hint) {
$question = $qa->get_question();
$response = $qa->get_last_qt_data();
if ($hint->statewhichincorrect) {
$wrongparts = $question->get_wrong_drags($response);
$wrongpartsstring = '';
foreach($wrongparts as $wrongpart) {
$wrongpartsstring .= html_writer::nonempty_tag('span',
$wrongpart, array('class' => 'wrongpart'));
}
$output .= html_writer::nonempty_tag('span',
get_string('followingarewrong', 'qtype_ddmarker', $wrongpartsstring),
array('class' => 'wrongparts'));
}
return $output . parent::hint($qa, $hint);
}
}

0 comments on commit 70c434e

Please sign in to comment.