MDL-43646 "disapprove" changed to "undo approval"
[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;
60527d0c
JMV
42 public $responsetemplate;
43 public $responsetemplateformat;
894e8b4e 44
6d03299d 45 public function make_behaviour(question_attempt $qa, $preferredbehaviour) {
f3460297 46 return question_engine::make_behaviour('manualgraded', $qa, $preferredbehaviour);
6d03299d
TH
47 }
48
b36d2d06
TH
49 /**
50 * @param moodle_page the page we are outputting to.
51 * @return qtype_essay_format_renderer_base the response-format-specific renderer.
52 */
53 public function get_format_renderer(moodle_page $page) {
54 return $page->get_renderer('qtype_essay', 'format_' . $this->responseformat);
55 }
56
6d03299d 57 public function get_expected_data() {
48d9c17d 58 if ($this->responseformat == 'editorfilepicker') {
2d2018ab 59 $expecteddata = array('answer' => question_attempt::PARAM_RAW_FILES);
c0d12fc1
TH
60 } else {
61 $expecteddata = array('answer' => PARAM_RAW);
48d9c17d 62 }
405aca35 63 $expecteddata['answerformat'] = PARAM_ALPHANUMEXT;
caeeff07
TH
64 if ($this->attachments != 0) {
65 $expecteddata['attachments'] = question_attempt::PARAM_FILES;
66 }
67 return $expecteddata;
6d03299d
TH
68 }
69
70 public function summarise_response(array $response) {
71 if (isset($response['answer'])) {
e2b388c1
TH
72 return question_utils::to_plain_text($response['answer'],
73 $response['answerformat'], array('para' => false));
6d03299d
TH
74 } else {
75 return null;
76 }
77 }
78
79 public function get_correct_response() {
80 return null;
81 }
82
83 public function is_complete_response(array $response) {
efe67797 84 return array_key_exists('answer', $response) && ($response['answer'] !== '');
6d03299d
TH
85 }
86
87 public function is_same_response(array $prevresponse, array $newresponse) {
60527d0c 88 if (array_key_exists('answer', $prevresponse) && $prevresponse['answer'] !== $this->responsetemplate) {
afb1b3d0 89 $value1 = (string) $prevresponse['answer'];
60527d0c
JMV
90 } else {
91 $value1 = '';
92 }
93 if (array_key_exists('answer', $newresponse) && $newresponse['answer'] !== $this->responsetemplate) {
afb1b3d0 94 $value2 = (string) $newresponse['answer'];
60527d0c
JMV
95 } else {
96 $value2 = '';
97 }
98 return $value1 === $value2 && ($this->attachments == 0 ||
cd3557e6
TH
99 question_utils::arrays_same_at_key_missing_is_blank(
100 $prevresponse, $newresponse, 'attachments'));
6d03299d 101 }
caeeff07
TH
102
103 public function check_file_access($qa, $options, $component, $filearea, $args, $forcedownload) {
104 if ($component == 'question' && $filearea == 'response_attachments') {
105 // Response attachments visible if the question has them.
106 return $this->attachments != 0;
107
48d9c17d
TH
108 } else if ($component == 'question' && $filearea == 'response_answer') {
109 // Response attachments visible if the question has them.
110 return $this->responseformat === 'editorfilepicker';
111
783af252
TH
112 } else if ($component == 'qtype_essay' && $filearea == 'graderinfo') {
113 return $options->manualcomment;
114
caeeff07 115 } else {
121fd4c1
TH
116 return parent::check_file_access($qa, $options, $component,
117 $filearea, $args, $forcedownload);
caeeff07
TH
118 }
119 }
6d03299d 120}