Moodle release 2.5beta
[moodle.git] / question / type / truefalse / edit_truefalse_form.php
CommitLineData
aeb15530 1<?php
fe6ce234
DC
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
2b7da645
TH
17/**
18 * Defines the editing form for the true-false question type.
19 *
b04a4319
TH
20 * @package qtype
21 * @subpackage truefalse
22 * @copyright 2007 Jamie Pratt
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
2b7da645
TH
24 */
25
26
a17b297d
TH
27defined('MOODLE_INTERNAL') || die();
28
bfebaf64 29
01ae934f 30require_once($CFG->dirroot.'/question/type/edit_question_form.php');
fe6ce234 31
2b7da645 32
36703ed7 33/**
2b7da645 34 * True-false question editing form definition.
36703ed7 35 *
7764183a
TH
36 * @copyright 2007 Jamie Pratt
37 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36703ed7 38 */
6e34cd29 39class qtype_truefalse_edit_form extends question_edit_form {
36703ed7 40 /**
41 * Add question-type specific form fields.
01ae934f 42 *
43 * @param object $mform the form being built.
36703ed7 44 */
2b7da645 45 protected function definition_inner($mform) {
dcd69f8d
TH
46 $mform->addElement('select', 'correctanswer',
47 get_string('correctanswer', 'qtype_truefalse'), array(
48 0 => get_string('false', 'qtype_truefalse'),
49 1 => get_string('true', 'qtype_truefalse')));
01ae934f 50
dcd69f8d 51 $mform->addElement('editor', 'feedbacktrue',
e3ab75de 52 get_string('feedbacktrue', 'qtype_truefalse'), array('rows' => 10), $this->editoroptions);
36703ed7 53 $mform->setType('feedbacktrue', PARAM_RAW);
54
dcd69f8d 55 $mform->addElement('editor', 'feedbackfalse',
e3ab75de 56 get_string('feedbackfalse', 'qtype_truefalse'), array('rows' => 10), $this->editoroptions);
36703ed7 57 $mform->setType('feedbackfalse', PARAM_RAW);
fe76ab50 58
dcd69f8d
TH
59 $mform->addElement('header', 'multitriesheader',
60 get_string('settingsformultipletries', 'question'));
2b7da645
TH
61
62 $mform->addElement('hidden', 'penalty', 1);
63
dcd69f8d
TH
64 $mform->addElement('static', 'penaltymessage',
65 get_string('penaltyforeachincorrecttry', 'question'), 1);
2b7da645 66 $mform->addHelpButton('penaltymessage', 'penaltyforeachincorrecttry', 'question');
36703ed7 67 }
01ae934f 68
42e6506e
TH
69 public function data_preprocessing($question) {
70 $question = parent::data_preprocessing($question);
71
36703ed7 72 if (!empty($question->options->trueanswer)) {
73 $trueanswer = $question->options->answers[$question->options->trueanswer];
2b7da645
TH
74 $question->correctanswer = ($trueanswer->fraction != 0);
75
fe6ce234
DC
76 $draftid = file_get_submitted_draft_itemid('trueanswer');
77 $answerid = $question->options->trueanswer;
fe6ce234 78
fe6ce234 79 $question->feedbacktrue = array();
fe6ce234
DC
80 $question->feedbacktrue['format'] = $trueanswer->feedbackformat;
81 $question->feedbacktrue['text'] = file_prepare_draft_area(
4464734b
TH
82 $draftid, // draftid
83 $this->context->id, // context
84 'question', // component
85 'answerfeedback', // filarea
86 !empty($answerid) ? (int) $answerid : null, // itemid
87 $this->fileoptions, // options
88 $trueanswer->feedback // text
fe6ce234
DC
89 );
90 $question->feedbacktrue['itemid'] = $draftid;
91 }
2b7da645 92
fe6ce234
DC
93 if (!empty($question->options->falseanswer)) {
94 $falseanswer = $question->options->answers[$question->options->falseanswer];
2b7da645 95
fe6ce234
DC
96 $draftid = file_get_submitted_draft_itemid('falseanswer');
97 $answerid = $question->options->falseanswer;
fe6ce234 98
fe6ce234 99 $question->feedbackfalse = array();
fe6ce234
DC
100 $question->feedbackfalse['format'] = $falseanswer->feedbackformat;
101 $question->feedbackfalse['text'] = file_prepare_draft_area(
4464734b 102 $draftid, // draftid
fe6ce234 103 $this->context->id, // context
4464734b
TH
104 'question', // component
105 'answerfeedback', // filarea
106 !empty($answerid) ? (int) $answerid : null, // itemid
fe6ce234 107 $this->fileoptions, // options
4464734b 108 $falseanswer->feedback // text
fe6ce234
DC
109 );
110 $question->feedbackfalse['itemid'] = $draftid;
36703ed7 111 }
ff58648f
TH
112
113 return $question;
36703ed7 114 }
01ae934f 115
2b7da645 116 public function qtype() {
36703ed7 117 return 'truefalse';
118 }
119}