MDL-47494 ddmarker: NOBUG fixed some problems with response summaries
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user