Permalink
Browse files

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.
  • Loading branch information...
1 parent d06a987 commit 8b3818d97bc2464d3c324db95b074d798c711416 @timhunt timhunt committed Oct 3, 2012
Showing with 13 additions and 5 deletions.
  1. +6 −2 enrol/ajax.php
  2. +7 −3 enrol/manual/ajax.php
View
@@ -54,9 +54,9 @@
$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 @@
$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:
View
@@ -53,9 +53,9 @@
$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) {
@@ -79,6 +79,10 @@
}
$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':
@@ -135,4 +139,4 @@
throw new enrol_ajax_exception('unknowajaxaction');
}
-echo json_encode($outcome);
+echo json_encode($outcome);

0 comments on commit 8b3818d

Please sign in to comment.