2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
19 * A form for creating and editing groupings.
21 * @copyright 2006 The Open University, N.D.Freear AT open.ac.uk, J.White AT open.ac.uk
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 if (!defined('MOODLE_INTERNAL')) {
27 die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
30 require_once($CFG->dirroot
.'/lib/formslib.php');
35 * @copyright 2006 The Open University, N.D.Freear AT open.ac.uk, J.White AT open.ac.uk
36 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
39 class grouping_form
extends moodleform
{
44 function definition () {
45 global $USER, $CFG, $COURSE;
47 $mform =& $this->_form
;
48 $editoroptions = $this->_customdata
['editoroptions'];
50 $mform->addElement('text','name', get_string('groupingname', 'group'),'maxlength="254" size="50"');
51 $mform->addRule('name', get_string('required'), 'required', null, 'server');
52 $mform->setType('name', PARAM_MULTILANG
);
54 $mform->addElement('editor', 'description_editor', get_string('groupingdescription', 'group'), null, $editoroptions);
55 $mform->setType('description_editor', PARAM_RAW
);
57 $mform->addElement('hidden','id');
58 $mform->setType('id', PARAM_INT
);
60 $mform->addElement('hidden', 'courseid');
61 $mform->setType('courseid', PARAM_INT
);
63 $this->add_action_buttons();
71 * @return array $errors An array of validataion errors for the form.
73 function validation($data, $files) {
76 $errors = parent
::validation($data, $files);
78 $name = trim($data['name']);
79 if ($data['id'] and $grouping = $DB->get_record('groupings', array('id'=>$data['id']))) {
80 if (textlib
::strtolower($grouping->name
) != textlib
::strtolower($name)) {
81 if (groups_get_grouping_by_name($COURSE->id
, $name)) {
82 $errors['name'] = get_string('groupingnameexists', 'group', $name);
86 } else if (groups_get_grouping_by_name($COURSE->id
, $name)) {
87 $errors['name'] = get_string('groupingnameexists', 'group', $name);