MDL-26770 enrol - Added support for bulk operations by enrol plugins

This commit is contained in:
Sam Hemelryk
2011-04-21 10:13:13 +08:00
parent 884faffda3
commit 75ee207b81
13 changed files with 743 additions and 5 deletions
+94
View File
@@ -0,0 +1,94 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Bulk user enrolment processing.
*
* @package core
* @subpackage enrol
* @copyright 2011 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require('../config.php');
require_once("$CFG->dirroot/enrol/locallib.php");
require_once("$CFG->dirroot/enrol/users_forms.php");
require_once("$CFG->dirroot/enrol/renderer.php");
require_once("$CFG->dirroot/group/lib.php");
$id = required_param('id', PARAM_INT); // course id
$bulkuserop = required_param('bulkuserop', PARAM_ALPHANUMEXT);
$userids = required_param('bulkuser', PARAM_INT);
$action = optional_param('action', '', PARAM_ACTION);
$filter = optional_param('ifilter', 0, PARAM_INT);
$course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST);
$context = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST);
if ($course->id == SITEID) {
redirect(new moodle_url('/'));
}
require_login($course);
require_capability('moodle/course:enrolreview', $context);
$PAGE->set_pagelayout('admin');
$manager = new course_enrolment_manager($PAGE, $course, $filter);
$table = new course_enrolment_users_table($manager, $PAGE);
$returnurl = new moodle_url('/enrol/users.php', $table->get_combined_url_params());
$actionurl = new moodle_url('/enrol/bulkchange.php', $table->get_combined_url_params()+array('bulkuserop' => $bulkuserop));
$PAGE->set_url($actionurl);
navigation_node::override_active_url(new moodle_url('/enrol/users.php', array('id' => $id)));
$ops = $table->get_bulk_user_enrolment_operations();
if (!array_key_exists($bulkuserop, $ops)) {
throw new moodle_exception('invalidbulkenrolop');
}
$operation = $ops[$bulkuserop];
// Prepare the properties of the form
$users = $manager->get_users_enrolments($userids);
// Get the form for the bulk operation
$mform = $operation->get_form($actionurl, array('users' => $users));
// If the mform is false then attempt an immediate process. This may be an immediate action that
// doesn't require user input OR confirmation.... who know what but maybe one day
if ($mform === false) {
if ($operation->process($manager, $users, new stdClass)) {
redirect($returnurl);
} else {
print_error('errorwithbulkoperation', 'enrol');
}
}
// Check if the bulk operation has been cancelled
if ($mform->is_cancelled()) {
redirect($returnurl);
}
if ($mform->is_submitted() && $mform->is_validated() && confirm_sesskey()) {
if ($operation->process($manager, $users, $mform->get_data())) {
redirect($returnurl);
}
}
$pagetitle = get_string('bulkuseroperation', 'enrol');
$PAGE->set_title($pagetitle);
$PAGE->set_heading($pagetitle);
echo $OUTPUT->header();
echo $OUTPUT->heading($operation->get_title());
$mform->display();
echo $OUTPUT->footer();
+118
View File
@@ -0,0 +1,118 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This file contains form for bulk changing user enrolments.
*
* @package core
* @subpackage enrol
* @copyright 2011 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
require_once("$CFG->libdir/formslib.php");
/**
* A base class that can be used to easily construct a form for use with bulk operations
*
* @copyright 2011 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
abstract class enrol_bulk_enrolment_change_form extends moodleform {
/**
* Defines the standard structure of the form
*/
protected function definition() {
$form = $this->_form;
$users = $this->_customdata['users'];
$statusoptions = $this->get_status_options();
$form->addElement('html', $this->get_users_table($users, $statusoptions));
$form->addElement('select', 'status', get_string('alterstatus', 'enrol_manual'), $statusoptions, array('optional' => true));
$form->addElement('date_selector', 'timestart', get_string('altertimestart', 'enrol_manual'), array('optional' => true));
$form->addElement('date_selector', 'timeend', get_string('altertimeend', 'enrol_manual'), array('optional' => true));
$this->add_action_buttons();
}
/**
* Returns an array of status options
* @return array
*/
protected function get_status_options() {
return array(-1 => get_string('nochange', 'enrol'),
ENROL_USER_ACTIVE => get_string('participationactive', 'enrol'),
ENROL_USER_SUSPENDED => get_string('participationsuspended', 'enrol'));
}
/**
* Generates an HTML table to display the users being affected by the bulk change.
*
* @param array $users
* @param array $statusoptions
* @return string
*/
protected function get_users_table(array $users, array $statusoptions) {
$table = new html_table();
$table->head = array(
get_string('name'),
get_string('participationstatus', 'enrol'),
get_string('enroltimestart', 'enrol'),
get_string('enroltimeend', 'enrol'),
);
$table->data = array();
foreach ($users as $user) {
foreach ($user->enrolments as $enrolment) {
$input = html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'bulkuser[]', 'value' => $user->id));
$table->data[] = array(
fullname($user).$input,
$statusoptions[$enrolment->status],
(!empty($enrolment->timestart))?userdate($enrolment->timestart):'',
(!empty($enrolment->timeend))?userdate($enrolment->timeend):'',
);
}
}
return html_writer::table($table);
}
}
/**
* A convenience class to allow the quick generation of a confirmation form for a bulk operation.
* @copyright 2011 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
abstract class enrol_bulk_enrolment_confirm_form extends enrol_bulk_enrolment_change_form {
/**
* Defines the standard structure of the form
*/
protected function definition() {
$form = $this->_form;
$users = $this->_customdata['users'];
$title = $this->_customdata['title'];
$message = $this->_customdata['message'];
$button = $this->_customdata['button'];
$form->addElement('html', $this->get_users_table($users, $this->get_status_options()));
$form->addElement('header', 'ebecf_header', $title);
$form->addElement('html', html_writer::tag('p', $message));
$this->add_action_buttons(true, $button);
}
}
+140
View File
@@ -25,6 +25,8 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* This class provides a targeted tied together means of interfacing the enrolment
* tasks together with a course.
@@ -913,6 +915,76 @@ class course_enrolment_manager {
}
return false;
}
/**
* Returns the enrolment plugin that the course manager was being filtered to.
*
* If no filter was being applied then this function returns false.
*
* @return enrol_plugin
*/
public function get_filtered_enrolment_plugin() {
$instances = $this->get_enrolment_instances();
$plugins = $this->get_enrolment_plugins();
if (empty($this->instancefilter) || !array_key_exists($this->instancefilter, $instances)) {
return false;
}
$instance = $instances[$this->instancefilter];
return $plugins[$instance->enrol];
}
/**
* Returns and array of users + enrolment details.
*
* Given an array of user id's this function returns and array of user enrolments for those users
* as well as enough user information to display the users name and picture for each enrolment.
*
* @global moodle_database $DB
* @param array $userids
* @return array
*/
public function get_users_enrolments(array $userids) {
global $DB;
$instances = $this->get_enrolment_instances();
$plugins = $this->get_enrolment_plugins();
if (!empty($this->instancefilter)) {
$instancesql = ' = :instanceid';
$instanceparams = array('instanceid' => $this->instancefilter);
} else {
list($instancesql, $instanceparams) = $DB->get_in_or_equal(array_keys($instances), SQL_PARAMS_NAMED, 'instanceid0000');
}
$userfields = user_picture::fields('u');
list($idsql, $idparams) = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED, 'userid0000');
$sql = "SELECT ue.id AS ueid, ue.status, ue.enrolid, ue.userid, ue.timestart, ue.timeend, ue.modifierid, ue.timecreated, ue.timemodified, $userfields
FROM {user_enrolments} ue
LEFT JOIN {user} u ON u.id = ue.userid
WHERE ue.enrolid $instancesql AND
u.id $idsql
ORDER BY u.firstname ASC, u.lastname ASC";
$rs = $DB->get_recordset_sql($sql, $idparams + $instanceparams);
$users = array();
foreach ($rs as $ue) {
$user = user_picture::unalias($ue);
$ue->id = $ue->ueid;
unset($ue->ueid);
if (!array_key_exists($user->id, $users)) {
$user->enrolments = array();
$users[$user->id] = $user;
}
$ue->enrolmentinstance = $instances[$ue->enrolid];
$ue->enrolmentplugin = $plugins[$ue->enrolmentinstance->enrol];
$users[$user->id]->enrolments[$ue->id] = $ue;
}
$rs->close();
return $users;
}
}
/**
@@ -1123,4 +1195,72 @@ class enrol_ajax_exception extends moodle_exception {
public function __construct($errorcode, $link = '', $a = NULL, $debuginfo = null) {
parent::__construct($errorcode, 'enrol', $link, $a, $debuginfo);
}
}
/**
* This class is used to manage a bulk operations for enrolment plugins.
*
* @copyright 2011 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
abstract class enrol_bulk_enrolment_operation {
/**
* The course enrolment manager
* @var course_enrolment_manager
*/
protected $manager;
/**
* The enrolment plugin to which this operation belongs
* @var enrol_plugin
*/
protected $plugin;
/**
* Contructor
* @param course_enrolment_manager $manager
* @param stdClass $plugin
*/
public function __construct(course_enrolment_manager $manager, enrol_plugin $plugin = null) {
$this->manager = $manager;
$this->plugin = $plugin;
}
/**
* Returns a moodleform used for this operation, or false if no form is required and the action
* should be immediatly processed.
*
* @param moodle_url|string $defaultaction
* @param mixed $defaultcustomdata
* @return enrol_bulk_enrolment_change_form|moodleform|false
*/
public function get_form($defaultaction = null, $defaultcustomdata = null) {
return false;
}
/**
* Returns the title to use for this bulk operation
*
* @return string
*/
abstract public function get_title();
/**
* Returns the identifier for this bulk operation.
* This should be the same identifier used by the plugins function when returning
* all of its bulk operations.
*
* @return string
*/
abstract public function get_identifier();
/**
* Processes the bulk operation on the given users
*
* @param course_enrolment_manager $manager
* @param array $users
* @param stdClass $properties
*/
abstract public function process(course_enrolment_manager $manager, array $users, stdClass $properties);
}
+1 -2
View File
@@ -128,5 +128,4 @@ switch ($action) {
throw new enrol_ajax_exception('unknowajaxaction');
}
echo json_encode($outcome);
die();
echo json_encode($outcome);
+45
View File
@@ -0,0 +1,45 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This file contains form for bulk changing user enrolments.
*
* @package core
* @subpackage enrol
* @copyright 2011 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
require_once("$CFG->dirroot/enrol/bulkchange_forms.php");
/**
* The form to collect required information when bulk editing users enrolments
*
* @copyright 2011 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class enrol_manual_editselectedusers_form extends enrol_bulk_enrolment_change_form {}
/**
* The form to confirm the intention to bulk delete users enrolments.
*
* @copyright 2011 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class enrol_manual_deleteselectedusers_form extends enrol_bulk_enrolment_confirm_form {}
+8
View File
@@ -24,10 +24,16 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['alterstatus'] = 'Alter status';
$string['altertimeend'] = 'Alter end time';
$string['altertimestart'] = 'Alter start time';
$string['assignrole'] = 'Assignrole';
$string['confirmbulkdeleteenrolment'] = 'Are you sure you want to delete these users enrolments?';
$string['defaultperiod'] = 'Default enrolment period';
$string['defaultperiod_desc'] = 'Default length of the default enrolment period setting (in seconds).'; //TODO: fixme
$string['deleteselectedusers'] = 'Delete selected user enrolments';
$string['editenrolment'] = 'Edit enrolment';
$string['editselectedusers'] = 'Edit selected user enrolments';
$string['enrolledincourserole'] = 'Enrolled in "{$a->course}" as "{$a->role}"';
$string['enrolusers'] = 'Enrol users';
$string['manual:config'] = 'Configure manual enrol instances';
@@ -43,5 +49,7 @@ $string['status_help'] = 'This setting determines whether users can be enrolled
$string['statusenabled'] = 'Enabled';
$string['statusdisabled'] = 'Disabled';
$string['unenrol'] = 'Unenrol user';
$string['unenrolselectedusers'] = 'Unenrol selected users';
$string['unenrolselfconfirm'] = 'Do you really want to unenrol yourself from course "{$a}"?';
$string['unenroluser'] = 'Do you really want to unenrol "{$a->user}" from course "{$a->course}"?';
$string['unenrolusers'] = 'Unenrol users';
+14
View File
@@ -269,6 +269,20 @@ class enrol_manual_plugin extends enrol_plugin {
}
return $actions;
}
/**
* The manual plugin has several bulk operations that can be performed
* @return array
*/
public function get_bulk_operations(course_enrolment_manager $manager) {
global $CFG;
require_once($CFG->dirroot.'/enrol/manual/locallib.php');
$bulkoperations = array(
'editselectedusers' => new enrol_manual_editselectedusers_operation($manager, $this),
'deleteselectedusers' => new enrol_manual_deleteselectedusers_operation($manager, $this)
);
return $bulkoperations;
}
}
/**
+201
View File
@@ -153,3 +153,204 @@ class enrol_manual_current_participant extends user_selector_base {
return $options;
}
}
/**
* A bulk operation for the manual enrolment plugin to edit selected users.
*
* @copyright 2011 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class enrol_manual_editselectedusers_operation extends enrol_bulk_enrolment_operation {
/**
* Returns the title to display for this bulk operation.
*
* @return string
*/
public function get_title() {
return get_string('editselectedusers', 'enrol_manual');
}
/**
* Returns the identifier for this bulk operation. This is the key used when the plugin
* returns an array containing all of the bulk operations it supports.
*/
public function get_identifier() {
return 'editselectedusers';
}
/**
* Processes the bulk operation request for the given userids with the provided properties.
*
* @global moodle_database $DB
* @param course_enrolment_manager $manager
* @param array $userids
* @param stdClass $properties The data returned by the form.
*/
public function process(course_enrolment_manager $manager, array $users, stdClass $properties) {
global $DB, $USER;
if (!has_capability("enrol/manual:manage", $manager->get_context())) {
return false;
}
// Get all of the user enrolment id's
$ueids = array();
$instances = array();
foreach ($users as $user) {
foreach ($user->enrolments as $enrolment) {
$ueids[] = $enrolment->id;
if (!array_key_exists($enrolment->id, $instances)) {
$instances[$enrolment->id] = $enrolment;
}
}
}
// Check that each instance is manageable by the current user.
foreach ($instances as $instance) {
if (!$this->plugin->allow_manage($instance)) {
return false;
}
}
// Collect the known properties.
$status = $properties->status;
$timestart = $properties->timestart;
$timeend = $properties->timeend;
list($ueidsql, $params) = $DB->get_in_or_equal($ueids, SQL_PARAMS_NAMED);
$updatesql = array();
if ($status == ENROL_USER_ACTIVE || $status == ENROL_USER_SUSPENDED) {
$updatesql[] = 'status = :status';
$params['status'] = (int)$status;
}
if (!empty($timestart)) {
$updatesql[] = 'timestart = :timestart';
$params['timestart'] = (int)$timestart;
}
if (!empty($timeend)) {
$updatesql[] = 'timeend = :timeend';
$params['timeend'] = (int)$timeend;
}
if (empty($updatesql)) {
return true;
}
// Update the modifierid
$updatesql[] = 'modifierid = :modifierid';
$params['modifierid'] = (int)$USER->id;
// Update the time modified
$updatesql[] = 'timemodified = :timemodified';
$params['timemodified'] = time();
// Build the SQL statement
$updatesql = join(', ', $updatesql);
$sql = "UPDATE {user_enrolments}
SET $updatesql
WHERE id $ueidsql";
if ($DB->execute($sql, $params)) {
foreach ($users as $user) {
foreach ($user->enrolments as $enrolment) {
$enrolment->courseid = $enrolment->enrolmentinstance->courseid;
$enrolment->enrol = 'manual';
events_trigger('user_unenrol_modified', $enrolment);
}
}
return true;
}
return false;
}
/**
* Returns a enrol_bulk_enrolment_operation extension form to be used
* in collecting required information for this operation to be processed.
*
* @param string|moodle_url|null $defaultaction
* @param mixed $defaultcustomdata
* @return enrol_manual_editselectedusers_form
*/
public function get_form($defaultaction = null, $defaultcustomdata = null) {
global $CFG;
require_once($CFG->dirroot.'/enrol/manual/bulkchangeforms.php');
return new enrol_manual_editselectedusers_form($defaultaction, $defaultcustomdata);
}
}
/**
* A bulk operation for the manual enrolment plugin to delete selected users enrolments.
*
* @copyright 2011 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class enrol_manual_deleteselectedusers_operation extends enrol_bulk_enrolment_operation {
/**
* Returns the title to display for this bulk operation.
*
* @return string
*/
public function get_identifier() {
return 'deleteselectedusers';
}
/**
* Returns the identifier for this bulk operation. This is the key used when the plugin
* returns an array containing all of the bulk operations it supports.
*
* @return string
*/
public function get_title() {
return get_string('deleteselectedusers', 'enrol_manual');
}
/**
* Returns a enrol_bulk_enrolment_operation extension form to be used
* in collecting required information for this operation to be processed.
*
* @param string|moodle_url|null $defaultaction
* @param mixed $defaultcustomdata
* @return enrol_manual_editselectedusers_form
*/
public function get_form($defaultaction = null, array $defaultcustomdata = null) {
global $CFG;
require_once($CFG->dirroot.'/enrol/manual/bulkchangeforms.php');
if (!array($defaultcustomdata)) {
$defaultcustomdata = array();
}
$defaultcustomdata['title'] = $this->get_title();
$defaultcustomdata['message'] = get_string('confirmbulkdeleteenrolment', 'enrol_manual');
$defaultcustomdata['button'] = get_string('unenrolusers', 'enrol_manual');
return new enrol_manual_deleteselectedusers_form($defaultaction, $defaultcustomdata);
}
/**
* Processes the bulk operation request for the given userids with the provided properties.
*
* @global moodle_database $DB
* @param course_enrolment_manager $manager
* @param array $userids
* @param stdClass $properties The data returned by the form.
*/
public function process(course_enrolment_manager $manager, array $users, stdClass $properties) {
global $DB;
if (!has_capability("enrol/manual:unenrol", $manager->get_context())) {
return false;
}
foreach ($users as $user) {
foreach ($user->enrolments as $enrolment) {
$plugin = $enrolment->enrolmentplugin;
$instance = $enrolment->enrolmentinstance;
if ($plugin->allow_unenrol($instance)) {
$plugin->unenrol_user($instance, $user->id);
}
}
}
return true;
}
}
+90 -1
View File
@@ -58,7 +58,34 @@ class core_enrol_renderer extends plugin_renderer_base {
}
$content .= $this->output->render($table->get_enrolment_type_filter());
$content .= $this->output->render($table->get_paging_bar());
$content .= html_writer::table($table);
// Check if the table has any bulk operations. If it does we want to wrap the table in a
// form so that we can capture and perform any required bulk operations.
if ($table->has_bulk_user_enrolment_operations()) {
$content .= html_writer::start_tag('form', array('action' => new moodle_url('/enrol/bulkchange.php'), 'method' => 'post'));
foreach ($table->get_combined_url_params() as $key => $value) {
if ($key == 'action') {
continue;
}
$content .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => $key, 'value' => $value));
}
$content .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'action', 'value' => 'bulkchange'));
$content .= html_writer::table($table);
$content .= html_writer::start_tag('div', array('class' => 'singleselect bulkuserop'));
$content .= html_writer::start_tag('select', array('name' => 'bulkuserop'));
$content .= html_writer::tag('option', get_string('withselectedusers', 'enrol'), array('value' => ''));
$options = array('' => get_string('withselectedusers', 'enrol'));
foreach ($table->get_bulk_user_enrolment_operations() as $operation) {
$content .= html_writer::tag('option', $operation->get_title(), array('value' => $operation->get_identifier()));
}
$content .= html_writer::end_tag('select');
$content .= html_writer::empty_tag('input', array('type' => 'submit', 'value' => get_string('go')));
$content .= html_writer::end_tag('div');
$content .= html_writer::end_tag('form');
} else {
$content .= html_writer::table($table);
}
$content .= $this->output->render($table->get_paging_bar());
if (!empty($buttonhtml)) {
$content .= $buttonhtml;
@@ -379,6 +406,12 @@ class course_enrolment_table extends html_table implements renderable {
*/
protected $fields = array();
/**
* An array of bulk user enrolment operations
* @var array
*/
protected $bulkoperations = array();
/**
* An array of sortable fields
* @static
@@ -412,6 +445,12 @@ class course_enrolment_table extends html_table implements renderable {
}
$this->id = html_writer::random_id();
// Collect the bulk operations for the currently filtered plugin if there is one.
$plugin = $manager->get_filtered_enrolment_plugin();
if ($plugin) {
$this->bulkoperations = $plugin->get_bulk_operations($manager);
}
}
/**
@@ -452,6 +491,13 @@ class course_enrolment_table extends html_table implements renderable {
$this->colclasses = array();
$this->align = array();
$url = $this->manager->get_moodlepage()->url;
if (!empty($this->bulkoperations)) {
// If there are bulk operations add a column for checkboxes.
$this->head[] = '';
$this->colclasses[] = 'field col_bulkops';
}
foreach ($fields as $name => $label) {
$newlabel = '';
if (is_array($label)) {
@@ -506,12 +552,18 @@ class course_enrolment_table extends html_table implements renderable {
*/
public function set_users(array $users) {
$this->users = $users;
$hasbulkops = !empty($this->bulkoperations);
foreach ($users as $userid=>$user) {
$user = (array)$user;
$row = new html_table_row();
$row->attributes = array('class' => 'userinforow');
$row->id = 'user_'.$userid;
$row->cells = array();
if ($hasbulkops) {
// Add a checkbox into the first column.
$input = html_writer::empty_tag('input', array('type' => 'checkbox', 'name' => 'bulkuser[]', 'value' => $userid));
$row->cells[] = new html_table_cell($input);
}
foreach ($this->fields as $field => $label) {
if (is_array($label)) {
$bits = array();
@@ -599,6 +651,43 @@ class course_enrolment_table extends html_table implements renderable {
self::SORTDIRECTIONVAR => $this->sortdirection
);
}
/**
* Returns an array of URL params for both the table and the manager.
*
* @return array
*/
public function get_combined_url_params() {
return $this->get_url_params() + $this->manager->get_url_params();
}
/**
* Sets the bulk operations for this table.
*
* @param array $bulkoperations
*/
public function set_bulk_user_enrolment_operations(array $bulkoperations) {
$this->bulkoperations = $bulkoperations;
}
/**
* Returns an array of bulk operations.
*
* @return array
*/
public function get_bulk_user_enrolment_operations() {
return $this->bulkoperations;
}
/**
* Returns true fi the table is aware of any bulk operations that can be performed on users
* selected from the currently filtered enrolment plugins.
*
* @return bool
*/
public function has_bulk_user_enrolment_operations() {
return !empty($this->bulkoperations);
}
}
/**
+4
View File
@@ -30,6 +30,7 @@ $string['ajaxoneuserfound'] = '1 user found';
$string['ajaxxusersfound'] = '{$a} users found';
$string['ajaxnext25'] = 'Next 25...';
$string['assignnotpermitted'] = 'You do not have permission or can not assign roles in this course.';
$string['bulkuseroperation'] = 'Bulk user operation';
$string['configenrolplugins'] = 'Please select all required plugins and arrange then in appropriate order.';
$string['custominstancename'] = 'Custom instance name';
$string['defaultenrol'] = 'Add instance to new courses';
@@ -61,11 +62,13 @@ $string['errajaxsearch'] = 'Error when searching users';
$string['erroreditenrolment'] = 'An error occurred while trying to edit a users enrolment';
$string['errorenrolcohort'] = 'Error creating cohort sync enrolment instance in this course.';
$string['errorenrolcohortusers'] = 'Error enrolling cohort members in this course.';
$string['errorwithbulkoperation'] = 'There was an error while processing your bulk enrolment change.';
$string['finishenrollingusers'] = 'Finish enrolling users';
$string['invalidenrolinstance'] = 'Invalid enrolment instance';
$string['invalidrole'] = 'Invalid role';
$string['manageenrols'] = 'Manage enrol plugins';
$string['manageinstance'] = 'Manage';
$string['nochange'] = 'No change';
$string['noexistingparticipants'] = 'No existing participants';
$string['noguestaccess'] = 'Guests can not access this course, please try to log in.';
$string['none'] = 'None';
@@ -98,6 +101,7 @@ $string['uninstalldeletefiles'] = 'All data associated with the enrol plugin \'{
$string['unknowajaxaction'] = 'Unknown action requested';
$string['unlimitedduration'] = 'Unlimited';
$string['usersearch'] = 'Search ';
$string['withselectedusers'] = 'With selected users';
$string['extremovedaction'] = 'External unenrol action';
$string['extremovedaction_help'] = 'Select action to carry out when user enrolment disappears from external enrolment source. Please note that some user data and settings are purged from course during course unenrolment.';
$string['extremovedsuspend'] = 'Disable course enrolment';
+1
View File
@@ -258,6 +258,7 @@ $string['invalidadminsettingname'] = 'Invalid admin setting ({$a})';
$string['invalidargorconf'] = 'No valid arguments supplied or incorrect server configuration';
$string['invalidarguments'] = 'No valid arguments supplied';
$string['invalidblockinstance'] = 'Invalid block instance for: {$a}';
$string['invalidbulkenrolop'] = 'Invalid bulk enrolment operation requested.';
$string['invalidcategory'] = 'Incorrect category!';
$string['invalidcategoryid'] = 'Incorrect category id!';
$string['invalidcomment'] = 'Comment is incorrect';
+20
View File
@@ -1542,4 +1542,24 @@ abstract class enrol_plugin {
public function get_user_enrolment_actions(course_enrolment_manager $manager, $ue) {
return array();
}
/**
* Returns true if the plugin has one or more bulk operations that can be performed on
* user enrolments.
*
* @return bool
*/
public function has_bulk_operations() {
return false;
}
/**
* Return an array of enrol_bulk_enrolment_operation objects that define
* the bulk actions that can be performed on user enrolments by the plugin.
*
* @return array
*/
public function get_bulk_operations() {
return array();
}
}
+7 -2
View File
@@ -413,8 +413,12 @@ table#tag-management-list {margin: 10px auto;width: 80%;}
.userenrolment tr.r0 {background-color:#F9F9F9;}
.userenrolment tr.r1 {background-color:#F3F3F3;}
.userenrolment td {border:1px solid #E9E9E9;border-top-color:#F6F6F6;border-right-color:#EEE;border-left-color:#F3F3F3;}
.userenrolment td.c0 {border-left-color:#999;}
.userenrolment td.c4 {border-right-color:#999;}
.userenrolment td.c0 {border-left-width:0;}
.userenrolment td.lastcol {border-right-color:#999;}
.userenrolment .col_bulkops {vertical-align:middle;text-align:center;}
.userenrolment .r0 .col_bulkops {background-color:#FFFFFF;}
.userenrolment .r1 .col_bulkops {background-color:#F9F9F9;}
.userenrolment tr.lastrow td {border-bottom-width:0;}
.userenrolment .col_userdetails {padding:3px;min-width:35%;}
.userenrolment .col_role .roles {position:relative;}
.userenrolment .col_role .role {line-height:10px;font-size:10px;}
@@ -432,6 +436,7 @@ table#tag-management-list {margin: 10px auto;width: 80%;}
.path-enrol .enrolusersbutton.instance1,
.path-enrol .enrolcohortbutton.instance1,
.path-enrol .assignuserrole.instance1 {float:right;}
.path-enrol .singleselect.bulkuserop {float:left;}
/* Registration */
#page-admin-registration-hubselector .registration_textfield {width: 400px;}