MDL-32932: Add quickgrading support to mod_assign
[moodle.git] / group / group_form.php
blob37044effcb3507e7fd93e6b74cdae03cbd103c18
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.
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/>.
18 /**
19 * A form for the creation and editing of groups.
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
23 * @package core_group
26 defined('MOODLE_INTERNAL') || die;
28 require_once($CFG->dirroot.'/lib/formslib.php');
30 /**
31 * Group form class
33 * @copyright 2006 The Open University, N.D.Freear AT open.ac.uk, J.White AT open.ac.uk
34 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
35 * @package core_group
37 class group_form extends moodleform {
39 /**
40 * Definition of the form
42 function definition () {
43 global $USER, $CFG, $COURSE;
45 $mform =& $this->_form;
46 $editoroptions = $this->_customdata['editoroptions'];
48 $mform->addElement('text','name', get_string('groupname', 'group'),'maxlength="254" size="50"');
49 $mform->addRule('name', get_string('required'), 'required', null, 'client');
50 $mform->setType('name', PARAM_MULTILANG);
52 $mform->addElement('editor', 'description_editor', get_string('groupdescription', 'group'), null, $editoroptions);
53 $mform->setType('description_editor', PARAM_RAW);
55 $mform->addElement('passwordunmask', 'enrolmentkey', get_string('enrolmentkey', 'group'), 'maxlength="254" size="24"', get_string('enrolmentkey', 'group'));
56 $mform->addHelpButton('enrolmentkey', 'enrolmentkey', 'group');
57 $mform->setType('enrolmentkey', PARAM_RAW);
59 if (!empty($CFG->gdversion)) {
60 $options = array(get_string('no'), get_string('yes'));
61 $mform->addElement('select', 'hidepicture', get_string('hidepicture'), $options);
63 $mform->addElement('filepicker', 'imagefile', get_string('newpicture', 'group'));
64 $mform->addHelpButton('imagefile', 'newpicture', 'group');
67 $mform->addElement('hidden','id');
68 $mform->setType('id', PARAM_INT);
70 $mform->addElement('hidden','courseid');
71 $mform->setType('courseid', PARAM_INT);
73 $this->add_action_buttons();
76 /**
77 * Form validation
79 * @param array $data
80 * @param array $files
81 * @return array $errors An array of errors
83 function validation($data, $files) {
84 global $COURSE, $DB, $CFG;
86 $errors = parent::validation($data, $files);
88 $name = trim($data['name']);
89 if ($data['id'] and $group = $DB->get_record('groups', array('id'=>$data['id']))) {
90 if (textlib::strtolower($group->name) != textlib::strtolower($name)) {
91 if (groups_get_group_by_name($COURSE->id, $name)) {
92 $errors['name'] = get_string('groupnameexists', 'group', $name);
96 if (!empty($CFG->groupenrolmentkeypolicy) and $data['enrolmentkey'] != '' and $group->enrolmentkey !== $data['enrolmentkey']) {
97 // enforce password policy only if changing password
98 $errmsg = '';
99 if (!check_password_policy($data['enrolmentkey'], $errmsg)) {
100 $errors['enrolmentkey'] = $errmsg;
104 } else if (groups_get_group_by_name($COURSE->id, $name)) {
105 $errors['name'] = get_string('groupnameexists', 'group', $name);
108 return $errors;
112 * Get editor options for this form
114 * @return array An array of options
116 function get_editor_options() {
117 return $this->_customdata['editoroptions'];