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