MDL-38509 Version bump for plugins installation
[moodle.git] / question / type / essay / question.php
CommitLineData
6d03299d 1<?php
6d03299d
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
6d03299d
TH
17/**
18 * Essay question definition class.
19 *
7764183a
TH
20 * @package qtype
21 * @subpackage essay
22 * @copyright 2009 The Open University
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
6d03299d
TH
24 */
25
26
a17b297d
TH
27defined('MOODLE_INTERNAL') || die();
28
29
6d03299d
TH
30/**
31 * Represents an essay question.
32 *
7764183a
TH
33 * @copyright 2009 The Open University
34 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
6d03299d
TH
35 */
36class qtype_essay_question extends question_with_responses {
894e8b4e
TH
37 public $responseformat;
38 public $responsefieldlines;
39 public $attachments;
40 public $graderinfo;
41 public $graderinfoformat;
42
6d03299d
TH
43 public function make_behaviour(question_attempt $qa, $preferredbehaviour) {
44 question_engine::load_behaviour_class('manualgraded');
45 return new qbehaviour_manualgraded($qa, $preferredbehaviour);
46 }
47
b36d2d06
TH
48 /**
49 * @param moodle_page the page we are outputting to.
50 * @return qtype_essay_format_renderer_base the response-format-specific renderer.
51 */
52 public function get_format_renderer(moodle_page $page) {
53 return $page->get_renderer('qtype_essay', 'format_' . $this->responseformat);
54 }
55
6d03299d 56 public function get_expected_data() {
48d9c17d 57 if ($this->responseformat == 'editorfilepicker') {
2d2018ab 58 $expecteddata = array('answer' => question_attempt::PARAM_RAW_FILES);
c0d12fc1
TH
59 } else {
60 $expecteddata = array('answer' => PARAM_RAW);
48d9c17d 61 }
405aca35 62 $expecteddata['answerformat'] = PARAM_ALPHANUMEXT;
caeeff07
TH
63 if ($this->attachments != 0) {
64 $expecteddata['attachments'] = question_attempt::PARAM_FILES;
65 }
66 return $expecteddata;
6d03299d
TH
67 }
68
69 public function summarise_response(array $response) {
70 if (isset($response['answer'])) {
71 $formatoptions = new stdClass();
72 $formatoptions->para = false;
e84dacff
TH
73 return html_to_text(format_text(
74 $response['answer'], FORMAT_HTML, $formatoptions), 0, false);
6d03299d
TH
75 } else {
76 return null;
77 }
78 }
79
80 public function get_correct_response() {
81 return null;
82 }
83
84 public function is_complete_response(array $response) {
85 return !empty($response['answer']);
86 }
87
88 public function is_same_response(array $prevresponse, array $newresponse) {
89 return question_utils::arrays_same_at_key_missing_is_blank(
cd3557e6
TH
90 $prevresponse, $newresponse, 'answer') && ($this->attachments == 0 ||
91 question_utils::arrays_same_at_key_missing_is_blank(
92 $prevresponse, $newresponse, 'attachments'));
6d03299d 93 }
caeeff07
TH
94
95 public function check_file_access($qa, $options, $component, $filearea, $args, $forcedownload) {
96 if ($component == 'question' && $filearea == 'response_attachments') {
97 // Response attachments visible if the question has them.
98 return $this->attachments != 0;
99
48d9c17d
TH
100 } else if ($component == 'question' && $filearea == 'response_answer') {
101 // Response attachments visible if the question has them.
102 return $this->responseformat === 'editorfilepicker';
103
783af252
TH
104 } else if ($component == 'qtype_essay' && $filearea == 'graderinfo') {
105 return $options->manualcomment;
106
caeeff07 107 } else {
121fd4c1
TH
108 return parent::check_file_access($qa, $options, $component,
109 $filearea, $args, $forcedownload);
caeeff07
TH
110 }
111 }
6d03299d 112}