Skip to content

Commit

Permalink
MDL-23532 enrol - removed general handling of user enrolment editing/…
Browse files Browse the repository at this point in the history
…unenrolment plugins are now responsible for this
  • Loading branch information
Sam Hemelryk committed Apr 21, 2011
1 parent 8c6e0eb commit 12a52d7
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 120 deletions.
42 changes: 1 addition & 41 deletions enrol/users.php
Expand Up @@ -47,6 +47,7 @@
$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) {
Expand All @@ -61,26 +62,6 @@
$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
*/
Expand Down Expand Up @@ -162,27 +143,6 @@
$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.
Expand Down
68 changes: 1 addition & 67 deletions enrol/users_forms.php
Expand Up @@ -131,70 +131,4 @@ function definition() {

$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;
}
}
}
1 change: 1 addition & 0 deletions lang/en/enrol.php
Expand Up @@ -58,6 +58,7 @@
$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';
Expand Down
13 changes: 1 addition & 12 deletions lib/enrollib.php
Expand Up @@ -1540,17 +1540,6 @@ public function get_manual_enrol_button(course_enrolment_manager $manager) {
* @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();
}
}

0 comments on commit 12a52d7

Please sign in to comment.