diff --git a/enrol/ajax.php b/enrol/ajax.php index 2d41a9892c1c9..4134c397280b4 100644 --- a/enrol/ajax.php +++ b/enrol/ajax.php @@ -88,7 +88,7 @@ break; case 'getassignable': $otheruserroles = optional_param('otherusers', false, PARAM_BOOL); - $outcome->response = array_reverse($manager->get_assignable_roles($otheruserroles), true); + $outcome->response = $manager->get_assignable_roles_for_json($otheruserroles); break; case 'searchotherusers': $search = optional_param('search', '', PARAM_RAW); diff --git a/enrol/locallib.php b/enrol/locallib.php index 2d918da0e5419..4699b3ad34c4a 100644 --- a/enrol/locallib.php +++ b/enrol/locallib.php @@ -621,6 +621,22 @@ public function get_assignable_roles($otherusers = false) { } } + /** + * Gets all of the assignable roles for this course, wrapped in an array to ensure + * role sort order is not lost during json deserialisation. + * + * @param boolean $otherusers whether to include the assignable roles for other users + * @return array + */ + public function get_assignable_roles_for_json($otherusers = false) { + $rolesarray = array(); + $assignable = $this->get_assignable_roles($otherusers); + foreach ($assignable as $id => $role) { + $rolesarray[] = array('id' => $id, 'name' => $role); + } + return $rolesarray; + } + /** * Gets all of the groups for this course. * diff --git a/enrol/manual/yui/quickenrolment/quickenrolment.js b/enrol/manual/yui/quickenrolment/quickenrolment.js index 5aeca3202d0f1..012cafb0415c0 100644 --- a/enrol/manual/yui/quickenrolment/quickenrolment.js +++ b/enrol/manual/yui/quickenrolment/quickenrolment.js @@ -198,8 +198,8 @@ YUI.add('moodle-enrol_manual-quickenrolment', function(Y) { var index = 0, count = 0; for (var i in roles) { count++; - var option = create(''); - if (i == v) { + var option = create(''); + if (roles[i].id == v) { index = count; } s.append(option); diff --git a/enrol/yui/otherusersmanager/otherusersmanager.js b/enrol/yui/otherusersmanager/otherusersmanager.js index 89390ee979d77..23d8ba9c0a53c 100644 --- a/enrol/yui/otherusersmanager/otherusersmanager.js +++ b/enrol/yui/otherusersmanager/otherusersmanager.js @@ -314,10 +314,10 @@ YUI.add('moodle-enrol-otherusersmanager', function(Y) { ) .append(Y.Node.create('