Permalink
Browse files

Merge branch 'MDL-35776_23' of git://github.com/timhunt/moodle into M…

…OODLE_23_STABLE
  • Loading branch information...
2 parents ae48ff8 + 1381537 commit 34983250b16c6368627d7b9d99d129edfec4fa0f @nebgor nebgor committed Oct 9, 2012
Showing with 29 additions and 16 deletions.
  1. +6 −2 enrol/ajax.php
  2. +7 −3 enrol/manual/ajax.php
  3. +8 −6 user/selector/module.js
  4. +8 −5 user/selector/search.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);
@@ -221,8 +221,9 @@ M.core_user.init_user_selector = function (Y, name, hash, extrafields, lastsearc
// Output each optgroup.
var count = 0;
- for (var groupname in data.results) {
- this.output_group(groupname, data.results[groupname], selectedusers, true);
+ for (var key in data.results) {
+ var groupdata = data.results[key];
+ this.output_group(groupdata.name, groupdata.users, selectedusers, true);
count++;
}
if (!count) {
@@ -248,13 +249,14 @@ M.core_user.init_user_selector = function (Y, name, hash, extrafields, lastsearc
output_group : function(groupname, users, selectedusers, processsingle) {
var optgroup = Y.Node.create('<optgroup></optgroup>');
var count = 0;
- for (var userid in users) {
- var user = users[userid];
- var option = Y.Node.create('<option value="'+userid+'">'+user.name+'</option>');
+ for (var key in users) {
+ var user = users[key];
+ var option = Y.Node.create('<option value="'+user.id+'">'+user.name+'</option>');
if (user.disabled) {
option.set('disabled', true);
- } else if (selectedusers===true || selectedusers[userid]) {
+ } else if (selectedusers===true || selectedusers[user.id]) {
option.set('selected', true);
+ delete selectedusers[user.id];
} else {
option.set('selected', false);
}
@@ -78,17 +78,20 @@
$userselector = new $classname($name, $options);
// Do the search and output the results.
-$users = $userselector->find_users($search);
-foreach ($users as &$group) {
- foreach ($group as $user) {
+$results = $userselector->find_users($search);
+$json = array();
+foreach ($results as $groupname => $users) {
+ $groupdata = array('name' => $groupname, 'users' => array());
+ foreach ($users as $user) {
$output = new stdClass;
$output->id = $user->id;
$output->name = $userselector->output_user($user);
if (!empty($user->disabled)) {
$output->disabled = true;
}
- $group[$user->id] = $output;
+ $groupdata['users'][] = $output;
}
+ $json[] = $groupdata;
}
-echo json_encode(array('results' => $users));
+echo json_encode(array('results' => $json));

0 comments on commit 3498325

Please sign in to comment.