PageRenderTime 45ms CodeModel.GetById 17ms RepoModel.GetById 0ms 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
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-3.0, GPL-3.0, LGPL-2.1, Apache-2.0, BSD-3-Clause, AGPL-3.0
  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. * Various enrol UI forms
  18. *
  19. * @package core_enrol
  20. * @copyright 2010 Petr Skoda {@link http://skodak.org}
  21. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  22. */
  23. defined('MOODLE_INTERNAL') || die();
  24. require_once("$CFG->libdir/formslib.php");
  25. class enrol_users_assign_form extends moodleform {
  26. function definition() {
  27. global $CFG, $DB;
  28. $mform = $this->_form;
  29. $user = $this->_customdata['user'];
  30. $course = $this->_customdata['course'];
  31. $context = context_course::instance($course->id);
  32. $assignable = $this->_customdata['assignable'];
  33. $assignable = array_reverse($assignable, true); // students first
  34. $ras = get_user_roles($context, $user->id, true);
  35. foreach ($ras as $ra) {
  36. unset($assignable[$ra->roleid]);
  37. }
  38. $mform->addElement('header','general', fullname($user));
  39. $mform->addElement('select', 'roleid', get_string('addrole', 'role'), $assignable);
  40. $mform->addElement('hidden', 'id');
  41. $mform->setType('id', PARAM_INT);
  42. $mform->addElement('hidden', 'user');
  43. $mform->setType('user', PARAM_INT);
  44. $mform->addElement('hidden', 'action');
  45. $mform->setType('action', PARAM_ALPHANUMEXT);
  46. $mform->addElement('hidden', 'ifilter');
  47. $mform->setType('ifilter', PARAM_ALPHA);
  48. $mform->addElement('hidden', 'page');
  49. $mform->setType('page', PARAM_INT);
  50. $mform->addElement('hidden', 'perpage');
  51. $mform->setType('perpage', PARAM_INT);
  52. $mform->addElement('hidden', 'sort');
  53. $mform->setType('sort', PARAM_ALPHA);
  54. $mform->addElement('hidden', 'dir');
  55. $mform->setType('dir', PARAM_ALPHA);
  56. $this->add_action_buttons();
  57. $this->set_data(array('action'=>'assign', 'user'=>$user->id));
  58. }
  59. }
  60. class enrol_users_addmember_form extends moodleform {
  61. function definition() {
  62. global $CFG, $DB;
  63. $mform = $this->_form;
  64. $user = $this->_customdata['user'];
  65. $course = $this->_customdata['course'];
  66. $context = context_course::instance($course->id, IGNORE_MISSING);
  67. $allgroups = $this->_customdata['allgroups'];
  68. $usergroups = groups_get_all_groups($course->id, $user->id, 0, 'g.id');
  69. $options = array();
  70. foreach ($allgroups as $group) {
  71. if (isset($usergroups[$group->id])) {
  72. continue;
  73. }
  74. $options[$group->id] = $group->name;
  75. }
  76. $mform->addElement('header','general', fullname($user));
  77. $mform->addElement('select', 'groupid', get_string('addgroup', 'group'), $options);
  78. $mform->addElement('hidden', 'id');
  79. $mform->setType('id', PARAM_INT);
  80. $mform->addElement('hidden', 'user');
  81. $mform->setType('user', PARAM_INT);
  82. $mform->addElement('hidden', 'action');
  83. $mform->setType('action', PARAM_ALPHANUMEXT);
  84. $mform->addElement('hidden', 'ifilter');
  85. $mform->setType('ifilter', PARAM_ALPHA);
  86. $mform->addElement('hidden', 'page');
  87. $mform->setType('page', PARAM_INT);
  88. $mform->addElement('hidden', 'perpage');
  89. $mform->setType('perpage', PARAM_INT);
  90. $mform->addElement('hidden', 'sort');
  91. $mform->setType('sort', PARAM_ALPHA);
  92. $mform->addElement('hidden', 'dir');
  93. $mform->setType('dir', PARAM_ALPHA);
  94. $this->add_action_buttons();
  95. $this->set_data(array('action'=>'addmember', 'user'=>$user->id));
  96. }
  97. }
  98. /**
  99. * Form that lets users filter the enrolled user list.
  100. */
  101. class enrol_users_filter_form extends moodleform {
  102. function definition() {
  103. global $CFG, $DB;
  104. $manager = $this->_customdata['manager'];
  105. $mform = $this->_form;
  106. // Text search box.
  107. $mform->addElement('text', 'search', get_string('search'));
  108. $mform->setType('search', PARAM_RAW);
  109. // Filter by enrolment plugin type.
  110. $mform->addElement('select', 'ifilter', get_string('enrolmentinstances', 'enrol'),
  111. array(0 => get_string('all')) + (array)$manager->get_enrolment_instance_names());
  112. // Role select dropdown includes all roles, but using course-specific
  113. // names if applied. The reason for not restricting to roles that can
  114. // be assigned at course level is that upper-level roles display in the
  115. // enrolments table so it makes sense to let users filter by them.
  116. $allroles = $manager->get_all_roles();
  117. $rolenames = array();
  118. foreach ($allroles as $id => $role) {
  119. $rolenames[$id] = $role->localname;
  120. }
  121. $mform->addElement('select', 'role', get_string('role'),
  122. array(0 => get_string('all')) + $rolenames);
  123. // Filter by group.
  124. $allgroups = $manager->get_all_groups();
  125. $groupsmenu[0] = get_string('allparticipants');
  126. foreach($allgroups as $gid => $unused) {
  127. $groupsmenu[$gid] = $allgroups[$gid]->name;
  128. }
  129. if (count($groupsmenu) > 1) {
  130. $mform->addElement('select', 'filtergroup', get_string('group'), $groupsmenu);
  131. }
  132. // Status active/inactive.
  133. $mform->addElement('select', 'status', get_string('status'),
  134. array(-1 => get_string('all'),
  135. ENROL_USER_ACTIVE => get_string('active'),
  136. ENROL_USER_SUSPENDED => get_string('inactive')));
  137. // Submit button does not use add_action_buttons because that adds
  138. // another fieldset which causes the CSS style to break in an unfixable
  139. // way due to fieldset quirks.
  140. $group = array();
  141. $group[] = $mform->createElement('submit', 'submitbutton', get_string('filter'));
  142. $group[] = $mform->createElement('submit', 'resetbutton', get_string('reset'));
  143. $mform->addGroup($group, 'buttons', '', ' ', false);
  144. // Add hidden fields required by page.
  145. $mform->addElement('hidden', 'id', $this->_customdata['id']);
  146. $mform->setType('id', PARAM_INT);
  147. }
  148. }