diff --git a/question/type/essay/edit_essay_form.php b/question/type/essay/edit_essay_form.php
index 702d8c74829..79277e3205d 100644
--- a/question/type/essay/edit_essay_form.php
+++ b/question/type/essay/edit_essay_form.php
@@ -29,46 +29,7 @@
* essay editing form definition.
*/
class question_edit_essay_form extends question_edit_form {
- /**
- * Add question-type specific form fields.
- *
- * @param MoodleQuickForm $mform the form being built.
- */
- function definition_inner(&$mform) {
- $mform->addElement('editor', 'feedback', get_string('feedback', 'quiz'), null, $this->editoroptions);
- $mform->setType('feedback', PARAM_RAW);
-
- $mform->addElement('hidden', 'fraction', 0);
- $mform->setType('fraction', PARAM_RAW);
-
- //don't need this default element.
- $mform->removeElement('penalty');
- $mform->addElement('hidden', 'penalty', 0);
- $mform->setType('penalty', PARAM_RAW);
- }
-
- function data_preprocessing($question) {
- if (!empty($question->options) && !empty($question->options->answers)) {
- $answer = reset($question->options->answers);
- $question->feedback = array();
- $draftid = file_get_submitted_draft_itemid('feedback');
- $question->feedback['text'] = file_prepare_draft_area(
- $draftid, // draftid
- $this->context->id, // context
- 'question', // component
- 'answerfeedback', // filarea
- !empty($answer->id)?(int)$answer->id:null, // itemid
- $this->fileoptions, // options
- $answer->feedback // text
- );
- $question->feedback['format'] = $answer->feedbackformat;
- $question->feedback['itemid'] = $draftid;
- }
- $question->penalty = 0;
- return $question;
- }
-
- function qtype() {
+ public function qtype() {
return 'essay';
}
}
diff --git a/question/type/essay/lang/en/qtype_essay.php b/question/type/essay/lang/en/qtype_essay.php
index bfcf00057ef..908b6dda3e1 100644
--- a/question/type/essay/lang/en/qtype_essay.php
+++ b/question/type/essay/lang/en/qtype_essay.php
@@ -25,7 +25,7 @@
$string['addingessay'] = 'Adding an Essay question';
$string['addingessay_link'] = 'question/type/essay';
-$string['editingessay'] = 'Editing a Essay question';
+$string['editingessay'] = 'Editing an Essay question';
$string['essay'] = 'Essay';
$string['essay_help'] = 'In response to a question (that may include an image) the respondent writes an answer of a paragraph or two. The essay question will not be assigned a grade until it has been reviewed by a teacher and manually graded.';
$string['essaysummary'] = 'Allows a response of a few sentences or paragraphs. This must then be graded manually.';
diff --git a/question/type/essay/question.php b/question/type/essay/question.php
new file mode 100644
index 00000000000..ac7209722ba
--- /dev/null
+++ b/question/type/essay/question.php
@@ -0,0 +1,66 @@
+.
+
+
+/**
+ * Essay question definition class.
+ *
+ * @package qtype_essay
+ * @copyright 2009 The Open University
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+
+/**
+ * Represents an essay question.
+ *
+ * @copyright 2009 The Open University
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class qtype_essay_question extends question_with_responses {
+ public function make_behaviour(question_attempt $qa, $preferredbehaviour) {
+ question_engine::load_behaviour_class('manualgraded');
+ return new qbehaviour_manualgraded($qa, $preferredbehaviour);
+ }
+
+ public function get_expected_data() {
+ return array('answer' => PARAM_CLEANHTML);
+ }
+
+ public function summarise_response(array $response) {
+ if (isset($response['answer'])) {
+ $formatoptions = new stdClass();
+ $formatoptions->para = false;
+ return shorten_text(html_to_text(format_text($response['answer'], FORMAT_HTML, $formatoptions), 0, false), 200);
+ } else {
+ return null;
+ }
+ }
+
+ public function get_correct_response() {
+ return null;
+ }
+
+ public function is_complete_response(array $response) {
+ return !empty($response['answer']);
+ }
+
+ public function is_same_response(array $prevresponse, array $newresponse) {
+ return question_utils::arrays_same_at_key_missing_is_blank(
+ $prevresponse, $newresponse, 'answer');
+ }
+}
diff --git a/question/type/essay/questiontype.php b/question/type/essay/questiontype.php
index 102b26f1bc2..9ccfe90917c 100644
--- a/question/type/essay/questiontype.php
+++ b/question/type/essay/questiontype.php
@@ -15,138 +15,28 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see
';
+ $this->assertEqual('Hello [world]', $essay->get_question_summary(
+ test_question_maker::get_a_qa($essay)));
+ }
+
+ public function test_summarise_response() {
+ $longstring = str_repeat('0123456789', 50);
+ $essay = test_question_maker::make_an_essay_question();
+ $summary = $essay->summarise_response(array('answer' => $longstring));
+ $this->assertTrue(strlen($summary) < 250);
+ $this->assertEqual(substr($longstring, 0, 100), substr($summary, 0, 100));
+ }
+}
diff --git a/question/type/essay/simpletest/testquestiontype.php b/question/type/essay/simpletest/testquestiontype.php
new file mode 100644
index 00000000000..1c5116c523b
--- /dev/null
+++ b/question/type/essay/simpletest/testquestiontype.php
@@ -0,0 +1,71 @@
+.
+
+
+/**
+ * Unit tests for the essay question type class.
+ *
+ * @package qtype_essay
+ * @copyright 2010 The Open University
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+require_once($CFG->dirroot . '/question/type/essay/questiontype.php');
+
+/**
+ * Unit tests for the essay question type class.
+ *
+ * @copyright 2010 The Open University
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class qtype_essay_test extends UnitTestCase {
+ var $qtype;
+
+ public function setUp() {
+ $this->qtype = new qtype_essay();
+ }
+
+ public function tearDown() {
+ $this->qtype = null;
+ }
+
+ protected function get_test_question_data() {
+ $q = new stdClass;
+ $q->id = 1;
+
+ return $q;
+ }
+
+ public function test_name() {
+ $this->assertEqual($this->qtype->name(), 'essay');
+ }
+
+ public function test_can_analyse_responses() {
+ $this->assertFalse($this->qtype->can_analyse_responses());
+ }
+
+ public function test_get_random_guess_score() {
+ $q = $this->get_test_question_data();
+ $this->assertEqual(0, $this->qtype->get_random_guess_score($q));
+ }
+
+ public function test_get_possible_responses() {
+ $q = $this->get_test_question_data();
+ $this->assertEqual(array(), $this->qtype->get_possible_responses($q));
+
+ }
+}
diff --git a/question/type/essay/version.php b/question/type/essay/version.php
index 9061bb2e5eb..4d9fe587b34 100644
--- a/question/type/essay/version.php
+++ b/question/type/essay/version.php
@@ -2,5 +2,3 @@
$plugin->version = 2010090501;
$plugin->requires = 2010090501;
-
-
diff --git a/question/type/truefalse/question.php b/question/type/truefalse/question.php
index fae901267f5..8a6a982e5b1 100644
--- a/question/type/truefalse/question.php
+++ b/question/type/truefalse/question.php
@@ -97,7 +97,7 @@ class qtype_truefalse_question extends question_graded_automatically {
return array($fraction, question_state::graded_state_for_fraction($fraction));
}
- function check_file_access($qa, $options, $component, $filearea, $args, $forcedownload) {
+ public function check_file_access($qa, $options, $component, $filearea, $args, $forcedownload) {
if ($component == 'question' && $filearea == 'answerfeedback') {
$answerid = reset($args); // itemid is answer id.
$response = $qa->get_last_qt_var('answer', '');