MDL-20636 converstion of questionlib.php and base questiontype.php, plus other cheang...
[moodle.git] / question / type / truefalse / edit_truefalse_form.php
CommitLineData
aeb15530 1<?php
fe6ce234
DC
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
bfebaf64
MD
18if (!defined('MOODLE_INTERNAL')) {
19 die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
20}
21
01ae934f 22require_once($CFG->dirroot.'/question/type/edit_question_form.php');
fe6ce234 23
36703ed7 24/**
25 * Defines the editing form for the thruefalse question type.
26 *
27 * @copyright &copy; 2006 The Open University
28 * @author T.J.Hunt@open.ac.uk
29 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
830e47a8 30 * @package questionbank
31 * @subpackage questiontypes
fe6ce234 32 */
36703ed7 33
34/**
35 * truefalse editing form definition.
36 */
01ae934f 37class question_edit_truefalse_form extends question_edit_form {
36703ed7 38 /**
39 * Add question-type specific form fields.
01ae934f 40 *
41 * @param object $mform the form being built.
36703ed7 42 */
43 function definition_inner(&$mform) {
44 $mform->addElement('select', 'correctanswer', get_string('correctanswer', 'qtype_truefalse'),
45 array(0 => get_string('false', 'qtype_truefalse'), 1 => get_string('true', 'qtype_truefalse')));
01ae934f 46
fe6ce234 47 $mform->addElement('editor', 'feedbacktrue', get_string('feedbacktrue', 'qtype_truefalse'), null, $this->editoroptions);;
36703ed7 48 $mform->setType('feedbacktrue', PARAM_RAW);
49
fe6ce234 50 $mform->addElement('editor', 'feedbackfalse', get_string('feedbackfalse', 'qtype_truefalse'), null, $this->editoroptions);
36703ed7 51 $mform->setType('feedbackfalse', PARAM_RAW);
fe76ab50 52
53 // Fix penalty factor at 1.
54 $mform->setDefault('penalty', 1);
55 $mform->freeze('penalty');
36703ed7 56 }
01ae934f 57
32db0d42 58 function set_data($question) {
36703ed7 59 if (!empty($question->options->trueanswer)) {
60 $trueanswer = $question->options->answers[$question->options->trueanswer];
fe6ce234
DC
61 $draftid = file_get_submitted_draft_itemid('trueanswer');
62 $answerid = $question->options->trueanswer;
63 $text = $trueanswer->feedback;
64
36703ed7 65 $question->correctanswer = ($trueanswer->fraction != 0);
fe6ce234
DC
66 $question->feedbacktrue = array();
67 $question->feedbacktrue['text'] = $trueanswer->feedback;
68 $question->feedbacktrue['format'] = $trueanswer->feedbackformat;
69 $question->feedbacktrue['text'] = file_prepare_draft_area(
70 $draftid, // draftid
71 $this->context->id, // context
72 'question', // component
73 'answerfeedback', // filarea
74 !empty($answerid)?(int)$answerid:null, // itemid
75 $this->fileoptions, // options
76 $text // text
77 );
78 $question->feedbacktrue['itemid'] = $draftid;
79 }
80 if (!empty($question->options->falseanswer)) {
81 $falseanswer = $question->options->answers[$question->options->falseanswer];
82 $draftid = file_get_submitted_draft_itemid('falseanswer');
83 $answerid = $question->options->falseanswer;
84 $text = $falseanswer->feedback;
85
fe6ce234
DC
86 $question->feedbackfalse = array();
87 $question->feedbackfalse['text'] = $falseanswer->feedback;
88 $question->feedbackfalse['format'] = $falseanswer->feedbackformat;
89 $question->feedbackfalse['text'] = file_prepare_draft_area(
90 $draftid, // draftid
91 $this->context->id, // context
92 'question', // component
93 'answerfeedback', // filarea
94 !empty($answerid)?(int)$answerid:null, // itemid
95 $this->fileoptions, // options
96 $text // text
97 );
98 $question->feedbackfalse['itemid'] = $draftid;
36703ed7 99 }
32db0d42 100 parent::set_data($question);
36703ed7 101 }
01ae934f 102
36703ed7 103 function qtype() {
104 return 'truefalse';
105 }
106}