3 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
19 * Essay question definition class.
23 * @copyright 2009 The Open University
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28 defined('MOODLE_INTERNAL') || die();
32 * Represents an essay question.
34 * @copyright 2009 The Open University
35 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37 class qtype_essay_question extends question_with_responses {
38 public $responseformat;
39 public $responsefieldlines;
42 public $graderinfoformat;
44 public function make_behaviour(question_attempt $qa, $preferredbehaviour) {
45 question_engine::load_behaviour_class('manualgraded');
46 return new qbehaviour_manualgraded($qa, $preferredbehaviour);
50 * @param moodle_page the page we are outputting to.
51 * @return qtype_essay_format_renderer_base the response-format-specific renderer.
53 public function get_format_renderer(moodle_page $page) {
54 return $page->get_renderer('qtype_essay', 'format_' . $this->responseformat);
57 public function get_expected_data() {
58 $expecteddata = array('answer' => PARAM_CLEANHTML);
59 if ($this->attachments != 0) {
60 $expecteddata['attachments'] = question_attempt::PARAM_FILES;
65 public function summarise_response(array $response) {
66 if (isset($response['answer'])) {
67 $formatoptions = new stdClass();
68 $formatoptions->para = false;
69 return shorten_text(html_to_text(format_text($response['answer'], FORMAT_HTML, $formatoptions), 0, false), 200);
75 public function get_correct_response() {
79 public function is_complete_response(array $response) {
80 return !empty($response['answer']);
83 public function is_same_response(array $prevresponse, array $newresponse) {
84 return question_utils::arrays_same_at_key_missing_is_blank(
85 $prevresponse, $newresponse, 'answer');
88 public function check_file_access($qa, $options, $component, $filearea, $args, $forcedownload) {
89 if ($component == 'question' && $filearea == 'response_attachments') {
90 // Response attachments visible if the question has them.
91 return $this->attachments != 0;
94 return parent::check_file_access($qa, $options, $component, $filearea, $args, $forcedownload);