From 13bd955e65521824ddde050d6625326cd5dfd172 Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Wed, 3 Oct 2012 18:46:07 +0100 Subject: [PATCH] MDL-35776 user ajax: fix sort order in chrome. It seems that Chrome orders fields of objects in order of array key. Therefore we must stop using user.id in the PHP arrays, and instead ensure that we use sequential numbers. This commit fixes the enrol UI. --- enrol/ajax.php | 8 ++++++-- enrol/manual/ajax.php | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) 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':