MDL-63185 core_question: add callback to some question types

Part of MDL-62610
This commit is contained in:
Simey Lameze 2018-09-27 09:43:09 +08:00
parent 3c4ff02e41
commit 71fc74cee5
3 changed files with 30 additions and 0 deletions

View File

@ -89,6 +89,14 @@ class qtype_essay_question extends question_with_responses {
}
}
public function un_summarise_response(string $summary) {
if (!empty($summary)) {
return ['answer' => $summary];
} else {
return [];
}
}
public function get_correct_response() {
return null;
}

View File

@ -85,6 +85,20 @@ class qtype_numerical_question extends question_graded_automatically {
return $resp;
}
public function un_summarise_response(string $response) {
if (!empty($response)) {
$resp = $response;
} else {
$resp = null;
}
if ($this->has_separate_unit_field() && !empty($response)) {
$resp = $this->ap->add_unit($resp, $response);
}
return $resp;
}
public function is_gradable_response(array $response) {
return array_key_exists('answer', $response) &&
($response['answer'] || $response['answer'] === '0' || $response['answer'] === 0);

View File

@ -57,6 +57,14 @@ class qtype_shortanswer_question extends question_graded_by_strategy
}
}
public function un_summarise_response(string $summary) {
if (!empty($summary)) {
return ['answer' => $summary];
} else {
return [];
}
}
public function is_complete_response(array $response) {
return array_key_exists('answer', $response) &&
($response['answer'] || $response['answer'] === '0');