Skip to content

Commit

Permalink
MDL-35776 user ajax: fix sort order in chrome.
Browse files Browse the repository at this point in the history
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
timhunt committed Oct 3, 2012
1 parent c62488c commit 13bd955
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 6 additions & 2 deletions enrol/ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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:
Expand Down
8 changes: 6 additions & 2 deletions enrol/manual/ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,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) {
Expand All @@ -77,6 +77,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':
Expand Down

0 comments on commit 13bd955

Please sign in to comment.