Merge branch 'MDL-68438_310' of https://github.com/t-schroeder/moodle into MOODLE_310...
[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'),
3b8f3198 51 array('contexts' => $this->contexts->having_cap('moodle/question:useall'), 'top' => true));
6e9b6ba2 52
59f26004
TH
53 $mform->addElement('advcheckbox', 'questiontext[text]',
54 get_string('includingsubcategories', 'qtype_random'), null, null, array(0, 1));
6e9b6ba2 55
3b8f3198
SR
56 $tops = question_get_top_categories_for_contexts(array_column($this->contexts->all(), 'id'));
57 $mform->hideIf('questiontext[text]', 'category', 'in', $tops);
58
6e9b6ba2 59 $mform->addElement('hidden', 'qtype');
60 $mform->setType('qtype', PARAM_ALPHA);
61
72553162 62 $this->add_hidden_fields();
271e6dec 63
6e9b6ba2 64 $buttonarray = array();
94dbfb3a
TH
65 $buttonarray[] = $mform->createElement('submit', 'submitbutton', get_string('savechanges'));
66 $buttonarray[] = $mform->createElement('cancel');
6e9b6ba2 67 $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
68 $mform->closeHeaderBefore('buttonar');
69 }
fe6ce234 70
f9b0500f 71 public function set_data($question) {
94dbfb3a
TH
72 $question->questiontext = array('text' => $question->questiontext);
73 // We don't want the complex stuff in the base class to run.
74 moodleform::set_data($question);
75 }
76
f9b0500f 77 public function validation($fromform, $files) {
3d9645ae 78 // Validation of category is not relevant for this question type.
79
3efbe6bc 80 return array();
81 }
fe6ce234 82
f9b0500f 83 public function qtype() {
6e9b6ba2 84 return 'random';
85 }
86}