Skip to content

Commit

Permalink
MDL-59369 enrol: Cleanup enrol pages
Browse files Browse the repository at this point in the history
* Cleanup edit enrolment form.
* Improve edit enrol form validation error message.
* Add modal custom data flag to edit enrolment form to hide action
  buttons if loaded via fragment.
* Point return URLs of edit enrolment and user unenrol pages back to
  participants page.
  • Loading branch information
junpataleta committed Jul 26, 2017
1 parent 5719f2c commit ea758b8
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 15 deletions.
2 changes: 1 addition & 1 deletion enrol/editenrolment.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
$course = $DB->get_record('course', array('id'=>$instance->courseid), '*', MUST_EXIST);

// The URL of the enrolled users page for the course.
$usersurl = new moodle_url('/enrol/users.php', array('id' => $course->id));
$usersurl = new moodle_url('/user/index.php', array('id' => $course->id));

// Do not allow any changes if plugin disabled, not available or not suitable.
if (!$plugin = enrol_get_plugin($instance->enrol)) {
Expand Down
17 changes: 7 additions & 10 deletions enrol/editenrolment_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,10 @@

class enrol_user_enrolment_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', '');
$ue = $this->_customdata['ue'];
$modal = !empty($this->_customdata['modal']);

$options = array(ENROL_USER_ACTIVE => get_string('participationactive', 'enrol'),
ENROL_USER_SUSPENDED => get_string('participationsuspended', 'enrol'));
Expand All @@ -56,7 +51,10 @@ function definition() {
$mform->addElement('hidden', 'ifilter');
$mform->setType('ifilter', PARAM_ALPHA);

$this->add_action_buttons();
// Show action buttons if this is not being rendered as a fragment.
if (!$modal) {
$this->add_action_buttons();
}

$this->set_data(array(
'ue' => $ue->id,
Expand All @@ -71,8 +69,7 @@ function 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');
$errors['timeend'] = get_string('enroltimeendinvalid', 'enrol');
}
}

Expand Down
7 changes: 3 additions & 4 deletions enrol/unenroluser.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,15 @@
$manager = new course_enrolment_manager($PAGE, $course, $filter);
$table = new course_enrolment_users_table($manager, $PAGE);

$returnurl = new moodle_url('/enrol/users.php', array('id' => $course->id)+$manager->get_url_params()+$table->get_url_params());
$usersurl = new moodle_url('/enrol/users.php', array('id' => $course->id));
$usersurl = new moodle_url('/user/index.php', array('id' => $course->id));

$PAGE->set_pagelayout('admin');
navigation_node::override_active_url($usersurl);

// If the unenrolment has been confirmed and the sesskey is valid unenrol the user.
if ($confirm && confirm_sesskey()) {
$plugin->unenrol_user($instance, $ue->userid);
redirect($returnurl);
redirect($usersurl);
}

$yesurl = new moodle_url($PAGE->url, array('confirm'=>1, 'sesskey'=>sesskey()));
Expand All @@ -82,5 +81,5 @@

echo $OUTPUT->header();
echo $OUTPUT->heading($fullname);
echo $OUTPUT->confirm($message, $yesurl, $returnurl);
echo $OUTPUT->confirm($message, $yesurl, $usersurl);
echo $OUTPUT->footer();
2 changes: 2 additions & 0 deletions lang/en/enrol.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
$string['disableinstanceconfirmself'] = 'Are you really sure you want to disable instance "{$a->name}" that gives you access to this course? It is possible that you will not be able to access this course if you continue.';
$string['durationdays'] = '{$a} days';
$string['editenrolment'] = 'Edit enrolment';
$string['edituserenrolment'] = 'Edit {$a}\'s enrolment';
$string['enrol'] = 'Enrol';
$string['enrolcandidates'] = 'Not enrolled users';
$string['enrolcandidatesmatching'] = 'Matching not enrolled users';
Expand All @@ -67,6 +68,7 @@
$string['enrolxusers'] = 'Enrol {$a} users';
$string['enroltimecreated'] = 'Enrolment created';
$string['enroltimeend'] = 'Enrolment ends';
$string['enroltimeendinvalid'] = 'Enrolment end date must be after the enrolment start date';
$string['enroltimestart'] = 'Enrolment starts';
$string['errajaxfailedenrol'] = 'Failed to enrol user';
$string['errajaxsearch'] = 'Error when searching users';
Expand Down

0 comments on commit ea758b8

Please sign in to comment.