Merge branch 'MDL-68722-310' of https://github.com/matt-catalyst/moodle into MOODLE_3...
[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);
8971ddd5 63 $mform->setType('penalty', PARAM_FLOAT);
2b7da645 64
dcd69f8d
TH
65 $mform->addElement('static', 'penaltymessage',
66 get_string('penaltyforeachincorrecttry', 'question'), 1);
2b7da645 67 $mform->addHelpButton('penaltymessage', 'penaltyforeachincorrecttry', 'question');
36703ed7 68 }
01ae934f 69
42e6506e
TH
70 public function data_preprocessing($question) {
71 $question = parent::data_preprocessing($question);
72
36703ed7 73 if (!empty($question->options->trueanswer)) {
74 $trueanswer = $question->options->answers[$question->options->trueanswer];
2b7da645
TH
75 $question->correctanswer = ($trueanswer->fraction != 0);
76
fe6ce234
DC
77 $draftid = file_get_submitted_draft_itemid('trueanswer');
78 $answerid = $question->options->trueanswer;
fe6ce234 79
fe6ce234 80 $question->feedbacktrue = array();
fe6ce234
DC
81 $question->feedbacktrue['format'] = $trueanswer->feedbackformat;
82 $question->feedbacktrue['text'] = file_prepare_draft_area(
3d9645ae 83 $draftid, // Draftid
4464734b
TH
84 $this->context->id, // context
85 'question', // component
86 'answerfeedback', // filarea
87 !empty($answerid) ? (int) $answerid : null, // itemid
88 $this->fileoptions, // options
3d9645ae 89 $trueanswer->feedback // text.
fe6ce234
DC
90 );
91 $question->feedbacktrue['itemid'] = $draftid;
92 }
2b7da645 93
fe6ce234
DC
94 if (!empty($question->options->falseanswer)) {
95 $falseanswer = $question->options->answers[$question->options->falseanswer];
2b7da645 96
fe6ce234
DC
97 $draftid = file_get_submitted_draft_itemid('falseanswer');
98 $answerid = $question->options->falseanswer;
fe6ce234 99
fe6ce234 100 $question->feedbackfalse = array();
fe6ce234
DC
101 $question->feedbackfalse['format'] = $falseanswer->feedbackformat;
102 $question->feedbackfalse['text'] = file_prepare_draft_area(
3d9645ae 103 $draftid, // Draftid
fe6ce234 104 $this->context->id, // context
4464734b
TH
105 'question', // component
106 'answerfeedback', // filarea
107 !empty($answerid) ? (int) $answerid : null, // itemid
fe6ce234 108 $this->fileoptions, // options
3d9645ae 109 $falseanswer->feedback // text.
fe6ce234
DC
110 );
111 $question->feedbackfalse['itemid'] = $draftid;
36703ed7 112 }
ff58648f
TH
113
114 return $question;
36703ed7 115 }
01ae934f 116
2b7da645 117 public function qtype() {
36703ed7 118 return 'truefalse';
119 }
120}