diff --git a/question/behaviour/rendererbase.php b/question/behaviour/rendererbase.php index 932ee305b68..203c5b35fec 100644 --- a/question/behaviour/rendererbase.php +++ b/question/behaviour/rendererbase.php @@ -235,4 +235,40 @@ abstract class qbehaviour_renderer extends plugin_renderer_base { public function head_code(question_attempt $qa) { return ''; } + + /** + * Generate the display of the marks for this question. + * @param question_attempt $qa the question attempt to display. + * @param core_question_renderer $qoutput the renderer for standard parts of questions. + * @param question_display_options $options controls what should and should not be displayed. + * @return HTML fragment. + */ + public function mark_summary(question_attempt $qa, core_question_renderer $qoutput, + question_display_options $options) { + return $qoutput->standard_mark_summary($qa, $this, $options); + } + + /** + * Generate the display of the available marks for this question. + * @param question_attempt $qa the question attempt to display. + * @param core_question_renderer $qoutput the renderer for standard parts of questions. + * @param question_display_options $options controls what should and should not be displayed. + * @return HTML fragment. + */ + public function marked_out_of_max(question_attempt $qa, core_question_renderer $qoutput, + question_display_options $options) { + return $qoutput->standard_marked_out_of_max($qa, $options); + } + + /** + * Generate the display of the marks for this question out of the available marks. + * @param question_attempt $qa the question attempt to display. + * @param core_question_renderer $qoutput the renderer for standard parts of questions. + * @param question_display_options $options controls what should and should not be displayed. + * @return HTML fragment. + */ + public function mark_out_of_max(question_attempt $qa, core_question_renderer $qoutput, + question_display_options $options) { + return $qoutput->standard_mark_out_of_max($qa, $options); + } } diff --git a/question/behaviour/upgrade.txt b/question/behaviour/upgrade.txt index c21854ff053..51d17c080ed 100644 --- a/question/behaviour/upgrade.txt +++ b/question/behaviour/upgrade.txt @@ -11,17 +11,23 @@ class qbehaviour_mybehaviour_type extends question_behaviour_type { question_attempt. That is like the difference between the qtype_mytype and the qtype_mytype_question classes. -Practically, what this means is that any of the methods that used to be -static methods of qbehaviour_mybehaviour class are now normal instance methods -of the qbehaviour_mybehaviour_type class. Specifically. + Practically, what this means is that any of the methods that used to be + static methods of qbehaviour_mybehaviour class are now normal instance + methods of the qbehaviour_mybehaviour_type class. Specifically. 2.5 / qbehaviour_mybehaviour -> 2.6 / qbehaviour_mybehaviour_type IS_ARCHETYPAL -> is_archetypal() adjust_random_guess_score() -> adjust_random_guess_score() get_unused_display_options() -> get_unused_display_options() -3) The static method is_manual_grade_in_range has move from the +3) The static method is_manual_grade_in_range has moved from the question_behaviour class to the question_engine class. +4) Behaviours can now control how the marks information is displayed in the + grey info area to the left of the question. There is a new method + mark_summary that you can override, although the default implementation is + fine in most cases. it uses the marked_out_of_max and mark_out_of_max methods + as appropriate, so you may just wish to override those. + === 2.3 === diff --git a/question/engine/renderer.php b/question/engine/renderer.php index f6793d4113d..b07317f7dea 100644 --- a/question/engine/renderer.php +++ b/question/engine/renderer.php @@ -115,7 +115,7 @@ class core_question_renderer extends plugin_renderer_base { $output = ''; $output .= $this->number($number); $output .= $this->status($qa, $behaviouroutput, $options); - $output .= $this->mark_summary($qa, $options); + $output .= $this->mark_summary($qa, $behaviouroutput, $options); $output .= $this->question_flag($qa, $options->flags); $output .= $this->edit_question_link($qa, $options); return $output; @@ -173,30 +173,59 @@ class core_question_renderer extends plugin_renderer_base { /** * Generate the display of the marks for this question. * @param question_attempt $qa the question attempt to display. + * @param qbehaviour_renderer $behaviouroutput the behaviour renderer, which can generate a custom display. * @param question_display_options $options controls what should and should not be displayed. * @return HTML fragment. */ - protected function mark_summary(question_attempt $qa, question_display_options $options) { + protected function mark_summary(question_attempt $qa, qbehaviour_renderer $behaviouroutput, question_display_options $options) { + return html_writer::nonempty_tag('div', + $behaviouroutput->mark_summary($qa, $this, $options), + array('class' => 'grade')); + } + + /** + * Generate the display of the marks for this question. + * @param question_attempt $qa the question attempt to display. + * @param question_display_options $options controls what should and should not be displayed. + * @return HTML fragment. + */ + public function standard_mark_summary(question_attempt $qa, qbehaviour_renderer $behaviouroutput, question_display_options $options) { if (!$options->marks) { return ''; - } - if ($qa->get_max_mark() == 0) { - $summary = get_string('notgraded', 'question'); + } else if ($qa->get_max_mark() == 0) { + return get_string('notgraded', 'question'); } else if ($options->marks == question_display_options::MAX_ONLY || is_null($qa->get_fraction())) { - $summary = get_string('markedoutofmax', 'question', - $qa->format_max_mark($options->markdp)); + return $behaviouroutput->marked_out_of_max($qa, $this, $options); } else { - $a = new stdClass(); - $a->mark = $qa->format_mark($options->markdp); - $a->max = $qa->format_max_mark($options->markdp); - $summary = get_string('markoutofmax', 'question', $a); + return $behaviouroutput->mark_out_of_max($qa, $this, $options); } + } - return html_writer::tag('div', $summary, array('class' => 'grade')); + /** + * Generate the display of the available marks for this question. + * @param question_attempt $qa the question attempt to display. + * @param question_display_options $options controls what should and should not be displayed. + * @return HTML fragment. + */ + public function standard_marked_out_of_max(question_attempt $qa, question_display_options $options) { + return get_string('markedoutofmax', 'question', $qa->format_max_mark($options->markdp)); + } + + /** + * Generate the display of the marks for this question out of the available marks. + * @param question_attempt $qa the question attempt to display. + * @param question_display_options $options controls what should and should not be displayed. + * @return HTML fragment. + */ + public function standard_mark_out_of_max(question_attempt $qa, question_display_options $options) { + $a = new stdClass(); + $a->mark = $qa->format_mark($options->markdp); + $a->max = $qa->format_max_mark($options->markdp); + return get_string('markoutofmax', 'question', $a); } /** diff --git a/question/engine/upgrade.txt b/question/engine/upgrade.txt index ec993f6d7b3..04d1f23b39b 100644 --- a/question/engine/upgrade.txt +++ b/question/engine/upgrade.txt @@ -4,4 +4,13 @@ This files describes API changes for the core question system. === 2.4 === 1) The method question_behaviour::is_manual_grade_in_range and move and become -question_engine::is_manual_grade_in_range. \ No newline at end of file +question_engine::is_manual_grade_in_range. + +2) The arguments to core_question_renderer::mark_summary changed from +($qa, $options) to ($qa, $behaviouroutput, $options). If you have overridden +that method you will need to update your code. + + +=== Earlier changes === + +* Were not documented in this way. Sorry.