mirror of
https://github.com/moodle/moodle.git
synced 2025-04-22 08:55:15 +02:00
MDL-23532 enrol - removed general handling of user enrolment editing/unenrolment plugins are now responsible for this
This commit is contained in:
parent
8c6e0ebebb
commit
12a52d7c6e
@ -47,6 +47,7 @@ $PAGE->set_pagelayout('admin');
|
||||
$manager = new course_enrolment_manager($PAGE, $course, $filter);
|
||||
$table = new course_enrolment_users_table($manager, $PAGE);
|
||||
$PAGE->set_url('/enrol/users.php', $manager->get_url_params()+$table->get_url_params());
|
||||
navigation_node::override_active_url(new moodle_url('/enrol/users.php', array('id' => $id)));
|
||||
|
||||
// Check if there is an action to take
|
||||
if ($action) {
|
||||
@ -61,26 +62,6 @@ if ($action) {
|
||||
$pagecontent = null;
|
||||
|
||||
switch ($action) {
|
||||
/**
|
||||
* Unenrols a user from this course (includes removing all of their grades)
|
||||
*/
|
||||
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($instance) && has_capability("enrol/$instance->enrol:unenrol", $manager->get_context())) {
|
||||
if ($confirm && $manager->unenrol_user($ue)) {
|
||||
redirect($PAGE->url);
|
||||
} else {
|
||||
$user = $DB->get_record('user', array('id'=>$ue->userid), '*', MUST_EXIST);
|
||||
$yesurl = new moodle_url($PAGE->url, array('action'=>'unenrol', 'ue'=>$ue->id, 'confirm'=>1, 'sesskey'=>sesskey()));
|
||||
|
||||
$message = get_string('unenrolconfirm', 'enrol', array('user'=>fullname($user, true), 'course'=>format_string($course->fullname)));
|
||||
$pagetitle = get_string('unenrol', 'enrol');
|
||||
$pagecontent = $OUTPUT->confirm($message, $yesurl, $PAGE->url);
|
||||
}
|
||||
$actiontaken = true;
|
||||
}
|
||||
break;
|
||||
/**
|
||||
* Removes a role from the user with this course
|
||||
*/
|
||||
@ -162,27 +143,6 @@ if ($action) {
|
||||
$actiontaken = true;
|
||||
}
|
||||
break;
|
||||
/**
|
||||
* Edits the details of a users enrolment in the course
|
||||
*/
|
||||
case 'edit':
|
||||
$ue = $DB->get_record('user_enrolments', array('id'=>required_param('ue', PARAM_INT)), '*', MUST_EXIST);
|
||||
|
||||
//Only show the edit form if the user has the appropriate capability
|
||||
list($instance, $plugin) = $manager->get_user_enrolment_components($ue);
|
||||
if ($instance && $plugin && $plugin->allow_manage($instance) && has_capability("enrol/$instance->enrol:manage", $manager->get_context())) {
|
||||
$user = $DB->get_record('user', array('id'=>$ue->userid), '*', MUST_EXIST);
|
||||
$mform = new enrol_users_edit_form(NULL, array('user'=>$user, 'course'=>$course, 'ue'=>$ue));
|
||||
$mform->set_data($PAGE->url->params());
|
||||
$data = $mform->get_data();
|
||||
if ($mform->is_cancelled() || ($data && $manager->edit_enrolment($ue, $data))) {
|
||||
redirect($PAGE->url);
|
||||
} else {
|
||||
$pagetitle = fullname($user);
|
||||
}
|
||||
$actiontaken = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// If we took an action display we need to display something special.
|
||||
|
@ -131,70 +131,4 @@ class enrol_users_addmember_form extends moodleform {
|
||||
|
||||
$this->set_data(array('action'=>'addmember', 'user'=>$user->id));
|
||||
}
|
||||
}
|
||||
|
||||
class enrol_users_edit_form extends moodleform {
|
||||
function definition() {
|
||||
global $CFG, $DB;
|
||||
|
||||
$mform = $this->_form;
|
||||
|
||||
$user = $this->_customdata['user'];
|
||||
$course = $this->_customdata['course'];
|
||||
$ue = $this->_customdata['ue'];
|
||||
|
||||
|
||||
$mform->addElement('header','general', '');
|
||||
|
||||
$options = array(ENROL_USER_ACTIVE => get_string('participationactive', 'enrol'),
|
||||
ENROL_USER_SUSPENDED => get_string('participationsuspended', 'enrol'));
|
||||
if (isset($options[$ue->status])) {
|
||||
$mform->addElement('select', 'status', get_string('participationstatus', 'enrol'), $options);
|
||||
}
|
||||
|
||||
$mform->addElement('date_selector', 'timestart', get_string('enroltimestart', 'enrol'), array('optional' => true));
|
||||
|
||||
$mform->addElement('date_selector', 'timeend', get_string('enroltimeend', 'enrol'), array('optional' => true));
|
||||
|
||||
$mform->addElement('hidden', 'id');
|
||||
$mform->setType('id', PARAM_INT);
|
||||
|
||||
$mform->addElement('hidden', 'ue');
|
||||
$mform->setType('ue', PARAM_INT);
|
||||
|
||||
$mform->addElement('hidden', 'action');
|
||||
$mform->setType('action', PARAM_ACTION);
|
||||
|
||||
$mform->addElement('hidden', 'ifilter');
|
||||
$mform->setType('ifilter', PARAM_ALPHA);
|
||||
|
||||
$mform->addElement('hidden', 'page');
|
||||
$mform->setType('page', PARAM_INT);
|
||||
|
||||
$mform->addElement('hidden', 'perpage');
|
||||
$mform->setType('perpage', PARAM_INT);
|
||||
|
||||
$mform->addElement('hidden', 'sort');
|
||||
$mform->setType('sort', PARAM_ALPHA);
|
||||
|
||||
$mform->addElement('hidden', 'dir');
|
||||
$mform->setType('dir', PARAM_ALPHA);
|
||||
|
||||
$this->add_action_buttons();
|
||||
|
||||
$this->set_data(array('action'=>'edit', 'ue'=>$ue->id, 'status'=>$ue->status, 'timestart'=>$ue->timestart, 'timeend'=>$ue->timeend));
|
||||
}
|
||||
|
||||
function validation($data, $files) {
|
||||
$errors = parent::validation($data, $files);
|
||||
|
||||
if (!empty($data['timestart']) and !empty($data['timeend'])) {
|
||||
if ($data['timestart'] >= $data['timeend']) {
|
||||
$errors['timestart'] = get_string('error');
|
||||
$errors['timeend'] = get_string('error');
|
||||
}
|
||||
}
|
||||
|
||||
return $errors;
|
||||
}
|
||||
}
|
||||
}
|
@ -58,6 +58,7 @@ $string['enroltimeend'] = 'Enrolment ends';
|
||||
$string['enroltimestart'] = 'Enrolment starts';
|
||||
$string['errajaxfailedenrol'] = 'Failed to enrol user';
|
||||
$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['finishenrollingusers'] = 'Finish enrolling users';
|
||||
|
@ -1540,17 +1540,6 @@ abstract class enrol_plugin {
|
||||
* @return array An array of user_enrolment_actions
|
||||
*/
|
||||
public function get_user_enrolment_actions(course_enrolment_manager $manager, $ue) {
|
||||
$actions = array();
|
||||
$context = $manager->get_context();
|
||||
$instance = $ue->enrolmentinstance;
|
||||
if ($this->allow_unenrol($instance) && has_capability("enrol/".$instance->enrol.":unenrol", $context)) {
|
||||
$url = new moodle_url($manager->get_moodlepage()->url, array('action' => 'unenrol', 'ue' => $ue->id));
|
||||
$actions[] = new user_enrolment_action(new pix_icon('t/delete', ''), get_string('unenrol', 'enrol'), $url, array('class'=>'unenrollink', 'rel'=>$ue->id));
|
||||
}
|
||||
if ($this->allow_manage($instance) && has_capability("enrol/".$instance->enrol.":manage", $context)) {
|
||||
$url = new moodle_url($manager->get_moodlepage()->url, array('action' => 'edit', 'ue' => $ue->id));
|
||||
$actions[] = new user_enrolment_action(new pix_icon('t/edit', ''), get_string('edit'), $url, array('class'=>'editenrollink', 'rel'=>$ue->id));
|
||||
}
|
||||
return $actions;
|
||||
return array();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user