weekly release 3.10.4+
[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 }
9b2fe16b
TH
58 $choices .= ' ' .
59 html_writer::tag('label', html_writer::empty_tag('input', $attributes) .
60 question_cbm::get_string($certainty), array('for' => $id));
d1b7e03d
TH
61 }
62 return $choices;
63 }
64
65 public function controls(question_attempt $qa, question_display_options $options) {
9b2fe16b
TH
66 $a = new stdClass();
67 $a->help = $this->output->help_icon('certainty', 'qbehaviour_deferredcbm');
68 $a->choices = $this->certainty_choices($qa->get_behaviour_field_name('certainty'),
69 $qa->get_last_behaviour_var('certainty'), $options->readonly);
70
71 return html_writer::tag('div', get_string('howcertainareyou', 'qbehaviour_deferredcbm', $a),
d1b7e03d
TH
72 array('class' => 'certaintychoices'));
73 }
74
75 public function feedback(question_attempt $qa, question_display_options $options) {
76 if (!$options->feedback) {
77 return '';
78 }
79
1631ceea
TH
80 if ($qa->get_state() == question_state::$gaveup || $qa->get_state() ==
81 question_state::$mangaveup) {
d1b7e03d
TH
82 return '';
83 }
84
85 $feedback = '';
1631ceea
TH
86 if (!$qa->get_last_behaviour_var('certainty') &&
87 $qa->get_last_behaviour_var('_assumedcertainty')) {
88 $feedback .= html_writer::tag('p',
89 get_string('assumingcertainty', 'qbehaviour_deferredcbm',
d1b7e03d
TH
90 question_cbm::get_string($qa->get_last_behaviour_var('_assumedcertainty'))));
91 }
92
d1b7e03d
TH
93 return $feedback;
94 }
fb74929e
TH
95
96 public function marked_out_of_max(question_attempt $qa, core_question_renderer $qoutput,
97 question_display_options $options) {
0b62cc2e 98 return get_string('weightx', 'qbehaviour_deferredcbm', $qa->format_fraction_as_mark(
fb74929e
TH
99 question_cbm::adjust_fraction(1, question_cbm::default_certainty()),
100 $options->markdp));
101 }
102
103 public function mark_out_of_max(question_attempt $qa, core_question_renderer $qoutput,
104 question_display_options $options) {
0b62cc2e
TH
105 return get_string('cbmmark', 'qbehaviour_deferredcbm', $qa->format_mark($options->markdp)) .
106 '<br>' . $this->marked_out_of_max($qa, $qoutput, $options);
fb74929e 107 }
0b62cc2e 108}