mirror of
https://github.com/moodle/moodle.git
synced 2025-03-14 12:40:01 +01:00
MDL-35052 show all enrolled users in enrol UI included those enrolled via disabled plugins
This commit is contained in:
parent
d71c486507
commit
005e57a225
@ -63,7 +63,7 @@ switch ($action) {
|
||||
case 'unenrol':
|
||||
$ue = $DB->get_record('user_enrolments', array('id'=>required_param('ue', PARAM_INT)), '*', MUST_EXIST);
|
||||
list ($instance, $plugin) = $manager->get_user_enrolment_components($ue);
|
||||
if (!$instance || !$plugin || !$plugin->allow_unenrol_user($instance, $ue) || !has_capability("enrol/$instance->enrol:unenrol", $manager->get_context()) || !$manager->unenrol_user($ue)) {
|
||||
if (!$instance || !$plugin || !enrol_is_enabled($instance->enrol) || !$plugin->allow_unenrol_user($instance, $ue) || !has_capability("enrol/$instance->enrol:unenrol", $manager->get_context()) || !$manager->unenrol_user($ue)) {
|
||||
throw new enrol_ajax_exception('unenrolnotpermitted');
|
||||
}
|
||||
break;
|
||||
|
@ -97,6 +97,7 @@ class course_enrolment_manager {
|
||||
private $_instances = null;
|
||||
private $_inames = null;
|
||||
private $_plugins = null;
|
||||
private $_allplugins = null;
|
||||
private $_roles = null;
|
||||
private $_assignableroles = null;
|
||||
private $_assignablerolesothers = null;
|
||||
@ -397,11 +398,13 @@ class course_enrolment_manager {
|
||||
/**
|
||||
* Returns all of the enrolment instances for this course.
|
||||
*
|
||||
* NOTE: since 2.4 it includes instances of disabled plugins too.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_enrolment_instances() {
|
||||
if ($this->_instances === null) {
|
||||
$this->_instances = enrol_get_instances($this->course->id, true);
|
||||
$this->_instances = enrol_get_instances($this->course->id, false);
|
||||
}
|
||||
return $this->_instances;
|
||||
}
|
||||
@ -409,12 +412,14 @@ class course_enrolment_manager {
|
||||
/**
|
||||
* Returns the names for all of the enrolment instances for this course.
|
||||
*
|
||||
* NOTE: since 2.4 it includes instances of disabled plugins too.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_enrolment_instance_names() {
|
||||
if ($this->_inames === null) {
|
||||
$instances = $this->get_enrolment_instances();
|
||||
$plugins = $this->get_enrolment_plugins();
|
||||
$plugins = $this->get_enrolment_plugins(false);
|
||||
foreach ($instances as $key=>$instance) {
|
||||
if (!isset($plugins[$instance->enrol])) {
|
||||
// weird, some broken stuff in plugin
|
||||
@ -430,13 +435,29 @@ class course_enrolment_manager {
|
||||
/**
|
||||
* Gets all of the enrolment plugins that are active for this course.
|
||||
*
|
||||
* @param bool $onlyenabled return only enabled enrol plugins
|
||||
* @return array
|
||||
*/
|
||||
public function get_enrolment_plugins() {
|
||||
public function get_enrolment_plugins($onlyenabled = true) {
|
||||
if ($this->_plugins === null) {
|
||||
$this->_plugins = enrol_get_plugins(true);
|
||||
}
|
||||
return $this->_plugins;
|
||||
|
||||
if ($onlyenabled) {
|
||||
return $this->_plugins;
|
||||
}
|
||||
|
||||
if ($this->_allplugins === null) {
|
||||
// Make sure we have the same objects in _allplugins and _plugins.
|
||||
$this->_allplugins = $this->_plugins;
|
||||
foreach (enrol_get_plugins(false) as $name=>$plugin) {
|
||||
if (!isset($this->_allplugins[$name])) {
|
||||
$this->_allplugins[$name] = $plugin;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->_allplugins;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -522,7 +543,7 @@ class course_enrolment_manager {
|
||||
$userenrolment = $DB->get_record('user_enrolments', array('id'=>(int)$userenrolment));
|
||||
}
|
||||
$instances = $this->get_enrolment_instances();
|
||||
$plugins = $this->get_enrolment_plugins();
|
||||
$plugins = $this->get_enrolment_plugins(false);
|
||||
if (!$userenrolment || !isset($instances[$userenrolment->enrolid])) {
|
||||
return array(false, false);
|
||||
}
|
||||
@ -675,7 +696,7 @@ class course_enrolment_manager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the enrolments this user has in the course
|
||||
* Gets the enrolments this user has in the course - including all suspended plugins and instances.
|
||||
*
|
||||
* @global moodle_database $DB
|
||||
* @param int $userid
|
||||
@ -687,7 +708,7 @@ class course_enrolment_manager {
|
||||
$params['userid'] = $userid;
|
||||
$userenrolments = $DB->get_records_select('user_enrolments', "enrolid $instancessql AND userid = :userid", $params);
|
||||
$instances = $this->get_enrolment_instances();
|
||||
$plugins = $this->get_enrolment_plugins();
|
||||
$plugins = $this->get_enrolment_plugins(false);
|
||||
$inames = $this->get_enrolment_instance_names();
|
||||
foreach ($userenrolments as &$ue) {
|
||||
$ue->enrolmentinstance = $instances[$ue->enrolid];
|
||||
@ -829,6 +850,8 @@ class course_enrolment_manager {
|
||||
$url = new moodle_url($pageurl, $this->get_url_params());
|
||||
$extrafields = get_extra_user_fields($context);
|
||||
|
||||
$enabledplugins = $this->get_enrolment_plugins(true);
|
||||
|
||||
$userdetails = array();
|
||||
foreach ($users as $user) {
|
||||
$details = $this->prepare_user_for_display($user, $extrafields, $now);
|
||||
@ -849,7 +872,15 @@ class course_enrolment_manager {
|
||||
// Enrolments
|
||||
$details['enrolments'] = array();
|
||||
foreach ($this->get_user_enrolments($user->id) as $ue) {
|
||||
if ($ue->timestart and $ue->timeend) {
|
||||
if (!isset($enabledplugins[$ue->enrolmentinstance->enrol])) {
|
||||
$details['enrolments'][$ue->id] = array(
|
||||
'text' => $ue->enrolmentinstancename,
|
||||
'period' => null,
|
||||
'dimmed' => true,
|
||||
'actions' => array()
|
||||
);
|
||||
continue;
|
||||
} else if ($ue->timestart and $ue->timeend) {
|
||||
$period = get_string('periodstartend', 'enrol', array('start'=>userdate($ue->timestart), 'end'=>userdate($ue->timeend)));
|
||||
$periodoutside = ($ue->timestart && $ue->timeend && $now < $ue->timestart && $now > $ue->timeend);
|
||||
} else if ($ue->timestart) {
|
||||
@ -909,7 +940,7 @@ class course_enrolment_manager {
|
||||
}
|
||||
|
||||
public function get_manual_enrol_buttons() {
|
||||
$plugins = $this->get_enrolment_plugins();
|
||||
$plugins = $this->get_enrolment_plugins(true); // Skip disabled plugins.
|
||||
$buttons = array();
|
||||
foreach ($plugins as $plugin) {
|
||||
$newbutton = $plugin->get_manual_enrol_button($this);
|
||||
@ -941,7 +972,7 @@ class course_enrolment_manager {
|
||||
*/
|
||||
public function get_filtered_enrolment_plugin() {
|
||||
$instances = $this->get_enrolment_instances();
|
||||
$plugins = $this->get_enrolment_plugins();
|
||||
$plugins = $this->get_enrolment_plugins(false);
|
||||
|
||||
if (empty($this->instancefilter) || !array_key_exists($this->instancefilter, $instances)) {
|
||||
return false;
|
||||
@ -965,7 +996,7 @@ class course_enrolment_manager {
|
||||
global $DB;
|
||||
|
||||
$instances = $this->get_enrolment_instances();
|
||||
$plugins = $this->get_enrolment_plugins();
|
||||
$plugins = $this->get_enrolment_plugins(false);
|
||||
|
||||
if (!empty($this->instancefilter)) {
|
||||
$instancesql = ' = :instanceid';
|
||||
|
@ -113,11 +113,14 @@ switch ($action) {
|
||||
|
||||
$user = $DB->get_record('user', array('id'=>$userid), '*', MUST_EXIST);
|
||||
$instances = $manager->get_enrolment_instances();
|
||||
$plugins = $manager->get_enrolment_plugins();
|
||||
$plugins = $manager->get_enrolment_plugins(true); // Do not allow actions on disabled plugins.
|
||||
if (!array_key_exists($enrolid, $instances)) {
|
||||
throw new enrol_ajax_exception('invalidenrolinstance');
|
||||
}
|
||||
$instance = $instances[$enrolid];
|
||||
if (!isset($plugins[$instance->enrol])) {
|
||||
throw new enrol_ajax_exception('enrolnotpermitted');
|
||||
}
|
||||
$plugin = $plugins[$instance->enrol];
|
||||
if ($plugin->allow_enrol($instance) && has_capability('enrol/'.$plugin->get_name().':enrol', $context)) {
|
||||
$plugin->enrol_user($instance, $user->id, $roleid, $timestart, $timeend);
|
||||
|
@ -449,7 +449,7 @@ class course_enrolment_table extends html_table implements renderable {
|
||||
|
||||
// Collect the bulk operations for the currently filtered plugin if there is one.
|
||||
$plugin = $manager->get_filtered_enrolment_plugin();
|
||||
if ($plugin) {
|
||||
if ($plugin and enrol_is_enabled($plugin->get_name())) {
|
||||
$this->bulkoperations = $plugin->get_bulk_operations($manager);
|
||||
}
|
||||
}
|
||||
|
@ -54,6 +54,11 @@ if ($course->id == SITEID) {
|
||||
redirect(new moodle_url('/'));
|
||||
}
|
||||
|
||||
// Do not allow any changes if plugin disabled.
|
||||
if (!enrol_is_enabled('self')) {
|
||||
redirect(new moodle_url('/course/view.php', array('id'=>$course->id)));
|
||||
}
|
||||
|
||||
// Obvioulsy
|
||||
require_login($course);
|
||||
// The user must be able to manage self enrolments within the course
|
||||
|
@ -8,6 +8,9 @@ required changes in code:
|
||||
* use role_get_name() or role_fix_names() if you need any role names, using role.name
|
||||
directly from database is not correct any more
|
||||
|
||||
other changes:
|
||||
* course enrolment manager now works with disabled plugins too
|
||||
|
||||
|
||||
=== 2.2 ===
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user