From af835c24b255f057273c824254de1ee9c210cd9e Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Mon, 16 Oct 2017 17:55:34 +0800 Subject: [PATCH] MDL-60179 core: make it clear what enrolment instance is being edited --- enrol/editenrolment.php | 9 ++++++++- enrol/editenrolment_form.php | 3 +++ enrol/externallib.php | 3 +++ enrol/unenroluser.php | 8 +++++++- lang/en/enrol.php | 2 +- lib/enrollib.php | 3 +++ user/amd/build/status_field.min.js | 2 +- user/amd/src/status_field.js | 3 ++- user/templates/status_field.mustache | 2 +- user/tests/behat/edit_user_enrolment.feature | 8 ++++---- 10 files changed, 33 insertions(+), 10 deletions(-) diff --git a/enrol/editenrolment.php b/enrol/editenrolment.php index 54f18efc46e..f9f4cf4e973 100644 --- a/enrol/editenrolment.php +++ b/enrol/editenrolment.php @@ -73,7 +73,14 @@ $PAGE->set_pagelayout('admin'); 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()) { diff --git a/enrol/editenrolment_form.php b/enrol/editenrolment_form.php index 307346c4125..d1ee2ec1e40 100644 --- a/enrol/editenrolment_form.php +++ b/enrol/editenrolment_form.php @@ -31,8 +31,11 @@ class enrol_user_enrolment_form extends moodleform { $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])) { diff --git a/enrol/externallib.php b/enrol/externallib.php index d11bfab194f..670be50703f 100644 --- a/enrol/externallib.php +++ b/enrol/externallib.php @@ -859,10 +859,13 @@ class core_enrol_external extends external_api { $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); diff --git a/enrol/unenroluser.php b/enrol/unenroluser.php index fe1fc18d190..4690c57516c 100644 --- a/enrol/unenroluser.php +++ b/enrol/unenroluser.php @@ -70,7 +70,13 @@ if ($confirm && confirm_sesskey()) { } $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'); diff --git a/lang/en/enrol.php b/lang/en/enrol.php index 666a8a59d99..8c870a6667e 100644 --- a/lang/en/enrol.php +++ b/lang/en/enrol.php @@ -132,7 +132,7 @@ $string['totalenrolledusers'] = '{$a} enrolled users'; $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'; diff --git a/lib/enrollib.php b/lib/enrollib.php index f3035575f71..2393735167b 100644 --- a/lib/enrollib.php +++ b/lib/enrollib.php @@ -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. diff --git a/user/amd/build/status_field.min.js b/user/amd/build/status_field.min.js index c1743f589b1..29f8eef5bc6 100644 --- a/user/amd/build/status_field.min.js +++ b/user/amd/build/status_field.min.js @@ -1 +1 @@ -define(["core/templates","jquery","core/str","core/config","core/notification","core/modal_factory","core/modal_events","core/fragment","core/ajax"],function(a,b,c,d,e,f,g,h,i){var j={EDIT_ENROLMENT:'[data-action="editenrolment"]',SHOW_DETAILS:'[data-action="showdetails"]',UNENROL:'[data-action="unenrol"]'},k=function(a){this.contextid=a.contextid,this.courseid=a.courseid,this.bindEditEnrol(),this.bindUnenrol(),this.bindStatusDetails()};return k.prototype.courseid=0,k.prototype.bindEditEnrol=function(){var a=this;b(j.EDIT_ENROLMENT).click(function(d){d.preventDefault();var h=b(this),i=h.parent(),j=i.data("fullname"),k=h.attr("rel");b.when(c.get_string("edituserenrolment","enrol",j)).then(function(a){return f.create({large:!0,title:a,type:f.types.SAVE_CANCEL})}).done(function(b){b.getRoot().on(g.save,function(c){c.preventDefault(),a.submitEditFormAjax(b)}),b.getRoot().on(g.hidden,function(){b.destroy()}),b.setBody(a.getBody(k)),b.show()}).fail(e.exception)})},k.prototype.bindUnenrol=function(){b(j.UNENROL).click(function(a){a.preventDefault();var h=b(this),i=h.parent(),j=[{key:"unenrol",component:"enrol"},{key:"unenrolconfirm",component:"enrol",param:{user:i.data("fullname"),course:i.data("coursename")}}],k=f.create({type:f.types.SAVE_CANCEL});b.when(c.get_strings(j),k).done(function(a,c){var e=a[0],f=a[1];c.setTitle(e),c.setBody(f),c.setSaveButtonText(e),c.getRoot().on(g.save,function(){var a={confirm:1,sesskey:d.sesskey,ue:b(h).attr("rel")};window.location.href=d.wwwroot+"/enrol/unenroluser.php?"+b.param(a)}),c.getRoot().on(g.hidden,function(){c.destroy()}),c.show()}).fail(e.exception)})},k.prototype.bindStatusDetails=function(){b(j.SHOW_DETAILS).click(function(d){d.preventDefault();var h=b(this),i=h.parent(),k={fullname:i.data("fullname"),coursename:i.data("coursename"),enrolinstancename:i.data("enrolinstancename"),status:i.data("status"),statusclass:i.find("span").attr("class"),timestart:i.data("timestart"),timeend:i.data("timeend")},l=[{key:"enroldetails",component:"enrol"}],m=h.next(j.EDIT_ENROLMENT);m.length&&(k.editenrollink=b("
").append(m.clone()).html());var n=c.get_strings(l),o=f.create({large:!0,type:f.types.CANCEL});b.when(n,o).done(function(c,d){var e=a.render("core_user/status_details",k);d.setTitle(c[0]),d.setBody(e),m.length&&d.getRoot().on("click",j.EDIT_ENROLMENT,function(a){a.preventDefault(),d.hide(),b(m).trigger("click")}),d.show(),d.getRoot().on(g.hidden,function(){d.destroy()})}).fail(e.exception)})},k.prototype.submitEditFormAjax=function(a){var c=this,d=a.getRoot().find("form"),f=b(d).find('[name="ue"]').val(),g=b(d).find('[name="status"]').val(),h={courseid:this.courseid,ueid:f,status:g},j=b(d).find('[name="timestart[enabled]"]');if(j.is(":checked")){var k=b(d).find('[name="timestart[year]"]').val(),l=b(d).find('[name="timestart[month]"]').val()-1,m=b(d).find('[name="timestart[day]"]').val(),n=b(d).find('[name="timestart[hour]"]').val(),o=b(d).find('[name="timestart[minute]"]').val(),p=new Date(k,l,m,n,o);h.timestart=p.getTime()/1e3}var q=b(d).find('[name="timeend[enabled]"]');if(q.is(":checked")){var r=b(d).find('[name="timeend[year]"]').val(),s=b(d).find('[name="timeend[month]"]').val()-1,t=b(d).find('[name="timeend[day]"]').val(),u=b(d).find('[name="timeend[hour]"]').val(),v=b(d).find('[name="timeend[minute]"]').val(),w=new Date(r,s,t,u,v);h.timeend=w.getTime()/1e3}var x={methodname:"core_enrol_edit_user_enrolment",args:h};i.call([x])[0].done(function(b){if(b.result)a.hide(),"undefined"!=typeof window.M.core_formchangechecker&&window.M.core_formchangechecker.reset_form_dirty_state(),window.location.reload();else{var e=JSON.stringify(d.serialize());a.setBody(c.getBody(f,e))}}).fail(e.exception)},k.prototype.getBody=function(a,b){var c={ueid:a};return"undefined"!=typeof b&&(c.formdata=b),h.loadFragment("enrol","user_enrolment_form",this.contextid,c).fail(e.exception)},{init:function(a){new k(a)}}}); \ No newline at end of file +define(["core/templates","jquery","core/str","core/config","core/notification","core/modal_factory","core/modal_events","core/fragment","core/ajax"],function(a,b,c,d,e,f,g,h,i){var j={EDIT_ENROLMENT:'[data-action="editenrolment"]',SHOW_DETAILS:'[data-action="showdetails"]',UNENROL:'[data-action="unenrol"]'},k=function(a){this.contextid=a.contextid,this.courseid=a.courseid,this.bindEditEnrol(),this.bindUnenrol(),this.bindStatusDetails()};return k.prototype.courseid=0,k.prototype.bindEditEnrol=function(){var a=this;b(j.EDIT_ENROLMENT).click(function(d){d.preventDefault();var h=b(this),i=h.parent(),j=i.data("fullname"),k=h.attr("rel");b.when(c.get_string("edituserenrolment","enrol",j)).then(function(a){return f.create({large:!0,title:a,type:f.types.SAVE_CANCEL})}).done(function(b){b.getRoot().on(g.save,function(c){c.preventDefault(),a.submitEditFormAjax(b)}),b.getRoot().on(g.hidden,function(){b.destroy()}),b.setBody(a.getBody(k)),b.show()}).fail(e.exception)})},k.prototype.bindUnenrol=function(){b(j.UNENROL).click(function(a){a.preventDefault();var h=b(this),i=h.parent(),j=[{key:"unenrol",component:"enrol"},{key:"unenrolconfirm",component:"enrol",param:{user:i.data("fullname"),course:i.data("coursename"),enrolinstancename:i.data("enrolinstancename")}}],k=f.create({type:f.types.SAVE_CANCEL});b.when(c.get_strings(j),k).done(function(a,c){var e=a[0],f=a[1];c.setTitle(e),c.setBody(f),c.setSaveButtonText(e),c.getRoot().on(g.save,function(){var a={confirm:1,sesskey:d.sesskey,ue:b(h).attr("rel")};window.location.href=d.wwwroot+"/enrol/unenroluser.php?"+b.param(a)}),c.getRoot().on(g.hidden,function(){c.destroy()}),c.show()}).fail(e.exception)})},k.prototype.bindStatusDetails=function(){b(j.SHOW_DETAILS).click(function(d){d.preventDefault();var h=b(this),i=h.parent(),k={fullname:i.data("fullname"),coursename:i.data("coursename"),enrolinstancename:i.data("enrolinstancename"),status:i.data("status"),statusclass:i.find("span").attr("class"),timestart:i.data("timestart"),timeend:i.data("timeend")},l=[{key:"enroldetails",component:"enrol"}],m=h.next(j.EDIT_ENROLMENT);m.length&&(k.editenrollink=b("
").append(m.clone()).html());var n=c.get_strings(l),o=f.create({large:!0,type:f.types.CANCEL});b.when(n,o).done(function(c,d){var e=a.render("core_user/status_details",k);d.setTitle(c[0]),d.setBody(e),m.length&&d.getRoot().on("click",j.EDIT_ENROLMENT,function(a){a.preventDefault(),d.hide(),b(m).trigger("click")}),d.show(),d.getRoot().on(g.hidden,function(){d.destroy()})}).fail(e.exception)})},k.prototype.submitEditFormAjax=function(a){var c=this,d=a.getRoot().find("form"),f=b(d).find('[name="ue"]').val(),g=b(d).find('[name="status"]').val(),h={courseid:this.courseid,ueid:f,status:g},j=b(d).find('[name="timestart[enabled]"]');if(j.is(":checked")){var k=b(d).find('[name="timestart[year]"]').val(),l=b(d).find('[name="timestart[month]"]').val()-1,m=b(d).find('[name="timestart[day]"]').val(),n=b(d).find('[name="timestart[hour]"]').val(),o=b(d).find('[name="timestart[minute]"]').val(),p=new Date(k,l,m,n,o);h.timestart=p.getTime()/1e3}var q=b(d).find('[name="timeend[enabled]"]');if(q.is(":checked")){var r=b(d).find('[name="timeend[year]"]').val(),s=b(d).find('[name="timeend[month]"]').val()-1,t=b(d).find('[name="timeend[day]"]').val(),u=b(d).find('[name="timeend[hour]"]').val(),v=b(d).find('[name="timeend[minute]"]').val(),w=new Date(r,s,t,u,v);h.timeend=w.getTime()/1e3}var x={methodname:"core_enrol_edit_user_enrolment",args:h};i.call([x])[0].done(function(b){if(b.result)a.hide(),"undefined"!=typeof window.M.core_formchangechecker&&window.M.core_formchangechecker.reset_form_dirty_state(),window.location.reload();else{var e=JSON.stringify(d.serialize());a.setBody(c.getBody(f,e))}}).fail(e.exception)},k.prototype.getBody=function(a,b){var c={ueid:a};return"undefined"!=typeof b&&(c.formdata=b),h.loadFragment("enrol","user_enrolment_form",this.contextid,c).fail(e.exception)},{init:function(a){new k(a)}}}); \ No newline at end of file diff --git a/user/amd/src/status_field.js b/user/amd/src/status_field.js index 46cb8b64556..c17844fa73c 100644 --- a/user/amd/src/status_field.js +++ b/user/amd/src/status_field.js @@ -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') } } ]; diff --git a/user/templates/status_field.mustache b/user/templates/status_field.mustache index 04cbf112dc3..0a594286f11 100644 --- a/user/templates/status_field.mustache +++ b/user/templates/status_field.mustache @@ -61,7 +61,7 @@ data-status="{{status}}" data-timestart="{{timestart}}" data-timeend="{{timeend}}"> {{status}} {{! - }}{{#pix}}docs, core, {{#str}}enroldetails, enrol{{/str}}{{/pix}}{{! + }}{{#pix}}docs, core, {{enrolinstancename}}{{/pix}}{{! }} {{#enrolactions}} {{! diff --git a/user/tests/behat/edit_user_enrolment.feature b/user/tests/behat/edit_user_enrolment.feature index 525b94b9c1e..9ff1bb23605 100644 --- a/user/tests/behat/edit_user_enrolment.feature +++ b/user/tests/behat/edit_user_enrolment.feature @@ -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" @@ -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" @@ -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"