MDL-6535 new features for the essay qtype. Part I DB tables and editing form.
[moodle.git] / question / type / essay / renderer.php
CommitLineData
6d03299d
TH
1<?php
2
3// This file is part of Moodle - http://moodle.org/
4//
5// Moodle is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// Moodle is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17
6d03299d
TH
18/**
19 * Essay question renderer class.
20 *
7764183a
TH
21 * @package qtype
22 * @subpackage essay
23 * @copyright 2009 The Open University
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
6d03299d
TH
25 */
26
27
a17b297d
TH
28defined('MOODLE_INTERNAL') || die();
29
30
6d03299d
TH
31/**
32 * Generates the output for essay questions.
33 *
7764183a
TH
34 * @copyright 2009 The Open University
35 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
6d03299d
TH
36 */
37class qtype_essay_renderer extends qtype_renderer {
38 public function formulation_and_controls(question_attempt $qa,
39 question_display_options $options) {
40
41 $question = $qa->get_question();
42
43 // Answer field.
44 $inputname = $qa->get_qt_field_name('answer');
45 $response = $qa->get_last_qt_var('answer', '');
46 if (empty($options->readonly)) {
47 // the student needs to type in their answer so print out a text editor
48 $answer = print_textarea(can_use_html_editor(), 18, 65, 630, 400, $inputname, $response, 0, true);
49
50 } else {
51 // it is read only, so just format the students answer and output it
52 $formatoptions = new stdClass();
53 $formatoptions->para = false;
54 $answer = html_writer::tag('div', format_text($response, FORMAT_HTML, $formatoptions),
55 array('class' => 'answerreview'));
56 }
57
58 $result = '';
59 $result .= html_writer::tag('div', $question->format_questiontext($qa),
60 array('class' => 'qtext'));
61
62 $result .= html_writer::start_tag('div', array('class' => 'ablock clearfix'));
f9b0500f 63 $result .= html_writer::tag('div', get_string('answer', 'question'),
6d03299d
TH
64 array('class' => 'prompt'));
65 $result .= html_writer::tag('div', $answer, array('class' => 'answer'));
66 $result .= html_writer::end_tag('div');
67
68 return $result;
69 }
70}