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