Merge branch 'MDL-61203_m35v3' of git://github.com/sbourget/moodle
[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() {
a13d4fbd 45 $mform = $this->_form;
6e9b6ba2 46
47 // Standard fields at the start of the form.
48 $mform->addElement('header', 'generalheader', get_string("general", 'form'));
49
5e8a85aa 50 $mform->addElement('questioncategory', 'category', get_string('category', 'question'),
271e6dec 51 array('contexts' => $this->contexts->having_cap('moodle/question:useall')));
6e9b6ba2 52
59f26004
TH
53 $mform->addElement('advcheckbox', 'questiontext[text]',
54 get_string('includingsubcategories', 'qtype_random'), null, null, array(0, 1));
6e9b6ba2 55
6e9b6ba2 56 $mform->addElement('hidden', 'qtype');
57 $mform->setType('qtype', PARAM_ALPHA);
58
72553162 59 $this->add_hidden_fields();
271e6dec 60
6e9b6ba2 61 $buttonarray = array();
94dbfb3a
TH
62 $buttonarray[] = $mform->createElement('submit', 'submitbutton', get_string('savechanges'));
63 $buttonarray[] = $mform->createElement('cancel');
6e9b6ba2 64 $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
65 $mform->closeHeaderBefore('buttonar');
66 }
fe6ce234 67
f9b0500f 68 public function set_data($question) {
94dbfb3a
TH
69 $question->questiontext = array('text' => $question->questiontext);
70 // We don't want the complex stuff in the base class to run.
71 moodleform::set_data($question);
72 }
73
f9b0500f 74 public function validation($fromform, $files) {
3d9645ae 75 // Validation of category is not relevant for this question type.
76
3efbe6bc 77 return array();
78 }
fe6ce234 79
f9b0500f 80 public function qtype() {
6e9b6ba2 81 return 'random';
82 }
83}