MDL-32188 question CBM: alter score handling.
[moodle.git] / question / behaviour / deferredcbm / renderer.php
CommitLineData
d1b7e03d 1<?php
d1b7e03d
TH
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
d1b7e03d 17/**
017bc1d9
TH
18 * Defines the renderer for the deferred feedback with certainty based marking
19 * behaviour.
d1b7e03d 20 *
017bc1d9
TH
21 * @package qbehaviour
22 * @subpackage deferredcbm
23 * @copyright 2009 The Open University
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
d1b7e03d
TH
25 */
26
27
a17b297d
TH
28defined('MOODLE_INTERNAL') || die();
29
30
017bc1d9
TH
31/**
32 * Renderer for outputting parts of a question belonging to the deferred
33 * feedback with certainty based marking behaviour.
34 *
35 * @copyright 2009 The Open University
36 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37 */
d1b7e03d 38class qbehaviour_deferredcbm_renderer extends qbehaviour_renderer {
c4efeb2b 39 protected function certainty_choices($controlname, $selected, $readonly) {
d1b7e03d
TH
40 $attributes = array(
41 'type' => 'radio',
42 'name' => $controlname,
43 );
44 if ($readonly) {
45 $attributes['disabled'] = 'disabled';
46 }
47
48 $choices = '';
49 foreach (question_cbm::$certainties as $certainty) {
50 $id = $controlname . $certainty;
51 $attributes['id'] = $id;
52 $attributes['value'] = $certainty;
53 if ($selected == $certainty) {
54 $attributes['checked'] = 'checked';
55 } else {
56 unset($attributes['checked']);
57 }
58 $choices .= ' ' . html_writer::empty_tag('input', $attributes) . ' ' .
59 html_writer::tag('label', question_cbm::get_string($certainty),
60 array('for' => $id));
61 }
62 return $choices;
63 }
64
65 public function controls(question_attempt $qa, question_display_options $options) {
66 return html_writer::tag('div', get_string('howcertainareyou', 'qbehaviour_deferredcbm',
c4efeb2b 67 $this->certainty_choices($qa->get_behaviour_field_name('certainty'),
d1b7e03d
TH
68 $qa->get_last_behaviour_var('certainty'), $options->readonly)),
69 array('class' => 'certaintychoices'));
70 }
71
72 public function feedback(question_attempt $qa, question_display_options $options) {
73 if (!$options->feedback) {
74 return '';
75 }
76
1631ceea
TH
77 if ($qa->get_state() == question_state::$gaveup || $qa->get_state() ==
78 question_state::$mangaveup) {
d1b7e03d
TH
79 return '';
80 }
81
82 $feedback = '';
1631ceea
TH
83 if (!$qa->get_last_behaviour_var('certainty') &&
84 $qa->get_last_behaviour_var('_assumedcertainty')) {
85 $feedback .= html_writer::tag('p',
86 get_string('assumingcertainty', 'qbehaviour_deferredcbm',
d1b7e03d
TH
87 question_cbm::get_string($qa->get_last_behaviour_var('_assumedcertainty'))));
88 }
89
d1b7e03d
TH
90 return $feedback;
91 }
fb74929e
TH
92
93 public function marked_out_of_max(question_attempt $qa, core_question_renderer $qoutput,
94 question_display_options $options) {
95 return get_string('basemark', 'qbehaviour_deferredcbm', $qa->format_fraction_as_mark(
96 question_cbm::adjust_fraction(1, question_cbm::default_certainty()),
97 $options->markdp));
98 }
99
100 public function mark_out_of_max(question_attempt $qa, core_question_renderer $qoutput,
101 question_display_options $options) {
102 return get_string('cbmmark', 'qbehaviour_deferredcbm', $qa->format_mark($options->markdp));
103 }
d1b7e03d 104}