renderer.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. // This file is part of Moodle - http://moodle.org/
  3. //
  4. // Moodle is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // Moodle is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
  16. /**
  17. * Renderer for outputting parts of a question belonging to the legacy
  18. * adaptive behaviour.
  19. *
  20. * @package qbehaviour
  21. * @subpackage adaptive
  22. * @copyright 2009 The Open University
  23. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24. */
  25. defined('MOODLE_INTERNAL') || die();
  26. /**
  27. * Renderer for outputting parts of a question belonging to the legacy
  28. * adaptive behaviour.
  29. *
  30. * @copyright 2009 The Open University
  31. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  32. */
  33. class qbehaviour_adaptive_renderer extends qbehaviour_renderer {
  34. public function controls(question_attempt $qa, question_display_options $options) {
  35. return $this->submit_button($qa, $options);
  36. }
  37. public function feedback(question_attempt $qa, question_display_options $options) {
  38. // If the latest answer was invalid, display an informative message.
  39. if ($qa->get_state() == question_state::$invalid) {
  40. return html_writer::nonempty_tag('div', $this->disregarded_info(),
  41. array('class' => 'gradingdetails'));
  42. }
  43. // Otherwise get the details.
  44. return $this->render_adaptive_marks(
  45. $qa->get_behaviour()->get_adaptive_marks(), $options);
  46. }
  47. /**
  48. * Display the scoring information about an adaptive attempt.
  49. * @param qbehaviour_adaptive_mark_details contains all the score details we need.
  50. * @param question_display_options $options display options.
  51. */
  52. public function render_adaptive_marks(qbehaviour_adaptive_mark_details $details, question_display_options $options) {
  53. if ($details->state == question_state::$todo || $options->marks < question_display_options::MARK_AND_MAX) {
  54. // No grades yet.
  55. return '';
  56. }
  57. // Display the grading details from the last graded state.
  58. $class = $details->state->get_feedback_class();
  59. return html_writer::tag('div', get_string($class, 'question'),
  60. array('class' => 'correctness ' . $class))
  61. . html_writer::tag('div', $this->grading_details($details, $options),
  62. array('class' => 'gradingdetails'));
  63. }
  64. /**
  65. * Display the information about the penalty calculations.
  66. * @param qbehaviour_adaptive_mark_details contains all the score details we need.
  67. * @param question_display_options $options display options.
  68. * @return string html fragment
  69. */
  70. protected function grading_details(qbehaviour_adaptive_mark_details $details, question_display_options $options) {
  71. $mark = $details->get_formatted_marks($options->markdp);
  72. if ($details->currentpenalty == 0 && $details->totalpenalty == 0) {
  73. return get_string('gradingdetails', 'qbehaviour_adaptive', $mark);
  74. }
  75. $output = '';
  76. // Print details of grade adjustment due to penalties
  77. if ($details->rawmark != $details->actualmark) {
  78. if (!$details->improvable) {
  79. return get_string('gradingdetailswithadjustment', 'qbehaviour_adaptive', $mark);
  80. } else if ($details->totalpenalty > $details->currentpenalty) {
  81. return get_string('gradingdetailswithadjustmenttotalpenalty', 'qbehaviour_adaptive', $mark);
  82. } else {
  83. return get_string('gradingdetailswithadjustmentpenalty', 'qbehaviour_adaptive', $mark);
  84. }
  85. } else {
  86. if (!$details->improvable) {
  87. return get_string('gradingdetails', 'qbehaviour_adaptive', $mark);
  88. } else if ($details->totalpenalty > $details->currentpenalty) {
  89. return get_string('gradingdetailswithtotalpenalty', 'qbehaviour_adaptive', $mark);
  90. } else {
  91. return get_string('gradingdetailswithpenalty', 'qbehaviour_adaptive', $mark);
  92. }
  93. }
  94. return $output;
  95. }
  96. /**
  97. * Display information about a disregarded (incomplete) response.
  98. */
  99. protected function disregarded_info() {
  100. return get_string('disregardedwithoutpenalty', 'qbehaviour_adaptive');
  101. }
  102. }