From da22c0127ba3472919797465e33026537dd9b508 Mon Sep 17 00:00:00 2001 From: M Kassaei Date: Fri, 20 Jan 2012 11:59:14 +0000 Subject: [PATCH] MDL-31306 question preview: disable 'Fill correct' for qtypes that can't --- question/engine/questionattempt.php | 8 ++++++-- question/engine/questionusage.php | 1 + question/preview.php | 4 +++- question/type/questionbase.php | 5 +++-- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/question/engine/questionattempt.php b/question/engine/questionattempt.php index 6d4811e8cec..f31ff3a59e5 100644 --- a/question/engine/questionattempt.php +++ b/question/engine/questionattempt.php @@ -987,11 +987,15 @@ class question_attempt { /** * Get a set of response data for this question attempt that would get the - * best possible mark. - * @return array name => value pairs that could be passed to {@link process_action()}. + * best possible mark. If it is not possible to compute a correct + * response, this method should return null. + * @return array|null name => value pairs that could be passed to {@link process_action()}. */ public function get_correct_response() { $response = $this->question->get_correct_response(); + if (is_null($response)) { + return null; + } $imvars = $this->behaviour->get_correct_response(); foreach ($imvars as $name => $value) { $response['-' . $name] = $value; diff --git a/question/engine/questionusage.php b/question/engine/questionusage.php index 6548bff073d..33aeb5fd019 100644 --- a/question/engine/questionusage.php +++ b/question/engine/questionusage.php @@ -582,6 +582,7 @@ class question_usage_by_activity { /** * Get the correct response to a particular question. Passing the results of * this method to {@link process_action()} will probably result in full marks. + * If it is not possible to compute a correct response, this method should return null. * @param int $slot the number used to identify this question within this usage. * @return array that constitutes a correct response to this question. */ diff --git a/question/preview.php b/question/preview.php index a50f9cc3387..8b62e43f66c 100644 --- a/question/preview.php +++ b/question/preview.php @@ -211,7 +211,9 @@ $filldisabled = ''; if ($quba->get_question_state($slot)->is_finished()) { $finishdisabled = ' disabled="disabled"'; $filldisabled = ' disabled="disabled"'; -} else if (is_null($quba->get_correct_response($slot))) { +} +// If question type cannot give us a correct response, disable this button. +if (is_null($quba->get_correct_response($slot))) { $filldisabled = ' disabled="disabled"'; } if (!$previewid) { diff --git a/question/type/questionbase.php b/question/type/questionbase.php index 062c9dd68f6..f2d0a06b9c1 100644 --- a/question/type/questionbase.php +++ b/question/type/questionbase.php @@ -262,9 +262,10 @@ abstract class question_definition { /** * What data would need to be submitted to get this question correct. * If there is more than one correct answer, this method should just - * return one possibility. + * return one possibility. If it is not possible to compute a correct + * response, this method should return null. * - * @return array parameter name => value. + * @return array|null parameter name => value. */ public abstract function get_correct_response(); -- 2.43.0