weekly release 2.3dev (blame stronk7 for 0202 mistake)
[moodle.git] / question / type / random / edit_random_form.php
CommitLineData
aeb15530 1<?php
f9b0500f
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
6e9b6ba2 17/**
18 * Defines the editing form for the random question type.
19 *
b04a4319
TH
20 * @package qtype
21 * @subpackage random
22 * @copyright 2007 Jamie Pratt me@jamiep.org
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
6e9b6ba2 24 */
25
a17b297d
TH
26
27defined('MOODLE_INTERNAL') || die();
28
29
6e9b6ba2 30/**
31 * random editing form definition.
b04a4319
TH
32 *
33 * @copyright 2007 Jamie Pratt me@jamiep.org
34 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
6e9b6ba2 35 */
42663bb7 36class qtype_random_edit_form extends question_edit_form {
6e9b6ba2 37 /**
38 * Build the form definition.
39 *
40 * This adds all the form files that the default question type supports.
41 * If your question type does not support all these fields, then you can
42 * override this method and remove the ones you don't want with $mform->removeElement().
43 */
c7df5006 44 protected function definition() {
6e9b6ba2 45 global $COURSE, $CFG;
46
47 $qtype = $this->qtype();
48 $langfile = "qtype_$qtype";
49
a13d4fbd 50 $mform = $this->_form;
6e9b6ba2 51
52 // Standard fields at the start of the form.
53 $mform->addElement('header', 'generalheader', get_string("general", 'form'));
54
5e8a85aa 55 $mform->addElement('questioncategory', 'category', get_string('category', 'question'),
271e6dec 56 array('contexts' => $this->contexts->having_cap('moodle/question:useall')));
6e9b6ba2 57
59f26004
TH
58 $mform->addElement('advcheckbox', 'questiontext[text]',
59 get_string('includingsubcategories', 'qtype_random'), null, null, array(0, 1));
6e9b6ba2 60
24e8b9b6 61 $mform->addElement('hidden', 'name');
62 $mform->setType('name', PARAM_ALPHA);
63 $mform->setDefault('name', '');
64
65 $mform->addElement('hidden', 'tags[]');
66 $mform->setType('tags[]', PARAM_ALPHA);
67 $mform->setDefault('tags[]', '');
68
6e9b6ba2 69 // Standard fields at the end of the form.
24f7485b 70 $mform->addElement('hidden', 'questiontextformat', 0);
71 $mform->setType('questiontextformat', PARAM_INT);
72
6e9b6ba2 73 $mform->addElement('hidden', 'id');
74 $mform->setType('id', PARAM_INT);
75
76 $mform->addElement('hidden', 'qtype');
77 $mform->setType('qtype', PARAM_ALPHA);
78
79 $mform->addElement('hidden', 'inpopup');
80 $mform->setType('inpopup', PARAM_INT);
81
82 $mform->addElement('hidden', 'versioning');
83 $mform->setType('versioning', PARAM_BOOL);
84
271e6dec 85 $mform->addElement('hidden', 'cmid');
86 $mform->setType('cmid', PARAM_INT);
87 $mform->setDefault('cmid', 0);
88
89 $mform->addElement('hidden', 'courseid');
90 $mform->setType('courseid', PARAM_INT);
91 $mform->setDefault('courseid', 0);
92
93 $mform->addElement('hidden', 'returnurl');
94 $mform->setType('returnurl', PARAM_LOCALURL);
95 $mform->setDefault('returnurl', 0);
96
6e9b6ba2 97 $buttonarray = array();
94dbfb3a
TH
98 $buttonarray[] = $mform->createElement('submit', 'submitbutton', get_string('savechanges'));
99 $buttonarray[] = $mform->createElement('cancel');
6e9b6ba2 100 $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
101 $mform->closeHeaderBefore('buttonar');
102 }
fe6ce234 103
f9b0500f 104 public function set_data($question) {
94dbfb3a
TH
105 $question->questiontext = array('text' => $question->questiontext);
106 // We don't want the complex stuff in the base class to run.
107 moodleform::set_data($question);
108 }
109
f9b0500f 110 public function validation($fromform, $files) {
3efbe6bc 111 //validation of category
112 //is not relevant for this question type
113 return array();
114 }
fe6ce234 115
f9b0500f 116 public function qtype() {
6e9b6ba2 117 return 'random';
118 }
119}