MDL-38197 Script to generate standard-size large course for testing
[moodle.git] / admin / tool / generator / classes / make_form.php
CommitLineData
bc4054f9 1<?php
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
17defined('MOODLE_INTERNAL') || die();
18
19require_once($CFG->libdir . '/formslib.php');
20
21/**
22 * Form with options for creating large course.
23 *
24 * @package tool_generator
25 * @copyright 2013 The Open University
26 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 */
28class tool_generator_make_form extends moodleform {
29
30 public function definition() {
31 $mform = $this->_form;
32
33 $mform->addElement('select', 'size', get_string('size', 'tool_generator'),
34 tool_generator_backend::get_size_choices());
35 $mform->setDefault('size', tool_generator_backend::DEFAULT_SIZE);
36
37 $mform->addElement('text', 'shortname', get_string('shortnamecourse'));
38 $mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client');
39 $mform->setType('shortname', PARAM_TEXT);
40
41 $mform->addElement('submit', 'submit', get_string('createcourse', 'tool_generator'));
42 }
43
44 public function validation($data, $files) {
45 global $DB;
46 $errors = array();
47
48 // Check course doesn't already exist.
49 if (!empty($data['shortname'])) {
50 // Check shortname.
51 $error = tool_generator_backend::check_shortname_available($data['shortname']);
52 if ($error) {
53 $errors['shortname'] = $error;
54 }
55 }
56
57 return $errors;
58 }
59}