diff --git a/enrol/ajax.php b/enrol/ajax.php index ede3c5a377c..64dba6a06e0 100644 --- a/enrol/ajax.php +++ b/enrol/ajax.php @@ -54,9 +54,9 @@ echo $OUTPUT->header(); // send headers $manager = new course_enrolment_manager($PAGE, $course); -$outcome = new stdClass; +$outcome = new stdClass(); $outcome->success = true; -$outcome->response = new stdClass; +$outcome->response = new stdClass(); $outcome->error = ''; switch ($action) { @@ -99,6 +99,10 @@ switch ($action) { $user->fullname = fullname($user); unset($user->id); } + // Chrome will display users in the order of the array keys, so we need + // to ensure that the results ordered array keys. Fortunately, the JavaScript + // does not care what the array keys are. It uses user.id where necessary. + $outcome->response['users'] = array_values($outcome->response['users']); $outcome->success = true; break; default: diff --git a/enrol/manual/ajax.php b/enrol/manual/ajax.php index faf8ac02025..492634f6c30 100644 --- a/enrol/manual/ajax.php +++ b/enrol/manual/ajax.php @@ -51,9 +51,9 @@ echo $OUTPUT->header(); // Send headers. $manager = new course_enrolment_manager($PAGE, $course); -$outcome = new stdClass; +$outcome = new stdClass(); $outcome->success = true; -$outcome->response = new stdClass; +$outcome->response = new stdClass(); $outcome->error = ''; switch ($action) { @@ -77,6 +77,10 @@ switch ($action) { } $user->extrafields = implode(', ', $fieldvalues); } + // Chrome will display users in the order of the array keys, so we need + // to ensure that the results ordered array keys. Fortunately, the JavaScript + // does not care what the array keys are. It uses user.id where necessary. + $outcome->response['users'] = array_values($outcome->response['users']); $outcome->success = true; break; case 'enrol':