From 1eb470fc429cb151d86e7cc8c3442cb2a7212fe7 Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Thu, 6 Feb 2014 15:00:56 +0000 Subject: [PATCH] MDL-43929 question manual grading: keep comment when validation fails. If the validation failed, so the manual grading page was re-displayed with a validation error, then any comment that had just been typed in was getting lost. This fixes that. --- question/behaviour/behaviourbase.php | 2 +- question/behaviour/rendererbase.php | 2 +- question/engine/questionattempt.php | 21 +++++++++++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/question/behaviour/behaviourbase.php b/question/behaviour/behaviourbase.php index b3b476a59f8..3df1e6635f6 100644 --- a/question/behaviour/behaviourbase.php +++ b/question/behaviour/behaviourbase.php @@ -192,7 +192,7 @@ abstract class question_behaviour { return array(); } - $vars = array('comment' => PARAM_RAW); + $vars = array('comment' => PARAM_RAW, 'commentformat' => PARAM_INT); if ($this->qa->get_max_mark()) { $vars['mark'] = question_attempt::PARAM_MARK; $vars['maxmark'] = PARAM_FLOAT; diff --git a/question/behaviour/rendererbase.php b/question/behaviour/rendererbase.php index 203c5b35fec..0397da02797 100644 --- a/question/behaviour/rendererbase.php +++ b/question/behaviour/rendererbase.php @@ -71,7 +71,7 @@ abstract class qbehaviour_renderer extends plugin_renderer_base { public function manual_comment_fields(question_attempt $qa, question_display_options $options) { $inputname = $qa->get_behaviour_field_name('comment'); $id = $inputname . '_id'; - list($commenttext, $commentformat) = $qa->get_manual_comment(); + list($commenttext, $commentformat) = $qa->get_current_manual_comment(); $editor = editors_get_preferred_editor($commentformat); $strformats = format_text_menu(); diff --git a/question/engine/questionattempt.php b/question/engine/questionattempt.php index 9d4d0f4e04e..c4e34ac4b6d 100644 --- a/question/engine/questionattempt.php +++ b/question/engine/questionattempt.php @@ -1284,6 +1284,27 @@ class question_attempt { return array(null, null); } + /** + * This is used by the manual grading code, particularly in association with + * validation. If there is a comment submitted in the request, then use that, + * otherwise use the latest comment for this question. + * @return number the current mark for this question. + * {@link get_fraction()} * {@link get_max_mark()}. + */ + public function get_current_manual_comment() { + $comment = $this->get_submitted_var($this->get_behaviour_field_name('comment'), PARAM_RAW); + if (is_null($comment)) { + return $this->get_manual_comment(); + } else { + $commentformat = $this->get_submitted_var( + $this->get_behaviour_field_name('commentformat'), PARAM_INT); + if ($commentformat === null) { + $commentformat = FORMAT_HTML; + } + return array($comment, $commentformat); + } + } + /** * Break down a student response by sub part and classification. * See also {@link question_type::get_possible_responses()}