mirrored from git://git.moodle.org/moodle.git
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
/
renderer.php
210 lines (177 loc) · 6.97 KB
/
renderer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Essay question renderer class.
*
* @package qtype
* @subpackage essay
* @copyright 2009 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Generates the output for essay questions.
*
* @copyright 2009 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class qtype_essay_renderer extends qtype_renderer {
public function formulation_and_controls(question_attempt $qa,
question_display_options $options) {
$question = $qa->get_question();
$responseoutput = $question->get_format_renderer($this->page);
// Answer field.
$inputname = $qa->get_qt_field_name('answer');
$response = $qa->get_last_qt_var('answer', '');
if (empty($options->readonly)) {
$answer =$responseoutput->response_area_input($inputname,
$response, $question->responsefieldlines);
} else {
$answer =$responseoutput->response_area_read_only($inputname,
$response, $question->responsefieldlines);
}
$files = '';
if (empty($options->readonly)) {
if ($question->attachments == 1) {
$files = $this->filepicker_input();
} else if ($question->attachments != 0) {
$files = $this->filemanager_input();
}
} else if ($question->attachments != 0) {
$files = $this->files_read_only();
}
$result = '';
$result .= html_writer::tag('div', $question->format_questiontext($qa),
array('class' => 'qtext'));
$result .= html_writer::start_tag('div', array('class' => 'ablock'));
$result .= html_writer::tag('div', $answer, array('class' => 'answer'));
$result .= html_writer::end_tag('div');
return $result;
}
/**
* Displays any attached files when the question is in read-only mode.
*/
public function files_read_only() {
return '';
}
/**
* Displays the input control for when the student should upload a single file.
*/
public function filepicker_input() {
return '';
}
/**
* Displays the input control for when the student should upload a number of files.
*/
public function filemanager_input() {
return '';
}
}
/**
* A base class to abstract out the differences between different type of
* response format.
*
* @copyright 2011 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
abstract class qtype_essay_format_renderer_base extends plugin_renderer_base {
/**
* Render the students respone when the question is in read-only mode.
* @param string $inputname the field name to use for this input.
* @param string $response the student's current response.
* @param int $lines approximate size of input box to display.
*/
public abstract function response_area_read_only($inputname, $response, $lines);
/**
* Render the students respone when the question is in read-only mode.
* @param string $inputname the field name to use for this input.
* @param string $response the student's current response.
* @param int $lines approximate size of input box to display.
*/
public abstract function response_area_input($inputname, $response, $lines);
}
/**
* An essay format renderer for essays where the student should use the HTML
* editor without the file picker.
*
* @copyright 2011 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class qtype_essay_format_editor_renderer extends plugin_renderer_base {
public function response_area_read_only($inputname, $response, $lines) {
$formatoptions = new stdClass();
$formatoptions->para = false;
return html_writer::tag('div', format_text($response, FORMAT_HTML, $formatoptions),
array('class' => 'qtype_essay_editor qtype_essay_response'));
}
public function response_area_input($inputname, $response, $lines) {
return print_textarea(can_use_html_editor(), 18, 80, 630, 400, $inputname, $response, 0, true);
}
}
/**
* An essay format renderer for essays where the student should use the HTML
* editor with the file picker.
*
* @copyright 2011 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class qtype_essay_format_editorfilepicker_renderer extends plugin_renderer_base {
public function response_area_read_only($inputname, $response, $lines) {
return 'Not yet implemented.';
}
public function response_area_input($inputname, $response, $lines) {
return 'Not yet implemented.';
}
}
/**
* An essay format renderer for essays where the student should use a plain
* input box, but with a normal, proportional font.
*
* @copyright 2011 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class qtype_essay_format_plain_renderer extends plugin_renderer_base {
/**
* @return string the HTML for the textarea.
*/
protected function textarea($response, $lines, $attributes) {
$attributes['class'] = $this->class_name() . ' qtype_essay_response';
$attributes['rows'] = $lines;
return html_writer::tag('textarea', s($response), $attributes);
}
protected function class_name() {
return 'qtype_essay_plain';
}
public function response_area_read_only($inputname, $response, $lines) {
return $this->textarea($response, $lines, array('readonly' => 'readonly'));
}
public function response_area_input($inputname, $response, $lines) {
return $this->textarea($response, $lines, array('name' => $inputname));
}
}
/**
* An essay format renderer for essays where the student should use a plain
* input box with a monospaced font. You might use this, for example, for a
* question where the students should type computer code.
*
* @copyright 2011 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class qtype_essay_format_monospaced_renderer extends qtype_essay_format_plain_renderer {
protected function class_name() {
return 'qtype_essay_monospaced';
}
}