MDL-47430 core_grades: Adding behat test for alternative mingrade
[moodle.git] / enrol / users_forms.php
bloba854d80862e137ca8d25fe3572150dd1471a46ff
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/>.
17 /**
18 * Various enrol UI forms
20 * @package core_enrol
21 * @copyright 2010 Petr Skoda {@link http://skodak.org}
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 defined('MOODLE_INTERNAL') || die();
27 require_once("$CFG->libdir/formslib.php");
29 class enrol_users_assign_form extends moodleform {
30 function definition() {
31 global $CFG, $DB;
33 $mform = $this->_form;
35 $user = $this->_customdata['user'];
36 $course = $this->_customdata['course'];
37 $context = context_course::instance($course->id);
38 $assignable = $this->_customdata['assignable'];
39 $assignable = array_reverse($assignable, true); // students first
41 $ras = get_user_roles($context, $user->id, true);
42 foreach ($ras as $ra) {
43 unset($assignable[$ra->roleid]);
46 $mform->addElement('header','general', fullname($user));
48 $mform->addElement('select', 'roleid', get_string('addrole', 'role'), $assignable);
50 $mform->addElement('hidden', 'id');
51 $mform->setType('id', PARAM_INT);
53 $mform->addElement('hidden', 'user');
54 $mform->setType('user', PARAM_INT);
56 $mform->addElement('hidden', 'action');
57 $mform->setType('action', PARAM_ALPHANUMEXT);
59 $mform->addElement('hidden', 'ifilter');
60 $mform->setType('ifilter', PARAM_ALPHA);
62 $mform->addElement('hidden', 'page');
63 $mform->setType('page', PARAM_INT);
65 $mform->addElement('hidden', 'perpage');
66 $mform->setType('perpage', PARAM_INT);
68 $mform->addElement('hidden', 'sort');
69 $mform->setType('sort', PARAM_ALPHA);
71 $mform->addElement('hidden', 'dir');
72 $mform->setType('dir', PARAM_ALPHA);
74 $this->add_action_buttons();
76 $this->set_data(array('action'=>'assign', 'user'=>$user->id));
80 class enrol_users_addmember_form extends moodleform {
81 function definition() {
82 global $CFG, $DB;
84 $mform = $this->_form;
86 $user = $this->_customdata['user'];
87 $course = $this->_customdata['course'];
88 $context = context_course::instance($course->id, IGNORE_MISSING);
89 $allgroups = $this->_customdata['allgroups'];
90 $usergroups = groups_get_all_groups($course->id, $user->id, 0, 'g.id');
92 $options = array();
93 foreach ($allgroups as $group) {
94 if (isset($usergroups[$group->id])) {
95 continue;
97 $options[$group->id] = $group->name;
100 $mform->addElement('header','general', fullname($user));
102 $mform->addElement('select', 'groupid', get_string('addgroup', 'group'), $options);
104 $mform->addElement('hidden', 'id');
105 $mform->setType('id', PARAM_INT);
107 $mform->addElement('hidden', 'user');
108 $mform->setType('user', PARAM_INT);
110 $mform->addElement('hidden', 'action');
111 $mform->setType('action', PARAM_ALPHANUMEXT);
113 $mform->addElement('hidden', 'ifilter');
114 $mform->setType('ifilter', PARAM_ALPHA);
116 $mform->addElement('hidden', 'page');
117 $mform->setType('page', PARAM_INT);
119 $mform->addElement('hidden', 'perpage');
120 $mform->setType('perpage', PARAM_INT);
122 $mform->addElement('hidden', 'sort');
123 $mform->setType('sort', PARAM_ALPHA);
125 $mform->addElement('hidden', 'dir');
126 $mform->setType('dir', PARAM_ALPHA);
128 $this->add_action_buttons();
130 $this->set_data(array('action'=>'addmember', 'user'=>$user->id));
136 * Form that lets users filter the enrolled user list.
138 class enrol_users_filter_form extends moodleform {
139 function definition() {
140 global $CFG, $DB;
142 $manager = $this->_customdata['manager'];
144 $mform = $this->_form;
146 // Text search box.
147 $mform->addElement('text', 'search', get_string('search'));
148 $mform->setType('search', PARAM_RAW);
150 // Filter by enrolment plugin type.
151 $mform->addElement('select', 'ifilter', get_string('enrolmentinstances', 'enrol'),
152 array(0 => get_string('all')) + (array)$manager->get_enrolment_instance_names());
154 // Role select dropdown includes all roles, but using course-specific
155 // names if applied. The reason for not restricting to roles that can
156 // be assigned at course level is that upper-level roles display in the
157 // enrolments table so it makes sense to let users filter by them.
158 $allroles = $manager->get_all_roles();
159 $rolenames = array();
160 foreach ($allroles as $id => $role) {
161 $rolenames[$id] = $role->localname;
163 $mform->addElement('select', 'role', get_string('role'),
164 array(0 => get_string('all')) + $rolenames);
166 // Filter by group.
167 $allgroups = $manager->get_all_groups();
168 $groupsmenu[0] = get_string('allparticipants');
169 foreach($allgroups as $gid => $unused) {
170 $groupsmenu[$gid] = $allgroups[$gid]->name;
172 if (count($groupsmenu) > 1) {
173 $mform->addElement('select', 'filtergroup', get_string('group'), $groupsmenu);
176 // Status active/inactive.
177 $mform->addElement('select', 'status', get_string('status'),
178 array(-1 => get_string('all'),
179 ENROL_USER_ACTIVE => get_string('active'),
180 ENROL_USER_SUSPENDED => get_string('inactive')));
182 // Submit button does not use add_action_buttons because that adds
183 // another fieldset which causes the CSS style to break in an unfixable
184 // way due to fieldset quirks.
185 $group = array();
186 $group[] = $mform->createElement('submit', 'submitbutton', get_string('filter'));
187 $group[] = $mform->createElement('submit', 'resetbutton', get_string('reset'));
188 $mform->addGroup($group, 'buttons', '', ' ', false);
190 // Add hidden fields required by page.
191 $mform->addElement('hidden', 'id', $this->_customdata['id']);
192 $mform->setType('id', PARAM_INT);