PageRenderTime 22ms CodeModel.GetById 10ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/enrol/users_forms.php

https://bitbucket.org/synergylearning/campusconnect
PHP | 194 lines | 112 code | 46 blank | 36 comment | 3 complexity | 95e527f2f8a98956418f60918ec25286 MD5 | raw file
  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
 17/**
 18 * Various enrol UI forms
 19 *
 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
 23 */
 24
 25defined('MOODLE_INTERNAL') || die();
 26
 27require_once("$CFG->libdir/formslib.php");
 28
 29class enrol_users_assign_form extends moodleform {
 30    function definition() {
 31        global $CFG, $DB;
 32
 33        $mform = $this->_form;
 34
 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
 40
 41        $ras = get_user_roles($context, $user->id, true);
 42        foreach ($ras as $ra) {
 43            unset($assignable[$ra->roleid]);
 44        }
 45
 46        $mform->addElement('header','general', fullname($user));
 47
 48        $mform->addElement('select', 'roleid', get_string('addrole', 'role'), $assignable);
 49
 50        $mform->addElement('hidden', 'id');
 51        $mform->setType('id', PARAM_INT);
 52
 53        $mform->addElement('hidden', 'user');
 54        $mform->setType('user', PARAM_INT);
 55
 56        $mform->addElement('hidden', 'action');
 57        $mform->setType('action', PARAM_ALPHANUMEXT);
 58
 59        $mform->addElement('hidden', 'ifilter');
 60        $mform->setType('ifilter', PARAM_ALPHA);
 61
 62        $mform->addElement('hidden', 'page');
 63        $mform->setType('page', PARAM_INT);
 64
 65        $mform->addElement('hidden', 'perpage');
 66        $mform->setType('perpage', PARAM_INT);
 67
 68        $mform->addElement('hidden', 'sort');
 69        $mform->setType('sort', PARAM_ALPHA);
 70
 71        $mform->addElement('hidden', 'dir');
 72        $mform->setType('dir', PARAM_ALPHA);
 73
 74        $this->add_action_buttons();
 75
 76        $this->set_data(array('action'=>'assign', 'user'=>$user->id));
 77    }
 78}
 79
 80class enrol_users_addmember_form extends moodleform {
 81    function definition() {
 82        global $CFG, $DB;
 83
 84        $mform = $this->_form;
 85
 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');
 91
 92        $options = array();
 93        foreach ($allgroups as $group) {
 94            if (isset($usergroups[$group->id])) {
 95                continue;
 96            }
 97            $options[$group->id] = $group->name;
 98        }
 99
100        $mform->addElement('header','general', fullname($user));
101
102        $mform->addElement('select', 'groupid', get_string('addgroup', 'group'), $options);
103
104        $mform->addElement('hidden', 'id');
105        $mform->setType('id', PARAM_INT);
106
107        $mform->addElement('hidden', 'user');
108        $mform->setType('user', PARAM_INT);
109
110        $mform->addElement('hidden', 'action');
111        $mform->setType('action', PARAM_ALPHANUMEXT);
112
113        $mform->addElement('hidden', 'ifilter');
114        $mform->setType('ifilter', PARAM_ALPHA);
115
116        $mform->addElement('hidden', 'page');
117        $mform->setType('page', PARAM_INT);
118
119        $mform->addElement('hidden', 'perpage');
120        $mform->setType('perpage', PARAM_INT);
121
122        $mform->addElement('hidden', 'sort');
123        $mform->setType('sort', PARAM_ALPHA);
124
125        $mform->addElement('hidden', 'dir');
126        $mform->setType('dir', PARAM_ALPHA);
127
128        $this->add_action_buttons();
129
130        $this->set_data(array('action'=>'addmember', 'user'=>$user->id));
131    }
132}
133
134
135/**
136 * Form that lets users filter the enrolled user list.
137 */
138class enrol_users_filter_form extends moodleform {
139    function definition() {
140        global $CFG, $DB;
141
142        $manager = $this->_customdata['manager'];
143
144        $mform = $this->_form;
145
146        // Text search box.
147        $mform->addElement('text', 'search', get_string('search'));
148        $mform->setType('search', PARAM_RAW);
149
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());
153
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;
162        }
163        $mform->addElement('select', 'role', get_string('role'),
164                array(0 => get_string('all')) + $rolenames);
165
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;
171        }
172        if (count($groupsmenu) > 1) {
173            $mform->addElement('select', 'filtergroup', get_string('group'), $groupsmenu);
174        }
175
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')));
181
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);
189
190        // Add hidden fields required by page.
191        $mform->addElement('hidden', 'id', $this->_customdata['id']);
192        $mform->setType('id', PARAM_INT);
193    }
194}