. /** * Renderer for outputting parts of a question belonging to the legacy * adaptive behaviour. * * @package qbehaviour * @subpackage adaptive * @copyright 2009 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die(); /** * Renderer for outputting parts of a question belonging to the legacy * adaptive behaviour. * * @copyright 2009 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class qbehaviour_adaptive_renderer extends qbehaviour_renderer { protected function get_graded_step(question_attempt $qa) { foreach ($qa->get_reverse_step_iterator() as $step) { if ($step->has_behaviour_var('_try')) { return $step; } } } public function controls(question_attempt $qa, question_display_options $options) { return $this->submit_button($qa, $options); } public function feedback(question_attempt $qa, question_display_options $options) { // Try to find the last graded step. $gradedstep = $this->get_graded_step($qa); if (is_null($gradedstep) || $qa->get_max_mark() == 0 || $options->marks < question_display_options::MARK_AND_MAX) { return ''; } // Display the grading details from the last graded state $mark = new stdClass(); $mark->max = $qa->format_max_mark($options->markdp); $actualmark = $gradedstep->get_fraction() * $qa->get_max_mark(); $mark->cur = format_float($actualmark, $options->markdp); $rawmark = $gradedstep->get_behaviour_var('_rawfraction') * $qa->get_max_mark(); $mark->raw = format_float($rawmark, $options->markdp); // let student know wether the answer was correct if ($qa->get_state()->is_commented()) { $class = $qa->get_state()->get_feedback_class(); } else { $class = question_state::graded_state_for_fraction( $gradedstep->get_behaviour_var('_rawfraction'))->get_feedback_class(); } $gradingdetails = get_string('gradingdetails', 'qbehaviour_adaptive', $mark); $gradingdetails .= $this->penalty_info($qa, $mark, $options); $output = ''; $output .= html_writer::tag('div', get_string($class, 'question'), array('class' => 'correctness ' . $class)); $output .= html_writer::tag('div', $gradingdetails, array('class' => 'gradingdetails')); return $output; } /** * Display the information about the penalty calculations. * @param question_attempt $qa the question attempt. * @param object $mark contains information about the current mark. * @param question_display_options $options display options. */ protected function penalty_info(question_attempt $qa, $mark, question_display_options $options) { if (!$qa->get_question()->penalty) { return ''; } $output = ''; // print details of grade adjustment due to penalties if ($mark->raw != $mark->cur) { $output .= ' ' . get_string('gradingdetailsadjustment', 'qbehaviour_adaptive', $mark); } // print info about new penalty // penalty is relevant only if the answer is not correct and further attempts are possible if (!$qa->get_state()->is_finished()) { $output .= ' ' . get_string('gradingdetailspenalty', 'qbehaviour_adaptive', format_float($qa->get_question()->penalty, $options->markdp)); } return $output; } }