Skip to content

Commit

Permalink
MDL-60179 core: make it clear what enrolment instance is being edited
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjnelson committed Oct 19, 2017
1 parent 9a316f3 commit af835c2
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 10 deletions.
9 changes: 8 additions & 1 deletion enrol/editenrolment.php
Expand Up @@ -73,7 +73,14 @@
navigation_node::override_active_url($usersurl);

// Get the enrolment edit form.
$mform = new enrol_user_enrolment_form($url, array('user'=>$user, 'course'=>$course, 'ue'=>$ue));
$mform = new enrol_user_enrolment_form($url,
[
'user' => $user,
'course' => $course,
'ue' => $ue,
'enrolinstancename' => $plugin->get_instance_name($instance)
]
);
$mform->set_data($PAGE->url->params());

if ($mform->is_cancelled()) {
Expand Down
3 changes: 3 additions & 0 deletions enrol/editenrolment_form.php
Expand Up @@ -31,8 +31,11 @@ function definition() {
$mform = $this->_form;

$ue = $this->_customdata['ue'];
$instancename = $this->_customdata['enrolinstancename'];
$modal = !empty($this->_customdata['modal']);

$mform->addElement('static', 'enrolmentmethod', get_string('enrolmentmethod', 'enrol'), $instancename);

$options = array(ENROL_USER_ACTIVE => get_string('participationactive', 'enrol'),
ENROL_USER_SUSPENDED => get_string('participationsuspended', 'enrol'));
if (isset($options[$ue->status])) {
Expand Down
3 changes: 3 additions & 0 deletions enrol/externallib.php
Expand Up @@ -859,10 +859,13 @@ public static function edit_user_enrolment($courseid, $ueid, $status, $timestart
$errors = [];

// Validate data against the edit user enrolment form.
$instance = $DB->get_record('enrol', ['id' => $userenrolment->enrolid], '*', MUST_EXIST);
$plugin = enrol_get_plugin($instance->enrol);
require_once("$CFG->dirroot/enrol/editenrolment_form.php");
$customformdata = [
'ue' => $userenrolment,
'modal' => true,
'enrolinstancename' => $plugin->get_instance_name($instance)
];
$mform = new \enrol_user_enrolment_form(null, $customformdata, 'post', '', null, true, $userenroldata);
$mform->set_data($userenroldata);
Expand Down
8 changes: 7 additions & 1 deletion enrol/unenroluser.php
Expand Up @@ -70,7 +70,13 @@
}

$yesurl = new moodle_url($PAGE->url, array('confirm'=>1, 'sesskey'=>sesskey()));
$message = get_string('unenrolconfirm', 'core_enrol', array('user'=>fullname($user, true), 'course'=>format_string($course->fullname)));
$message = get_string('unenrolconfirm', 'core_enrol',
[
'user' => fullname($user, true),
'course' => format_string($course->fullname),
'enrolinstancename' => $plugin->get_instance_name($instance)
]
);
$fullname = fullname($user);
$title = get_string('unenrol', 'core_enrol');

Expand Down
2 changes: 1 addition & 1 deletion lang/en/enrol.php
Expand Up @@ -132,7 +132,7 @@
$string['totalotherusers'] = '{$a} other users';
$string['unassignnotpermitted'] = 'You do not have permission to unassign roles in this course';
$string['unenrol'] = 'Unenrol';
$string['unenrolconfirm'] = 'Do you really want to unenrol user "{$a->user}" from course "{$a->course}"?';
$string['unenrolconfirm'] = 'Do you really want to unenrol "{$a->user}" (previously enrolled via "{$a->enrolinstancename}") from "{$a->course}"?';
$string['unenrolme'] = 'Unenrol me from {$a}';
$string['unenrolnotpermitted'] = 'You do not have permission or can not unenrol this user from this course.';
$string['unenrolroleusers'] = 'Unenrol users';
Expand Down
3 changes: 3 additions & 0 deletions lib/enrollib.php
Expand Up @@ -1528,9 +1528,12 @@ function enrol_output_fragment_user_enrolment_form($args) {

$ueid = $args->ueid;
$userenrolment = $DB->get_record('user_enrolments', ['id' => $ueid], '*', MUST_EXIST);
$instance = $DB->get_record('enrol', ['id' => $userenrolment->enrolid], '*', MUST_EXIST);
$plugin = enrol_get_plugin($instance->enrol);
$customdata = [
'ue' => $userenrolment,
'modal' => true,
'enrolinstancename' => $plugin->get_instance_name($instance)
];

// Set the data if applicable.
Expand Down
2 changes: 1 addition & 1 deletion user/amd/build/status_field.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion user/amd/src/status_field.js
Expand Up @@ -140,7 +140,8 @@ define(['core/templates',
component: 'enrol',
param: {
user: parentContainer.data('fullname'),
course: parentContainer.data('coursename')
course: parentContainer.data('coursename'),
enrolinstancename: parentContainer.data('enrolinstancename')
}
}
];
Expand Down
2 changes: 1 addition & 1 deletion user/templates/status_field.mustache
Expand Up @@ -61,7 +61,7 @@
data-status="{{status}}" data-timestart="{{timestart}}" data-timeend="{{timeend}}">
<span class="label {{#active}}label-success{{/active}}{{#suspended}}label-warning{{/suspended}}{{#notcurrent}}label-default{{/notcurrent}}">{{status}}</span>
<a data-action="showdetails" href="#" role="button" tabindex="0">{{!
}}{{#pix}}docs, core, {{#str}}enroldetails, enrol{{/str}}{{/pix}}{{!
}}{{#pix}}docs, core, {{enrolinstancename}}{{/pix}}{{!
}}</a>
{{#enrolactions}}
<a href="{{url}}" role="button" {{#attributes}}{{name}}="{{value}}" {{/attributes}}>{{!
Expand Down
8 changes: 4 additions & 4 deletions user/tests/behat/edit_user_enrolment.feature
Expand Up @@ -53,13 +53,13 @@ Feature: Edit user enrolment
Given I log in as "teacher1"
And I am on "Course 1" course homepage
And I navigate to course participants
When I click on "Enrolment details" "icon" in the "student1" "table_row"
When I click on "Manual enrolments" "icon" in the "student1" "table_row"
Then I should see "Enrolment details"
And I should see "Student 1" in the "Full name" "table_row"
And I should see "Active" in the "//td[@class='user-enrol-status']" "xpath_element"
And I should see "Manual enrolments" in the "Enrolment method" "table_row"
And I press "Cancel"
And I click on "Enrolment details" "icon" in the "student2" "table_row"
And I click on "Manual enrolments" "icon" in the "student2" "table_row"
And I should see "Enrolment details"
And I should see "Student 2" in the "Full name" "table_row"
And I should see "Suspended" in the "//td[@class='user-enrol-status']" "xpath_element"
Expand Down Expand Up @@ -90,7 +90,7 @@ Feature: Edit user enrolment
Then I should see "Student 3" in the "participants" "table"
And "Edit enrolment" "icon" should not exist in the "student3" "table_row"
And "Unenrol" "icon" should not exist in the "student3" "table_row"
And I click on "Enrolment details" "icon" in the "student3" "table_row"
And I click on "Course meta link (Course 2)" "icon" in the "student3" "table_row"
And I should see "Enrolment details"
And I should see "Student 3" in the "Full name" "table_row"
And I should see "Active" in the "//td[@class='user-enrol-status']" "xpath_element"
Expand All @@ -102,7 +102,7 @@ Feature: Edit user enrolment
Given I log in as "teacher1"
And I am on "Course 1" course homepage
And I navigate to course participants
When I click on "Enrolment details" "icon" in the "student2" "table_row"
When I click on "Manual enrolments" "icon" in the "student2" "table_row"
And I click on "Edit enrolment" "icon" in the "Enrolment method" "table_row"
And I should see "Edit Student 2's enrolment"
And I set the field "Status" to "Active"
Expand Down

0 comments on commit af835c2

Please sign in to comment.